blob: 9548b493752b215e755fb3482dfdab8e95058b59 [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
4" Version: 173
Bram Moolenaar29634562020-01-09 21:46:04 +01005" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00006" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +00008" Permission is hereby granted to use and distribute this code,
9" with or without modifications, provided that this copyright
10" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000012" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000013" expressed or implied. By using this plugin, you agree that
14" in no event will the copyright holder be liable for any damages
15" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010016"
17" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
18" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
19"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020020"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000021"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000022" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000023" (James 1:22 RSV)
24" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000025" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000026if &cp || exists("g:loaded_netrw")
27 finish
28endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020029
30" Check that vim has patches that netrw requires.
31" Patches needed for v7.4: 1557, and 213.
32" (netrw will benefit from vim's having patch#656, too)
33let s:needspatches=[1557,213]
34if exists("s:needspatches")
35 for ptch in s:needspatches
36 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
37 if !exists("s:needpatch{ptch}")
38 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
39 endif
40 let s:needpatch{ptch}= 1
41 finish
42 endif
43 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020044endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020045
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010046let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000047if !exists("s:NOTE")
48 let s:NOTE = 0
49 let s:WARNING = 1
50 let s:ERROR = 2
51endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000052
Bram Moolenaar1afcace2005-11-25 19:54:28 +000053let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010054setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020055"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010056"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010057"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000059" ======================
60" Netrw Variables: {{{1
61" ======================
62
Bram Moolenaar071d4272004-06-13 20:20:40 +000063" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020064" netrw#ErrorMsg: {{{2
65" 0=note = s:NOTE
66" 1=warning = s:WARNING
67" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010068" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
69" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
70" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010071" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020072fun! netrw#ErrorMsg(level,msg,errnum)
73" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
74
75 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020076" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020077 return
78 endif
79
80 if a:level == 1
81 let level= "**warning** (netrw) "
82 elseif a:level == 2
83 let level= "**error** (netrw) "
84 else
85 let level= "**note** (netrw) "
86 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010087" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020088
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020089 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
90 " use popup window
91 if type(a:msg) == 3
92 let msg = [level]+a:msg
93 else
94 let msg= level.a:msg
95 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020096 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020097 let s:popuperr_text= ""
98 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +020099 " (default) netrw creates a one-line window to show error/warning
100 " messages (reliably displayed)
101
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100102 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200103 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100104" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200105
106 " getting messages out reliably is just plain difficult!
107 " This attempt splits the current window, creating a one line window.
108 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100109" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200110 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100111" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200112 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100113 if type(a:msg) == 3
114 for msg in a:msg
115 NetrwKeepj call setline(line("$")+1,level.msg)
116 endfor
117 else
118 NetrwKeepj call setline(line("$")+1,level.a:msg)
119 endif
120 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200121 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100122" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200123 bo 1split
124 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200125 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200126 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100127 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100128" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200129 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100130 if type(a:msg) == 3
131 for msg in a:msg
132 NetrwKeepj call setline(line("$")+1,level.msg)
133 endfor
134 else
135 NetrwKeepj call setline(line("$"),level.a:msg)
136 endif
137 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100139" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 if &fo !~ '[ta]'
141 syn clear
142 syn match netrwMesgNote "^\*\*note\*\*"
143 syn match netrwMesgWarning "^\*\*warning\*\*"
144 syn match netrwMesgError "^\*\*error\*\*"
145 hi link netrwMesgWarning WarningMsg
146 hi link netrwMesgError Error
147 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100148" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200149 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200150
151 else
152 " (optional) netrw will show messages using echomsg. Even if the
153 " message doesn't appear, at least it'll be recallable via :messages
154" redraw!
155 if a:level == s:WARNING
156 echohl WarningMsg
157 elseif a:level == s:ERROR
158 echohl Error
159 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100160
161 if type(a:msg) == 3
162 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100163 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100164 endfor
165 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100166 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100167 endif
168
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100169" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200170 echohl None
171 endif
172
173" call Dret("netrw#ErrorMsg")
174endfun
175
176" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100177" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100178" Loosely, varname = value.
179fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100180" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100181 if !exists(a:varname)
182 if type(a:value) == 0
183 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200184 elseif type(a:value) == 1 && a:value =~ '^[{[]'
185 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100186 elseif type(a:value) == 1
187 exe "let ".a:varname."="."'".a:value."'"
188 else
189 exe "let ".a:varname."=".a:value
190 endif
191 endif
192endfun
193
194" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000195" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200196call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000197if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100198 call s:NetrwInit("s:THINLIST",0)
199 call s:NetrwInit("s:LONGLIST",1)
200 call s:NetrwInit("s:WIDELIST",2)
201 call s:NetrwInit("s:TREELIST",3)
202 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000203endif
204
205" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200206" Default option values: {{{2
207let g:netrw_localcopycmdopt = ""
208let g:netrw_localcopydircmdopt = ""
209let g:netrw_localmkdiropt = ""
210let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200211
212" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000213" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200214if (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")
215 call s:NetrwInit("g:netrw_use_errorwindow",2)
216else
217 call s:NetrwInit("g:netrw_use_errorwindow",1)
218endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200219
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000220if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100221 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000222 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100223 elseif executable("curl")
224 let g:netrw_dav_cmd = "curl"
225 else
226 let g:netrw_dav_cmd = ""
227 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000229if !exists("g:netrw_fetch_cmd")
230 if executable("fetch")
231 let g:netrw_fetch_cmd = "fetch -o"
232 else
233 let g:netrw_fetch_cmd = ""
234 endif
235endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100236if !exists("g:netrw_file_cmd")
237 if executable("elinks")
238 call s:NetrwInit("g:netrw_file_cmd","elinks")
239 elseif executable("links")
240 call s:NetrwInit("g:netrw_file_cmd","links")
241 endif
242endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000243if !exists("g:netrw_ftp_cmd")
244 let g:netrw_ftp_cmd = "ftp"
245endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200246let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200247if !exists("g:netrw_ftp_options")
248 let g:netrw_ftp_options= "-i -n"
249endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000250if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100251 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100252 let g:netrw_http_cmd = "wget"
253 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100254 elseif executable("curl")
255 let g:netrw_http_cmd = "curl"
256 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200257 elseif executable("elinks")
258 let g:netrw_http_cmd = "elinks"
259 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000260 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100261 let g:netrw_http_cmd = "fetch"
262 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200263 elseif executable("links")
264 let g:netrw_http_cmd = "links"
265 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000266 else
267 let g:netrw_http_cmd = ""
268 endif
269endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100270call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100271call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100272call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
273call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200274call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200275if !exists("g:netrw_scp_cmd")
276 if executable("scp")
277 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
278 elseif executable("pscp")
279 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
280 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
281 else
282 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
283 endif
284 else
285 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
286 endif
287endif
288
Bram Moolenaar5c736222010-01-06 20:54:52 +0100289call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
290call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000291
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000292if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000293 \ && exists("g:netrw_use_nt_rcp")
294 \ && g:netrw_use_nt_rcp
295 \ && executable( $SystemRoot .'/system32/rcp.exe')
296 let s:netrw_has_nt_rcp = 1
297 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000298else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000299 let s:netrw_has_nt_rcp = 0
300 let s:netrw_rcpmode = ''
301endif
302
303" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000304" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000305" Cygwin Detection ------- {{{3
306if !exists("g:netrw_cygwin")
307 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100308 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000309 let g:netrw_cygwin= 1
310 else
311 let g:netrw_cygwin= 0
312 endif
313 else
314 let g:netrw_cygwin= 0
315 endif
316endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000317" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100318call s:NetrwInit("g:netrw_alto" , &sb)
319call s:NetrwInit("g:netrw_altv" , &spr)
320call s:NetrwInit("g:netrw_banner" , 1)
321call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200322call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100323call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200324call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100325call s:NetrwInit("g:netrw_compress" , "gzip")
326call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200327if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
328 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
329 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000330endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200331call s:NetrwInit("g:netrw_cursor" , 2)
332let s:netrw_usercul = &cursorline
333let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200334"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100335call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000336" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200337call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200338call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200339call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100340call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200341call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100342call s:NetrwInit("g:netrw_fastbrowse" , 1)
343call 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 +0000344if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000345 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
346 let g:netrw_ftp_list_cmd = "ls -lF"
347 let g:netrw_ftp_timelist_cmd = "ls -tlF"
348 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000349 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000350 let g:netrw_ftp_list_cmd = "dir"
351 let g:netrw_ftp_timelist_cmd = "dir"
352 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000353 endif
354endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100355call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000356" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100357call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000358if !exists("g:netrw_ignorenetrc")
359 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
360 let g:netrw_ignorenetrc= 1
361 else
362 let g:netrw_ignorenetrc= 0
363 endif
364endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100365call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000366if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000367 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000368 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200369 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000370 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
371 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100372 if exists("g:netrw_list_cmd_options")
373 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
374 else
375 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
376 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000377 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200378 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100379 if exists("g:netrw_list_cmd_options")
380 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
381 else
382 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
383 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000384 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100385" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000386 let g:netrw_list_cmd= ""
387 endif
388endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100389call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000390" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200391if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200392 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200393 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
394endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100395if !exists("g:netrw_localcmdshell")
396 let g:netrw_localcmdshell= ""
397endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000398if !exists("g:netrw_localcopycmd")
399 if has("win32") || has("win95") || has("win64") || has("win16")
400 if g:netrw_cygwin
401 let g:netrw_localcopycmd= "cp"
402 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200403 let g:netrw_localcopycmd = expand("$COMSPEC")
404 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000405 endif
406 elseif has("unix") || has("macunix")
407 let g:netrw_localcopycmd= "cp"
408 else
409 let g:netrw_localcopycmd= ""
410 endif
411endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100412if !exists("g:netrw_localcopydircmd")
413 if has("win32") || has("win95") || has("win64") || has("win16")
414 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200415 let g:netrw_localcopydircmd = "cp"
416 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100417 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200418 let g:netrw_localcopydircmd = expand("$COMSPEC")
419 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100420 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200421 elseif has("unix")
422 let g:netrw_localcopydircmd = "cp"
423 let g:netrw_localcopydircmdopt= " -R"
424 elseif has("macunix")
425 let g:netrw_localcopydircmd = "cp"
426 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100427 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200428 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100429 endif
430endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200431if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100432 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200433 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
434endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200435if has("win32") || has("win95") || has("win64") || has("win16")
436 if g:netrw_cygwin
437 call s:NetrwInit("g:netrw_localmkdir","mkdir")
438 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200439 let g:netrw_localmkdir = expand("$COMSPEC")
440 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200441 endif
442else
443 call s:NetrwInit("g:netrw_localmkdir","mkdir")
444endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200445call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200446if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200447 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200448 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
449endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000450if !exists("g:netrw_localmovecmd")
451 if has("win32") || has("win95") || has("win64") || has("win16")
452 if g:netrw_cygwin
453 let g:netrw_localmovecmd= "mv"
454 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200455 let g:netrw_localmovecmd = expand("$COMSPEC")
456 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000457 endif
458 elseif has("unix") || has("macunix")
459 let g:netrw_localmovecmd= "mv"
460 else
461 let g:netrw_localmovecmd= ""
462 endif
463endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100464" following serves as an example for how to insert a version&patch specific test
465"if v:version < 704 || (v:version == 704 && !has("patch1107"))
466"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100467call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
468" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000469if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000470 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000471endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000472if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000473 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
474endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000475" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100476call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
477call s:NetrwInit("g:netrw_maxfilenamelen", 32)
478call s:NetrwInit("g:netrw_menu" , 1)
479call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200480call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100481call s:NetrwInit("g:netrw_retmap" , 0)
482if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
483 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
484elseif has("win32") || has("win95") || has("win64") || has("win16")
485 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
486else
487 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000488endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100489call s:NetrwInit("g:netrw_preview" , 0)
490call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100491call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100492call s:NetrwInit("g:netrw_sshport" , "-p")
493call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
494call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
495call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100496call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
497" Default values - q-s ---------- {{{3
498call s:NetrwInit("g:netrw_quickhelp",0)
499let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100500 \ "(create new) %:file d:directory",
501 \ "(windows split&open) o:horz v:vert p:preview",
502 \ "i:style qf:file info O:obtain r:reverse",
503 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
504 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
505 \ "(history) qb:list u:go up U:go down",
506 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100507" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
508call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100509if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
510 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
511else
512 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
513endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100514call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
515call s:NetrwInit("g:netrw_sort_options" , "")
516call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000517if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100518 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200519 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520 else
521 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000522 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000523endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100524call s:NetrwInit("g:netrw_special_syntax" , 0)
525call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200526call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100527call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100528call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000529" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200531if !exists("g:netrw_xstrlen")
532 if exists("g:Align_xstrlen")
533 let g:netrw_xstrlen= g:Align_xstrlen
534 elseif exists("g:drawit_xstrlen")
535 let g:netrw_xstrlen= g:drawit_xstrlen
536 elseif &enc == "latin1" || !has("multi_byte")
537 let g:netrw_xstrlen= 0
538 else
539 let g:netrw_xstrlen= 1
540 endif
541endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200544call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100545call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200546if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000547" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000548" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200550if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200551 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200552else
Bram Moolenaarff034192013-04-24 18:51:19 +0200553 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200554endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200555call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100556call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
557call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100558if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100559 let s:treedepthstring= "│ "
560else
561 let s:treedepthstring= "| "
562endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200563call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000564
565" BufEnter event ignored by decho when following variable is true
566" Has a side effect that doau BufReadPost doesn't work, so
567" files read by network transfer aren't appropriately highlighted.
568"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569
Bram Moolenaaradc21822011-04-01 18:03:16 +0200570" ======================
571" Netrw Initialization: {{{1
572" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200573if 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 +0100574" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100575 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200576" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100577 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100578 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
579 au VimEnter * let s:initbeval= &beval
580"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100581" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
582" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
583" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
584" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
585" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
586" 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 +0200587endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200588au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200589
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200590if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100591 com! -nargs=* NetrwKeepj keepj <args>
592else
593 let g:netrw_keepj= ""
594 com! -nargs=* NetrwKeepj <args>
595endif
596
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000597" ==============================
598" Netrw Utility Functions: {{{1
599" ==============================
600
Bram Moolenaaradc21822011-04-01 18:03:16 +0200601" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100602" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100603if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100604" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100605 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100606 if &ft != "netrw"
607 return ""
608 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200609 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
610 " popup error window is still showing
611 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
612 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
613 " text under mouse hasn't changed; only close window when it changes
614 call popup_close(s:popuperr_id)
615 unlet s:popuperr_text
616 else
617 let s:popuperr_text= v:beval_text
618 endif
619 let mesg= ""
620 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 +0100621 let mesg= ""
622 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
623 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
624 elseif getline(v:beval_lnum) =~ '^"\s*/'
625 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
626 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100627 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100628 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
629 let mesg = "S: edit sorting sequence"
630 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
631 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
632 elseif v:beval_text == "Quick" || v:beval_text == "Help"
633 let mesg = "Help: press <F1>"
634 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
635 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
636 else
637 let mesg= ""
638 endif
639 return mesg
640 endfun
641"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100642" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
643" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
644" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
645" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
646" 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 +0200647endif
648
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200650" netrw#Explore: launch the local browser in the directory of the current file {{{2
651" indx: == -1: Nexplore
652" == -2: Pexplore
653" == +: this is overloaded:
654" * If Nexplore/Pexplore is in use, then this refers to the
655" indx'th item in the w:netrw_explore_list[] of items which
656" matched the */pattern **/pattern *//pattern **//pattern
657" * If Hexplore or Vexplore, then this will override
658" g:netrw_winsize to specify the qty of rows or columns the
659" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100660" 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 +0200661" dosplit==1: the window will be split before running the local browser
662" style == 0: Explore style == 1: Explore!
663" == 2: Hexplore style == 3: Hexplore!
664" == 4: Vexplore style == 5: Vexplore!
665" == 6: Texplore
666fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100667" 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 +0100668" 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 +0200669 if !exists("b:netrw_curdir")
670 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100671" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200672 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100673
674 " record current file for Rexplore's benefit
675 if &ft != "netrw"
676 let w:netrw_rexfile= expand("%:p")
677 endif
678
679 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200680 let curdir = simplify(b:netrw_curdir)
681 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200682 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
683 let curdir= substitute(curdir,'\','/','g')
684 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100685" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100686
687 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
688 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
689 " try Explore again.
690 if a:0 > 0
691" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100692 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
693 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
694 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
695 \ '~'.expand("<slnum>"))
696 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
697" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100698 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
699" call Dret("netrw#Explore : returning from retry")
700 return
701" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100702" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100703 endif
704 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200705
706 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200707 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100708" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100709 sil! let keepregstar = @*
710 sil! let keepregplus = @+
711 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200712 sil! let keepregslash= @/
713
Bram Moolenaar8d043172014-01-23 14:24:41 +0100714 " if dosplit
715 " -or- file has been modified AND file not hidden when abandoned
716 " -or- Texplore used
717 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100718" 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 +0200719 call s:SaveWinVars()
720 let winsz= g:netrw_winsize
721 if a:indx > 0
722 let winsz= a:indx
723 endif
724
725 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100726" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200727 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200728 if winsz == 0|let winsz= ""|endif
729 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100730" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200731
732 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100733" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200734 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200735 if winsz == 0|let winsz= ""|endif
736 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100737" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200738
739 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100740" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200741 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200742 if winsz == 0|let winsz= ""|endif
743 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100744" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200745
746 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100747" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200748 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200749 if winsz == 0|let winsz= ""|endif
750 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100751" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200752
753 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100754" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200756 if winsz == 0|let winsz= ""|endif
757 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100758" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200759
760 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100761" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200762 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200763 if winsz == 0|let winsz= ""|endif
764 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100765" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200766
767 elseif a:style == 6 " Texplore
768 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100769" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 call s:RestoreBufVars()
773 endif
774 call s:RestoreWinVars()
775" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" 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 +0200777 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100778 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200779
780 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
789 if dirname !~ '/$'
790 let dirname= dirname."/"
791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100792" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200793 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100794" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200795 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200797 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100798" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200799 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200803 let dirname= a:1
804 endif
805 else
806 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 call s:NetrwClearExplore()
809" call Dret("netrw#Explore : cleared list")
810 return
811 endif
812
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100813" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200814 if dirname =~ '\.\./\=$'
815 let dirname= simplify(fnamemodify(dirname,':p:h'))
816 elseif dirname =~ '\.\.' || dirname == '.'
817 let dirname= simplify(fnamemodify(dirname,':p'))
818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820
821 if dirname =~ '^\*//'
822 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100823" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
825 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
828
829 elseif dirname =~ '^\*\*//'
830 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 let pattern= substitute(dirname,'^\*\*//','','')
833 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835
836 elseif dirname =~ '/\*\*/'
837 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100838" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200839 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
840 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
841 let b:netrw_curdir = prefixdir
842 else
843 let b:netrw_curdir= getcwd().'/'.prefixdir
844 endif
845 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
846 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100847" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
848" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200849
850 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200851 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200852 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854
855 elseif dirname=~ '^\*\*/'
856 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
857 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100858" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200859
860 else
861 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200863 endif
864
865 if starpat == 0 && a:indx >= 0
866 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100867" 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 +0200868 if dirname == ""
869 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200872 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200873 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200875 if dirname == ""
876 let dirname= getcwd()
877 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100878 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100879 " depending on whether backslashes have been converted to forward slashes by earlier code).
880 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200881 let dirname= b:netrw_curdir."/".dirname
882 endif
883 elseif dirname !~ '^/'
884 let dirname= b:netrw_curdir."/".dirname
885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100886" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200887 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100888" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
889" 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 +0200890 endif
891 if exists("w:netrw_bannercnt")
892 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
893 " If one wants to return the same place in the netrw window, use :Rex instead.
894 exe w:netrw_bannercnt
895 endif
896
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100897" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200898 " ---------------------------------------------------------------------
899 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
900" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100901" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200902" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100903" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200904" endif
905 " ---------------------------------------------------------------------
906
907 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
908 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
909 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
910 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
911 elseif a:indx <= 0
912 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100913" 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 +0200914 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100915" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200916 let s:didstarstar= 1
917 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
918 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
919 endif
920
921 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100922" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200923 if !exists("w:netrw_explore_indx")
924 let w:netrw_explore_indx= 0
925 endif
926
927 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100928" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200929
930 if indx == -1
931 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100932" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100934 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 +0200935 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100936" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100937 if @* != keepregstar | sil! let @* = keepregstar | endif
938 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100939 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200940 sil! let @/ = keepregslash
941" call Dret("netrw#Explore")
942 return
943 endif
944 let indx= w:netrw_explore_indx
945 if indx < 0 | let indx= 0 | endif
946 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
947 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100948" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200949 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
950 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 endwhile
953 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955
956 elseif indx == -2
957 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100958" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100960 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 +0200961 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100962" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100963 if @* != keepregstar | sil! let @* = keepregstar | endif
964 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100965 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200966 sil! let @/ = keepregslash
967" call Dret("netrw#Explore")
968 return
969 endif
970 let indx= w:netrw_explore_indx
971 if indx < 0 | let indx= 0 | endif
972 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
973 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100974" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200975 while indx >= 0 && curfile == w:netrw_explore_list[indx]
976 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 endwhile
979 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200981
982 else
983 " Explore -- initialize
984 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100985" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100986 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200987 let w:netrw_explore_indx= 0
988 if !exists("b:netrw_curdir")
989 let b:netrw_curdir= getcwd()
990 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100991" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200992
993 " switch on starpat to build the w:netrw_explore_list of files
994 if starpat == 1
995 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100996" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
997" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100999 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 catch /^Vim\%((\a\+)\)\=:E480/
1001 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1002" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1003 return
1004 endtry
1005 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1006 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1007
1008 elseif starpat == 2
1009 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001010" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1011" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001012 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001013 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001014 catch /^Vim\%((\a\+)\)\=:E480/
1015 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1016 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001017 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001018" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001019 if @* != keepregstar | sil! let @* = keepregstar | endif
1020 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001021 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001022 sil! let @/ = keepregslash
1023" call Dret("netrw#Explore : no files matched pattern")
1024 return
1025 endtry
1026 let s:netrw_curdir = b:netrw_curdir
1027 let w:netrw_explore_list = getqflist()
1028 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1029 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1030
1031 elseif starpat == 3
1032 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001033" 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 +02001034 let filepat= substitute(dirname,'^\*/','','')
1035 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1037" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001038 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1039 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1040
1041 elseif starpat == 4
1042 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001043" 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 +02001044 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1045 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1046 endif " switch on starpat to build w:netrw_explore_list
1047
1048 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001049" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1050" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001051
1052 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001053 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001054 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001055" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001056 if @* != keepregstar | sil! let @* = keepregstar | endif
1057 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001058 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001059 sil! let @/ = keepregslash
1060" call Dret("netrw#Explore : no files matched")
1061 return
1062 endif
1063 endif " if indx ... endif
1064
1065 " NetrwStatusLine support - for exploring support
1066 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001067" 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 +02001068
1069 " wrap the indx around, but issue a note
1070 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001071" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1073 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001074 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 endif
1076
1077 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001080" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001081
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001082" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001083 call netrw#LocalBrowseCheck(newdir)
1084 if !exists("w:netrw_liststyle")
1085 let w:netrw_liststyle= g:netrw_liststyle
1086 endif
1087 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001088 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001089 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001090 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001091 endif
1092 let w:netrw_explore_mtchcnt = indx + 1
1093 let w:netrw_explore_bufnr = bufnr("%")
1094 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001096" 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 +02001097
1098 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001099" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001100 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001101 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 +02001102 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001103 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001104" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001105 if @* != keepregstar | sil! let @* = keepregstar | endif
1106 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001107 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 sil! let @/ = keepregslash
1109" call Dret("netrw#Explore : missing +path_extra")
1110 return
1111 endif
1112
1113 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001114" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001115 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1116 sil! unlet w:netrw_treedict
1117 sil! unlet w:netrw_treetop
1118 endif
1119 let newdir= dirname
1120 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001121 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001123 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001124 endif
1125 endif
1126
1127 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001128" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1129" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001130 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001132 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001133 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 let s:explore_prvdir = b:netrw_curdir
1136 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001137 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 if b:netrw_curdir !~ '/$'
1139 let dirlen= dirlen + 1
1140 endif
1141 let prvfname= ""
1142 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001143" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001144 if fname =~ '^'.b:netrw_curdir
1145 if s:explore_match == ""
1146 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1147 else
1148 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1149 endif
1150 elseif fname !~ '^/' && fname != prvfname
1151 if s:explore_match == ""
1152 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1153 else
1154 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1155 endif
1156 endif
1157 let prvfname= fname
1158 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001159" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001160 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1161 exe "2match netrwMarkFile /".s:explore_match."/"
1162 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001163 endif
1164 echo "<s-up>==Pexplore <s-down>==Nexplore"
1165 else
1166 2match none
1167 if exists("s:explore_match") | unlet s:explore_match | endif
1168 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1169 echo " "
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001170" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001171 endif
1172
Bram Moolenaara6878372014-03-22 21:02:50 +01001173 " since Explore may be used to initialize netrw's browser,
1174 " there's no danger of a late FocusGained event on initialization.
1175 " Consequently, set s:netrw_events to 2.
1176 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001177 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001178" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001179 if @* != keepregstar | sil! let @* = keepregstar | endif
1180 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001181 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001182 sil! let @/ = keepregslash
1183" call Dret("netrw#Explore : @/<".@/.">")
1184endfun
1185
1186" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001187" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001188" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1189" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1190" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1191" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1192" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001194" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 let curwin= winnr()
1196
Bram Moolenaara6878372014-03-22 21:02:50 +01001197 if a:0 > 0 && a:1 != ""
1198 " if a netrw window is already on the left-side of the tab
1199 " and a directory has been specified, explore with that
1200 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001201" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001202 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001203" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001204 exe "1wincmd w"
1205 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001206" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 exe "Explore ".fnameescape(a1)
1208 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001209 let s:lexplore_win= curwin
1210 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001212" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 unlet t:netrw_lexposn
1214 endif
1215" call Dret("netrw#Lexplore")
1216 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001217 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001218 exe curwin."wincmd w"
1219 else
1220 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001221" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001222 endif
1223
Bram Moolenaar8d043172014-01-23 14:24:41 +01001224 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001226 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228 else
1229 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001230" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233
1234 if lexwinnr > 0
1235 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001236" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001237 exe lexwinnr."wincmd w"
1238 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001239 let t:netrw_lexposn = winsaveview()
1240" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001241" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001242 close
1243 if lexwinnr < curwin
1244 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001246 if lexwinnr != curwin
1247 exe curwin."wincmd w"
1248 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001249 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001250" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251
1252 else
1253 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001254" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001255 exe "1wincmd w"
1256 let keep_altv = g:netrw_altv
1257 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 if a:count != 0
1259 let netrw_winsize = g:netrw_winsize
1260 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001261 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001263" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 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 +02001265" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001267" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001268 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001270 elseif curfile =~ '^\a\{3,}://'
1271" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001272 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001273 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001274" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001275 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001276 endif
1277 if a:count != 0
1278 let g:netrw_winsize = netrw_winsize
1279 endif
1280 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001281 let g:netrw_altv = keep_altv
1282 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001283 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1284 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001285 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001286 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001287" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1288" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001289 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001290" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001291" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1292 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001293 unlet t:netrw_lexposn
1294 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001295 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001296
1297 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001298 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001299 if a:rightside
1300 let g:netrw_chgwin= 1
1301 else
1302 let g:netrw_chgwin= 2
1303 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001304" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001305 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001306
Bram Moolenaar8d043172014-01-23 14:24:41 +01001307" call Dret("netrw#Lexplore")
1308endfun
1309
1310" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001311" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001312" supports :NetrwClean -- remove netrw from first directory on runtimepath
1313" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001314fun! netrw#Clean(sys)
1315" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001316
1317 if a:sys
1318 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1319 else
1320 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1321 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001322" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001323 let diddel= 0
1324 let diddir= ""
1325
1326 if choice == 1
1327 for dir in split(&rtp,',')
1328 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001329" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001330 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1331 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1332 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1333 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1334 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1335 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 +00001336 let diddir= dir
1337 let diddel= diddel + 1
1338 if !a:sys|break|endif
1339 endif
1340 endfor
1341 endif
1342
1343 echohl WarningMsg
1344 if diddel == 0
1345 echomsg "netrw is either not installed or not removable"
1346 elseif diddel == 1
1347 echomsg "removed one copy of netrw from <".diddir.">"
1348 else
1349 echomsg "removed ".diddel." copies of netrw"
1350 endif
1351 echohl None
1352
Bram Moolenaara6878372014-03-22 21:02:50 +01001353" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001354endfun
1355
Bram Moolenaar5c736222010-01-06 20:54:52 +01001356" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001357" netrw#MakeTgt: make a target out of the directory name provided {{{2
1358fun! netrw#MakeTgt(dname)
1359" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1360 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001361 let svpos = winsaveview()
1362" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001363 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1364" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001365 if s:netrwmftgt_islocal
1366 let netrwmftgt= simplify(a:dname)
1367 else
1368 let netrwmftgt= a:dname
1369 endif
1370 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1371 " re-selected target, so just clear it
1372 unlet s:netrwmftgt s:netrwmftgt_islocal
1373 else
1374 let s:netrwmftgt= netrwmftgt
1375 endif
1376 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001377 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001378 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001379" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1380 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001381" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001382endfun
1383
Bram Moolenaara6878372014-03-22 21:02:50 +01001384" ---------------------------------------------------------------------
1385" netrw#Obtain: {{{2
1386" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001387" islocal=0 obtain from remote source
1388" =1 obtain from local source
1389" fname : a filename or a list of filenames
1390" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001391fun! netrw#Obtain(islocal,fname,...)
1392" 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 +02001393 " NetrwStatusLine support - for obtaining support
1394
1395 if type(a:fname) == 1
1396 let fnamelist= [ a:fname ]
1397 elseif type(a:fname) == 3
1398 let fnamelist= a:fname
1399 else
1400 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 +01001401" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001402 return
1403 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405 if a:0 > 0
1406 let tgtdir= a:1
1407 else
1408 let tgtdir= getcwd()
1409 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411
1412 if exists("b:netrw_islocal") && b:netrw_islocal
1413 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001414" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1416 let topath= s:ComposePath(tgtdir,"")
1417 if (has("win32") || has("win95") || has("win64") || has("win16"))
1418 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001419" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001421" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001422 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001423 if v:shell_error != 0
1424 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 +01001425" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001426 return
1427 endif
1428 endfor
1429 else
1430 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001431" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1432 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1433" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001434 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001435 if v:shell_error != 0
1436 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 +01001437" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001438 return
1439 endif
1440 endif
1441 elseif !exists("b:netrw_curdir")
1442 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1443 else
1444 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1445 endif
1446
1447 else
1448 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001449" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001450 if type(a:fname) == 1
1451 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1452 endif
1453 call s:NetrwMethod(b:netrw_curdir)
1454
1455 if b:netrw_method == 4
1456 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001457" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001458 if exists("g:netrw_port") && g:netrw_port != ""
1459 let useport= " ".g:netrw_scpport." ".g:netrw_port
1460 else
1461 let useport= ""
1462 endif
1463 if b:netrw_fname =~ '/'
1464 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1465 else
1466 let path= ""
1467 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001468 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001469 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 +02001470
1471 elseif b:netrw_method == 2
1472 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001474 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001475 let tmpbufnr= bufnr("%")
1476 setl ff=unix
1477 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001478 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001479" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 endif
1481
1482 if exists("b:netrw_fname") && b:netrw_fname != ""
1483 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001484" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 endif
1486
1487 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001488 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001489" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001490 endif
1491 for fname in fnamelist
1492 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 endfor
1495 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001496 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001497 else
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))
Bram Moolenaarff034192013-04-24 18:51:19 +02001499 endif
1500 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1501 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1502 let debugkeep= &debug
1503 setl debug=msg
1504 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1505 let &debug= debugkeep
1506 endif
1507
1508 elseif b:netrw_method == 3
1509 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001510" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001512 let tmpbufnr= bufnr("%")
1513 setl ff=unix
1514
1515 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001517" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001519 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001520" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 endif
1522
1523 if exists("g:netrw_uid") && g:netrw_uid != ""
1524 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001525 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001526" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001527 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001528 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001530" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001532 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001533" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001534 endif
1535 endif
1536
1537 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001538 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001539" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001540 endif
1541
1542 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001543 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001544" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 endif
1546
1547 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001548 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001549" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001550 endif
1551
1552 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001553 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001554" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001555 endif
1556 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001557 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001558 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001559" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001560
1561 " perform ftp:
1562 " -i : turns off interactive prompting from ftp
1563 " -n unix : DON'T use <.netrc>, even though it exists
1564 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001565 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1566 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001567 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001568 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1569 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001570" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001571 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001572 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001573 endif
1574 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001575
1576 elseif b:netrw_method == 9
1577 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001578" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001579 if a:fname =~ '/'
1580 let localfile= substitute(a:fname,'^.*/','','')
1581 else
1582 let localfile= a:fname
1583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001584 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 +02001585
Bram Moolenaarff034192013-04-24 18:51:19 +02001586 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001587 " probably a badly formed url; protocol not recognized
1588" call Dret("netrw#Obtain : unsupported method")
1589 return
1590
1591 else
1592 " protocol recognized but not supported for Obtain (yet?)
1593 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001594 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001595 endif
1596" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001597 return
1598 endif
1599
1600 " restore status line
1601 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001602 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001603 endif
1604
1605 endif
1606
1607 " cleanup
1608 if exists("tmpbufnr")
1609 if bufnr("%") != tmpbufnr
1610 exe tmpbufnr."bw!"
1611 else
1612 q!
1613 endif
1614 endif
1615
Bram Moolenaara6878372014-03-22 21:02:50 +01001616" call Dret("netrw#Obtain")
1617endfun
1618
1619" ---------------------------------------------------------------------
1620" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1621fun! netrw#Nread(mode,fname)
1622" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001623 let svpos= winsaveview()
1624" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001625 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001626" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1627 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001628
1629 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1630 if exists("w:netrw_bannercnt")
1631 " start with cursor just after the banner
1632 exe w:netrw_bannercnt
1633 endif
1634 endif
1635" call Dret("netrw#Nread")
1636endfun
1637
1638" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001639" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1640" Options get restored by s:NetrwOptionsRestore()
1641"
1642" Option handling:
1643" * save user's options (s:NetrwOptionsSave)
1644" * set netrw-safe options (s:NetrwOptionsSafe)
1645" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1646" * restore user's options (s:netrwOPtionsRestore)
1647" - restore a user option when != safe option (s:NetrwRestoreSetting)
1648" vt: (variable type) normally its either "w:" or "s:"
1649fun! s:NetrwOptionsSave(vt)
1650" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1651" 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 +02001652" 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>"))
1653" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001654
1655 if !exists("{a:vt}netrw_optionsave")
1656 let {a:vt}netrw_optionsave= 1
1657 else
1658" call Dret("s:NetrwOptionsSave : options already saved")
1659 return
1660 endif
1661" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1662
1663 " Save current settings and current directory
1664" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1665 let s:yykeep = @@
1666 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1667 let {a:vt}netrw_aikeep = &l:ai
1668 let {a:vt}netrw_awkeep = &l:aw
1669 let {a:vt}netrw_bhkeep = &l:bh
1670 let {a:vt}netrw_blkeep = &l:bl
1671 let {a:vt}netrw_btkeep = &l:bt
1672 let {a:vt}netrw_bombkeep = &l:bomb
1673 let {a:vt}netrw_cedit = &cedit
1674 let {a:vt}netrw_cikeep = &l:ci
1675 let {a:vt}netrw_cinkeep = &l:cin
1676 let {a:vt}netrw_cinokeep = &l:cino
1677 let {a:vt}netrw_comkeep = &l:com
1678 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001679 let {a:vt}netrw_cuckeep = &l:cuc
1680 let {a:vt}netrw_culkeep = &l:cul
1681" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001682 let {a:vt}netrw_diffkeep = &l:diff
1683 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1685 let {a:vt}netrw_ffkeep = &l:ff
1686 endif
1687 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1688 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001689 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001690 let {a:vt}netrw_hidkeep = &l:hidden
1691 let {a:vt}netrw_imkeep = &l:im
1692 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001693 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001694 let {a:vt}netrw_lskeep = &l:ls
1695 let {a:vt}netrw_makeep = &l:ma
1696 let {a:vt}netrw_magickeep = &l:magic
1697 let {a:vt}netrw_modkeep = &l:mod
1698 let {a:vt}netrw_nukeep = &l:nu
1699 let {a:vt}netrw_rnukeep = &l:rnu
1700 let {a:vt}netrw_repkeep = &l:report
1701 let {a:vt}netrw_rokeep = &l:ro
1702 let {a:vt}netrw_selkeep = &l:sel
1703 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001704 if !g:netrw_use_noswf
1705 let {a:vt}netrw_swfkeep = &l:swf
1706 endif
1707 let {a:vt}netrw_tskeep = &l:ts
1708 let {a:vt}netrw_twkeep = &l:tw " textwidth
1709 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1710 let {a:vt}netrw_wrapkeep = &l:wrap
1711 let {a:vt}netrw_writekeep = &l:write
1712
1713 " save a few selected netrw-related variables
1714" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1715 if g:netrw_keepdir
1716 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001717" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001718 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001719 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720 sil! let {a:vt}netrw_starkeep = @*
1721 sil! let {a:vt}netrw_pluskeep = @+
1722 endif
1723 sil! let {a:vt}netrw_slashkeep= @/
1724
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001725" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001726" 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>"))
1727" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1728endfun
1729
1730" ---------------------------------------------------------------------
1731" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1732" Use s:NetrwSaveOptions() to save user settings
1733" Use s:NetrwOptionsRestore() to restore user settings
1734fun! s:NetrwOptionsSafe(islocal)
1735" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1736" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1737" 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>"))
1738 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1739 call s:NetrwSetSafeSetting("&l:ai",0)
1740 call s:NetrwSetSafeSetting("&l:aw",0)
1741 call s:NetrwSetSafeSetting("&l:bl",0)
1742 call s:NetrwSetSafeSetting("&l:bomb",0)
1743 if a:islocal
1744 call s:NetrwSetSafeSetting("&l:bt","nofile")
1745 else
1746 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1747 endif
1748 call s:NetrwSetSafeSetting("&l:ci",0)
1749 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001750 if g:netrw_fastbrowse > a:islocal
1751 call s:NetrwSetSafeSetting("&l:bh","hide")
1752 else
1753 call s:NetrwSetSafeSetting("&l:bh","delete")
1754 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001755 call s:NetrwSetSafeSetting("&l:cino","")
1756 call s:NetrwSetSafeSetting("&l:com","")
1757 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1758 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1759 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001760 if &go =~ 'a' | set go-=a | endif
1761 if &go =~ 'A' | set go-=A | endif
1762 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001763 call s:NetrwSetSafeSetting("&l:hid",0)
1764 call s:NetrwSetSafeSetting("&l:im",0)
1765 setl isk+=@ isk+=* isk+=/
1766 call s:NetrwSetSafeSetting("&l:magic",1)
1767 if g:netrw_use_noswf
1768 call s:NetrwSetSafeSetting("swf",0)
1769 endif
1770 call s:NetrwSetSafeSetting("&l:report",10000)
1771 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1772 call s:NetrwSetSafeSetting("&l:spell",0)
1773 call s:NetrwSetSafeSetting("&l:tw",0)
1774 call s:NetrwSetSafeSetting("&l:wig","")
1775 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001776
1777 " set up cuc and cul based on g:netrw_cursor and listing style
1778 " COMBAK -- cuc cul related
1779 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001780
1781 " allow the user to override safe options
1782" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1783 if &ft == "netrw"
1784" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1785 keepalt NetrwKeepj doau FileType netrw
1786 endif
1787
1788" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1789" 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>"))
1790" call Dret("s:NetrwOptionsSafe")
1791endfun
1792
1793" ---------------------------------------------------------------------
1794" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1795fun! s:NetrwOptionsRestore(vt)
1796" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001797" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001798" 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 +01001799 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001800" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01001801 if filereadable(expand("%"))
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001802" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001803 filetype detect
1804" call Decho("..settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
1805 else
1806 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001807 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001808" call Decho("..ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001809" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001810 return
1811 endif
1812 unlet {a:vt}netrw_optionsave
1813
1814 if exists("+acd")
1815 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001816" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001817 let curdir = getcwd()
1818 let &l:acd = {a:vt}netrw_acdkeep
1819 unlet {a:vt}netrw_acdkeep
1820 if &l:acd
1821 call s:NetrwLcd(curdir)
1822 endif
1823 endif
1824 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001825" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001826 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1827 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1828 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1829 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1830 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001831" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001832 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1833 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1834 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1835 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1836 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001837" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001838 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1839 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1840 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1841 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1842 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001843 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001844" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1845 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1846 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001847 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001848 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1849" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1850 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1851 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1852" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1853 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1854" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1855 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1856 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001857 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1859 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1860" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1861 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1862 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1863 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1864 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1865" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001866 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001867 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1868 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1869 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001870 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001871" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001872 call s:NetrwRestoreSetting("s:yykeep","@@")
1873 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1874 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1875 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1876 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1877
Bram Moolenaara6878372014-03-22 21:02:50 +01001878 if exists("{a:vt}netrw_swfkeep")
1879 if &directory == ""
1880 " user hasn't specified a swapfile directory;
1881 " netrw will temporarily set the swapfile directory
1882 " to the current directory as returned by getcwd().
1883 let &l:directory= getcwd()
1884 sil! let &l:swf = {a:vt}netrw_swfkeep
1885 setl directory=
1886 unlet {a:vt}netrw_swfkeep
1887 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001888 if !g:netrw_use_noswf
1889 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1890 sil! let &l:swf= {a:vt}netrw_swfkeep
1891 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001892 unlet {a:vt}netrw_swfkeep
1893 endif
1894 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001895 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001896 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1897 if exists("{a:vt}netrw_dirkeep")
1898 call s:NetrwLcd(dirkeep)
1899 unlet {a:vt}netrw_dirkeep
1900 endif
1901 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001902 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001903" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001904 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1905 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001906 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001907 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001908
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001909" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1910" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1911" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1912" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1913" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001914 " Moved the filetype detect here from NetrwGetFile() because remote files
1915 " were having their filetype detect-generated settings overwritten by
1916 " NetrwOptionRestore.
1917 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001918" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1919 filetype detect
1920" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001921 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001922" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001923" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001924" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001925endfun
1926
1927" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001928" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1929" but only when the options' value and the safe setting differ
1930" Doing this means that netrw will not come up as having changed a
1931" setting last when it really didn't actually change it.
1932"
1933" Called from s:NetrwOptionsSafe
1934" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1935fun! s:NetrwSetSafeSetting(setting,safesetting)
1936" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001937
Bram Moolenaar85850f32019-07-19 22:05:51 +02001938 if a:setting =~ '^&'
1939" call Decho("fyi: a:setting starts with &")
1940 exe "let settingval= ".a:setting
1941" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001942
Bram Moolenaar85850f32019-07-19 22:05:51 +02001943 if settingval != a:safesetting
1944" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1945 if type(a:safesetting) == 0
1946 exe "let ".a:setting."=".a:safesetting
1947 elseif type(a:safesetting) == 1
1948 exe "let ".a:setting."= '".a:safesetting."'"
1949 else
1950 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1951 endif
1952 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001953 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001954
Bram Moolenaar85850f32019-07-19 22:05:51 +02001955" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001956endfun
1957
1958" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001959" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1960" but only if the setting value differs from the associated keepvar.
1961" Doing this means that netrw will not come up as having changed a
1962" setting last when it really didn't actually change it.
1963"
1964" Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
1965" keepvars are set up by s:NetrwOptionsSave
1966fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001967""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001968
Bram Moolenaar85850f32019-07-19 22:05:51 +02001969 " typically called from s:NetrwOptionsRestore
1970 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1971 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001972 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001973 if exists(a:keepvar)
1974 exe "let keepvarval= ".a:keepvar
1975 exe "let setting= ".a:setting
1976
1977"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1978"" call Decho("fyi: keepvarval=".keepvarval)
1979"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1980
1981 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001982"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001983 if type(a:setting) == 0
1984 exe "let ".a:setting."= ".keepvarval
1985 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001986 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001987 else
1988 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1989 endif
1990 endif
1991
1992 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001993 endif
1994
Bram Moolenaar85850f32019-07-19 22:05:51 +02001995"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001996endfun
1997
1998" ---------------------------------------------------------------------
1999" NetrwStatusLine: {{{2
2000fun! NetrwStatusLine()
2001
2002" vvv NetrwStatusLine() debugging vvv
2003" let g:stlmsg=""
2004" if !exists("w:netrw_explore_bufnr")
2005" let g:stlmsg="!X<explore_bufnr>"
2006" elseif w:netrw_explore_bufnr != bufnr("%")
2007" let g:stlmsg="explore_bufnr!=".bufnr("%")
2008" endif
2009" if !exists("w:netrw_explore_line")
2010" let g:stlmsg=" !X<explore_line>"
2011" elseif w:netrw_explore_line != line(".")
2012" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2013" endif
2014" if !exists("w:netrw_explore_list")
2015" let g:stlmsg=" !X<explore_list>"
2016" endif
2017" ^^^ NetrwStatusLine() debugging ^^^
2018
2019 if !exists("w:netrw_explore_bufnr") || w:netrw_explore_bufnr != bufnr("%") || !exists("w:netrw_explore_line") || w:netrw_explore_line != line(".") || !exists("w:netrw_explore_list")
2020 " restore user's status line
2021 let &stl = s:netrw_users_stl
2022 let &laststatus = s:netrw_users_ls
2023 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2024 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2025 return ""
2026 else
2027 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2028 endif
2029endfun
2030
Bram Moolenaar85850f32019-07-19 22:05:51 +02002031" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002032" Netrw Transfer Functions: {{{1
2033" ===============================
2034
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002036" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002037" mode: =0 read remote file and insert before current line
2038" =1 read remote file and insert after current line
2039" =2 replace with remote file
2040" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002041fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002042" call Dfunc("netrw#NetRead(mode=".a:mode.",...) a:0=".a:0." ".g:loaded_netrw.((a:0 > 0)? " a:1<".a:1.">" : ""))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043
Bram Moolenaar5c736222010-01-06 20:54:52 +01002044 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002045 call s:NetrwOptionsSave("w:")
2046 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002047 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002048 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2049 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2050 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002051" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002052
Bram Moolenaar5c736222010-01-06 20:54:52 +01002053 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002055 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 elseif a:mode == 2 " replace with remote file
2059 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002060 elseif a:mode == 3 " skip read of file (leave as temporary)
2061 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062 else
2063 exe a:mode
2064 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002065 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002067" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002068
Bram Moolenaar5c736222010-01-06 20:54:52 +01002069 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002070 let tmpfile= s:GetTempfile("")
2071 if tmpfile == ""
2072" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002073 return
2074 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002077
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 " attempt to repeat with previous host-file-etc
2079 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002080" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 let choice = b:netrw_lastfile
2082 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002083
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002084 else
2085 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002086" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002087
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002089 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002090 echomsg 'NetRead Usage:'
2091 echomsg ':Nread machine:path uses rcp'
2092 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2093 echomsg ':Nread "machine id password path" uses ftp'
2094 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2095 echomsg ':Nread fetch://machine/path uses fetch'
2096 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2097 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002098 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002099 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002100 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2101 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2102 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2103 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002104 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002105 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002106
Bram Moolenaar9964e462007-05-05 17:54:07 +00002107 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002108 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002109" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002110 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002112 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 else
2114 " case "... ... ..."
2115 let choice = strpart(choice,1,strlen(choice)-1)
2116 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002117
Bram Moolenaar9964e462007-05-05 17:54:07 +00002118 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002119 let wholechoice = wholechoice . " " . choice
2120 let ichoice = ichoice + 1
2121 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002122 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002123 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002124 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002125" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002126 return
2127 endif
2128 let choice= a:{ichoice}
2129 endwhile
2130 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2131 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132 endif
2133 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002135" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002136 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002137
Bram Moolenaar5c736222010-01-06 20:54:52 +01002138 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002139 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002140 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002141" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002142 return
2143 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002144 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002145
Bram Moolenaar8d043172014-01-23 14:24:41 +01002146 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002147" call Decho("checking if NetrwBrowse() should handle choice<".choice."> with netrw_list_cmd<".g:netrw_list_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02002148 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002149" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002150 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002151" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002154
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002156 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002157 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002158 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2159 echo "(netrw) Processing your read request..."
2160 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002161
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002163 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002165" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002166 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002168 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 " ER: the tmpfile is full path: rcp sees C:\... as host C
2170 if s:netrw_has_nt_rcp == 1
2171 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2172 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2173 else
2174 " Any way needed it machine contains a '.'
2175 let uid_machine = g:netrw_machine .'.'. $USERNAME
2176 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002178 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2179 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2180 else
2181 let uid_machine = g:netrw_machine
2182 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002183 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002184 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002185 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002187
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002189 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002192 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002193 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002194 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002195 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002196 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002198 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002199 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002201 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002202 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002203" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002204 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002206 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 endif
2209 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar83bab712005-08-01 21:58:57 +00002210 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002211 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002212 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002213 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002214 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002215 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002216 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002217 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002218 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2219 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002220 q!
2221 endif
2222 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002223 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002225
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002227 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2229 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002230" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002231 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002232 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002233 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002234 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002235 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002237" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002238 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002239 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002240" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002241 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002242
Bram Moolenaar97d62492012-11-15 21:28:22 +01002243 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002244 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002246" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002248 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002252 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002253" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002254 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002255 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002256
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002257 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002258 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002259" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002260 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002261 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002264 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002265 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002266" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002267
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 " perform ftp:
2269 " -i : turns off interactive prompting from ftp
2270 " -n unix : DON'T use <.netrc>, even though it exists
2271 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002272 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002273 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2275 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002277 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002278 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002279 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002281 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002282 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002284
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002286 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002288" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002290 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 else
2292 let useport= ""
2293 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002294 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2295 " This is workaround to avoid mis-handle windows local-path:
2296 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2297 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2298 else
2299 let tmpfile_get = tmpfile
2300 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002301 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".escape(s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1),' ')." ".s:ShellEscape(tmpfile_get,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002302 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002304
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002306 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002307 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002308" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002309 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002310 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002311 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002312 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002313" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002314 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002315 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002316
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002317 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2318 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002319" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002320 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1)." ".g:netrw_http_xcmd." ".s:ShellEscape(tmpfile,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002322 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.b:netrw_fname,1))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002324 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002325 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002326
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002327 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002328 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002330 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2331 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002332" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2333" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2334 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(b:netrw_http."://".g:netrw_machine.netrw_html,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002335 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002336" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002337 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002338 endif
2339 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002341 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002342
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002343 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002344 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002345 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002346" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002347
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 if !executable(g:netrw_dav_cmd)
2349 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2350" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2351 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002352 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002354 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_dav_cmd." ".s:ShellEscape("dav://".g:netrw_machine.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 else
2356 " Construct execution string (four lines) which will be passed through filter
2357 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2358 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002359 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002360 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002362 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002363 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002365 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002366 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002367 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002368 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2369 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002370
Bram Moolenaar5c736222010-01-06 20:54:52 +01002371 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002372 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002373 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002374 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002375 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002376 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002377 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002378
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002379 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002380 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002381 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002382" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002383 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1)." ".s:ShellEscape(tmpfile,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002384 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002386
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002388 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002390 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002391" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002393 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002394 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002395 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002396" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002397 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002398 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002399 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002400 let netrw_option= "http"
2401 else
2402 let netrw_option= "ftp"
2403 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002404" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002405
Bram Moolenaar446cb832008-06-24 21:56:24 +00002406 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002407 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_uid.':'.s:netrw_passwd.'@'.g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002408 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002410 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002411
Bram Moolenaar446cb832008-06-24 21:56:24 +00002412 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002413 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002414" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002415 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002416
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002418 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002419 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002420" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2421 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_sftp_cmd." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002422 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002423 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002424
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002426 " NetRead: (file) NetRead Method #10 {{{3
2427 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002428" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2429 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002430 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2431 let b:netrw_lastfile = choice
2432
2433 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002434 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002435 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002436 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 endif
2438 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002439
Bram Moolenaar5c736222010-01-06 20:54:52 +01002440 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002442" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002443 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 unlet b:netrw_fname
2445 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002446 if s:FileReadable(tmpfile) && tmpfile !~ '.tar.bz2$' && tmpfile !~ '.tar.gz$' && tmpfile !~ '.zip' && tmpfile !~ '.tar' && readcmd != 't' && tmpfile !~ '.tar.xz$' && tmpfile !~ '.txz'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002447" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002448 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002449 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002450 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002451
Bram Moolenaar9964e462007-05-05 17:54:07 +00002452" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002453endfun
2454
2455" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002456" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002457fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002458" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002459
Bram Moolenaar5c736222010-01-06 20:54:52 +01002460 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002461 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002462 call s:NetrwOptionsSave("w:")
2463 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002464
Bram Moolenaar5c736222010-01-06 20:54:52 +01002465 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002466 let tmpfile= s:GetTempfile("")
2467 if tmpfile == ""
2468" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002469 return
2470 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002471
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002472 if a:0 == 0
2473 let ichoice = 0
2474 else
2475 let ichoice = 1
2476 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002477
Bram Moolenaar9964e462007-05-05 17:54:07 +00002478 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002479" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002480 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002481 " For binary writes, always write entire file.
2482 " (line numbers don't really make sense for that).
2483 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002484" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002485 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002486 elseif g:netrw_cygwin
2487 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002488 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002489" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002490 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002491 else
2492 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002493" call Decho("(write selected portion) sil exe ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002494 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002495 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002496
Bram Moolenaar9964e462007-05-05 17:54:07 +00002497 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002498 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002499 " on the temporary file's name. Deletion of the temporary file during
2500 " cleanup then causes an error message.
2501 0file!
2502 endif
2503
Bram Moolenaar5c736222010-01-06 20:54:52 +01002504 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002506
Bram Moolenaar9964e462007-05-05 17:54:07 +00002507 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002508 " attempt to repeat with previous host-file-etc
2509 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002510" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002511 let choice = b:netrw_lastfile
2512 let ichoice= ichoice + 1
2513 else
2514 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002515
Bram Moolenaar8d043172014-01-23 14:24:41 +01002516 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002517 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002518 echomsg 'NetWrite Usage:"'
2519 echomsg ':Nwrite machine:path uses rcp'
2520 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2521 echomsg ':Nwrite "machine id password path" uses ftp'
2522 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2523 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2524 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2525 echomsg ':Nwrite rcp://machine/path uses rcp'
2526 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2527 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2528 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002529 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002530 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002531
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002532 elseif match(choice,"^\"") != -1
2533 if match(choice,"\"$") != -1
2534 " case "..."
2535 let choice=strpart(choice,1,strlen(choice)-2)
2536 else
2537 " case "... ... ..."
2538 let choice = strpart(choice,1,strlen(choice)-1)
2539 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002540
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002541 while match(choice,"\"$") == -1
2542 let wholechoice= wholechoice . " " . choice
2543 let ichoice = ichoice + 1
2544 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002545 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002546 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002547 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002548" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002549 return
2550 endif
2551 let choice= a:{ichoice}
2552 endwhile
2553 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2554 endif
2555 endif
2556 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002557 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002558" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002559
Bram Moolenaar9964e462007-05-05 17:54:07 +00002560 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002561 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002562 if !exists("b:netrw_method") || b:netrw_method < 0
2563" call Dfunc("netrw#NetWrite : unsupported method")
2564 return
2565 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002566
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002568 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002569 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002570 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2571 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002572" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002573 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002574
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002575 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002576 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002577 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002578" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002579 if s:netrw_has_nt_rcp == 1
2580 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2581 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2582 else
2583 let uid_machine = g:netrw_machine .'.'. $USERNAME
2584 endif
2585 else
2586 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2587 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2588 else
2589 let uid_machine = g:netrw_machine
2590 endif
2591 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002592 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rcp_cmd." ".s:netrw_rcpmode." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(uid_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002593 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002594
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002595 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002596 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002597 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002598" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002599 let netrw_fname = b:netrw_fname
2600
2601 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2602 let bhkeep = &l:bh
2603 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002604 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002606
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002608 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002609 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002611 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002612 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002614 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002615 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002616" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002618 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002620" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2621 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 endif
2623 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2624 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002625 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002626 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002627 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002628 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002629 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002630
2631 " remove enew buffer (quietly)
2632 let filtbuf= bufnr("%")
2633 exe curbuf."b!"
2634 let &l:bh = bhkeep
2635 exe filtbuf."bw!"
2636
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002638
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002639 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002641 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002642 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002643" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 let netrw_fname = b:netrw_fname
2645 let bhkeep = &l:bh
2646
2647 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2648 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002649 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002650 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002651 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002652
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002654 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002656 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002657 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002659 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002660 if exists("g:netrw_uid") && g:netrw_uid != ""
2661 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002665 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002671 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002672 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002675 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002676 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002677" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002678 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002679 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002680" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002681 " save choice/id/password for future use
2682 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002683
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002684 " perform ftp:
2685 " -i : turns off interactive prompting from ftp
2686 " -n unix : DON'T use <.netrc>, even though it exists
2687 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002688 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002689 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002690 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2691 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002692 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002693 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002694 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002695 let mod=1
2696 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002697
2698 " remove enew buffer (quietly)
2699 let filtbuf= bufnr("%")
2700 exe curbuf."b!"
2701 let &l:bh= bhkeep
2702 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002703
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002705 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002706 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002708 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002709 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710 else
2711 let useport= ""
2712 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002713 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.useport." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.":".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002715
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002716 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002717 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002718 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002719" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002720 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2721 if executable(curl)
2722 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002723 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_http_put_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(url,1) )
Bram Moolenaar8d043172014-01-23 14:24:41 +01002724 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002725 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002726 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002727
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002728 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002729 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002730 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002731" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002732
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002733 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002734 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2735 let bhkeep = &l:bh
2736
2737 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2738 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002739 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002740 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002741
Bram Moolenaarff034192013-04-24 18:51:19 +02002742 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002743 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002744 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002745 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002746 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002748 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002749 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002750 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002751 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002752
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002753 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002754 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002755 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002756
2757 " remove enew buffer (quietly)
2758 let filtbuf= bufnr("%")
2759 exe curbuf."b!"
2760 let &l:bh = bhkeep
2761 exe filtbuf."bw!"
2762
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002763 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002764
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002765 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002766 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002767 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002768" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002769 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_rsync_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(g:netrw_machine.g:netrw_rsync_sep.b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002770 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002771
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002772 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002773 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002774 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002775" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002776 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2778 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2779 else
2780 let uid_machine = g:netrw_machine
2781 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002782
2783 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2784 let bhkeep = &l:bh
2785 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002786 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002788
Bram Moolenaarff034192013-04-24 18:51:19 +02002789 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002790 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002791" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002792 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002793 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002794 let filtbuf= bufnr("%")
2795 exe curbuf."b!"
2796 let &l:bh = bhkeep
2797 exe filtbuf."bw!"
2798 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002799
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002800 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002801 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002802 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002803 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002804 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002806 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002807
Bram Moolenaar5c736222010-01-06 20:54:52 +01002808 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002809" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002810 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002811" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002812 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002813 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002814 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002815
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002816 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002817 " restore modifiability; usually equivalent to set nomod
2818 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002819" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02002820 elseif !exists("leavemod")
2821 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002823 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002824" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002826
Bram Moolenaar9964e462007-05-05 17:54:07 +00002827" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002828endfun
2829
2830" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002831" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002832" uses NetRead to get a copy of the file into a temporarily file,
2833" then sources that file,
2834" then removes that file.
2835fun! netrw#NetSource(...)
2836" call Dfunc("netrw#NetSource() a:0=".a:0)
2837 if a:0 > 0 && a:1 == '?'
2838 " give help
2839 echomsg 'NetSource Usage:'
2840 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2841 echomsg ':Nsource fetch://machine/path uses fetch'
2842 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002843 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002844 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2845 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2846 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2847 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2848 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002849 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002851 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002852 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002853" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002856 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002858 if delete(s:netrw_tmpfile)
2859 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2860 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002861 unlet s:netrw_tmpfile
2862 else
2863 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2864 endif
2865 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002866 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002867 endif
2868" call Dret("netrw#NetSource")
2869endfun
2870
Bram Moolenaar8d043172014-01-23 14:24:41 +01002871" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002872" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2873" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002874fun! netrw#SetTreetop(iscmd,...)
2875" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2876" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002877
Bram Moolenaar85850f32019-07-19 22:05:51 +02002878 " iscmd==0: netrw#SetTreetop called using gn mapping
2879 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2880" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002881 " clear out the current tree
2882 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002883" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002884 let inittreetop= w:netrw_treetop
2885 unlet w:netrw_treetop
2886 endif
2887 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002889 unlet w:netrw_treedict
2890 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002891" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002892
Bram Moolenaar85850f32019-07-19 22:05:51 +02002893 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002894 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002896 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002897 if isdirectory(s:NetrwFile(a:1))
2898" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002899 let treedir = a:1
2900 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002902 let treedir = b:netrw_curdir."/".a:1
2903 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002904" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002905 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906 " normally the cursor is left in the message window.
2907 " However, here this results in the directory being listed in the message window, which is not wanted.
2908 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002909 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002911 let treedir = "."
2912 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002913 endif
2914 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002916
2917 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002918 let islocal= expand("%") !~ '^\a\{3,}://'
2919" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002920
2921 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002922 if islocal
2923 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2924 else
2925 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2926 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002927
Bram Moolenaara6878372014-03-22 21:02:50 +01002928" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002929endfun
2930
Bram Moolenaar9964e462007-05-05 17:54:07 +00002931" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002932" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002933" readcmd == %r : replace buffer with newly read file
2934" == 0r : read file at top of buffer
2935" == r : read file after current line
2936" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002937fun! s:NetrwGetFile(readcmd, tfile, method)
2938" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002939
2940 " readcmd=='t': simply do nothing
2941 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002942" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01002943" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002944 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002945 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002946
Bram Moolenaar9964e462007-05-05 17:54:07 +00002947 " get name of remote filename (ie. url and all)
2948 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002949" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002950
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 if exists("*NetReadFixup")
2952 " for the use of NetReadFixup (not otherwise used internally)
2953 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002954 endif
2955
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956 if a:readcmd[0] == '%'
2957 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002958" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959
2960 " rename the current buffer to the temp file (ie. tfile)
2961 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002962 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963 else
2964 let tfile= a:tfile
2965 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002966 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967
2968 " edit temporary file (ie. read the temporary file in)
2969 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971 call zip#Browse(tfile)
2972 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002973" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002974 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002975 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002977 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002978 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002979" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002980 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002981 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002982" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002983 call tar#Browse(tfile)
2984 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002985" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002986 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002988" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002989 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002990 endif
2991
2992 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002993 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002994
Bram Moolenaar71badf92023-04-22 22:40:14 +01002995 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002996 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002997 " Note that isk must not include a "/" for scripts.vim
2998 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002999" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3000" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003001" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003002" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3003 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003004 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003005 filetype detect
3006" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3007 let &isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003008" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003009 let line1 = 1
3010 let line2 = line("$")
3011
Bram Moolenaar8d043172014-01-23 14:24:41 +01003012 elseif !&ma
3013 " attempting to read a file after the current line in the file, but the buffer is not modifiable
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003014 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003015" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003016 return
3017
Bram Moolenaar9964e462007-05-05 17:54:07 +00003018 elseif s:FileReadable(a:tfile)
3019 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003020" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003021 let curline = line(".")
3022 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003023" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003024 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003025 let line1= curline + 1
3026 let line2= line("$") - lastline + 1
3027
3028 else
3029 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003030" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3031" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003032 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003033" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003034 return
3035 endif
3036
3037 " User-provided (ie. optional) fix-it-up command
3038 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003039" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003040 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003041" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003042" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003043 endif
3044
Bram Moolenaaradc21822011-04-01 18:03:16 +02003045 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003046 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003047 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003048 endif
3049
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003050" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003051
3052 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003053" redraw!
3054
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003055" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003056" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003057endfun
3058
Bram Moolenaar9964e462007-05-05 17:54:07 +00003059" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003060" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003061" Input:
3062" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3063" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003064" b:netrw_method= 1: rcp
3065" 2: ftp + <.netrc>
3066" 3: ftp + machine, id, password, and [path]filename
3067" 4: scp
3068" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003069" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003070" 7: rsync
3071" 8: fetch
3072" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003073" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003074" g:netrw_machine= hostname
3075" b:netrw_fname = filename
3076" g:netrw_port = optional port number (for ftp)
3077" g:netrw_choice = copy of input url (choice)
3078fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003079" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003080
Bram Moolenaar251e1912011-06-19 05:09:16 +02003081 " sanity check: choice should have at least three slashes in it
3082 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3083 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3084 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003085" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003086 return
3087 endif
3088
Bram Moolenaar5c736222010-01-06 20:54:52 +01003089 " record current g:netrw_machine, if any
3090 " curmachine used if protocol == ftp and no .netrc
3091 if exists("g:netrw_machine")
3092 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003093" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003094 else
3095 let curmachine= "N O T A HOST"
3096 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003097 if exists("g:netrw_port")
3098 let netrw_port= g:netrw_port
3099 endif
3100
3101 " insure that netrw_ftp_cmd starts off every method determination
3102 " with the current g:netrw_ftp_cmd
3103 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003104
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 " initialization
3106 let b:netrw_method = 0
3107 let g:netrw_machine = ""
3108 let b:netrw_fname = ""
3109 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003110 let g:netrw_choice = a:choice
3111
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003113 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003114 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3115 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003116 " rcpurm : rcp://[user@]host/filename Use rcp
3117 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003118 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003119 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003120 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 " rsyncurm : rsync://host[:port]/path Use rsync
3122 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3123 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003124 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3126 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003127 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3128 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003130 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003131 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003132 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003134 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003136 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003137
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003138" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003140 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003141 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003142" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003143 let b:netrw_method = 1
3144 let userid = substitute(a:choice,rcpurm,'\1',"")
3145 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3146 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 if userid != ""
3148 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003150
Bram Moolenaaradc21822011-04-01 18:03:16 +02003151 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003152 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003153" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003154 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003155 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3156 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3157 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003158
Bram Moolenaar15146672011-10-20 22:22:38 +02003159 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003160 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003161" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 let b:netrw_method = 5
3163 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3164 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003165 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003166
Bram Moolenaaradc21822011-04-01 18:03:16 +02003167 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003168 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003169" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003170 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003171 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003172 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3173 else
3174 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3175 endif
3176 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003177
Bram Moolenaaradc21822011-04-01 18:03:16 +02003178 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003179 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003180" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003181 let b:netrw_method = 7
3182 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3183 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003184
Bram Moolenaaradc21822011-04-01 18:03:16 +02003185 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003187" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003188 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003189 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3190 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3191 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003192" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003193 if userid != ""
3194 let g:netrw_uid= userid
3195 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003196
Bram Moolenaaradc21822011-04-01 18:03:16 +02003197 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003198 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003199 call NetUserPass("ftp:".g:netrw_machine)
3200 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003201 " if there's a change in hostname, require password re-entry
3202 unlet s:netrw_passwd
3203 endif
3204 if exists("netrw_port")
3205 unlet netrw_port
3206 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003207 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003208
Bram Moolenaar446cb832008-06-24 21:56:24 +00003209 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003210 let b:netrw_method = 3
3211 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003212 let host= substitute(g:netrw_machine,'\..*$','','')
3213 if exists("s:netrw_hup[host]")
3214 call NetUserPass("ftp:".host)
3215
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003216 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003217" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3218" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003219 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003220 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003221" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003222 endif
3223 let b:netrw_method= 2
3224 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003225" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 let b:netrw_method= 2
3227 else
3228 if !exists("g:netrw_uid") || g:netrw_uid == ""
3229 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003230 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003231 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003232 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003233 endif
3234 let b:netrw_method= 3
3235 endif
3236 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003237
Bram Moolenaaradc21822011-04-01 18:03:16 +02003238 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003239 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003240" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 let b:netrw_method = 8
3242 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3243 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3244 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3245 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003246
Bram Moolenaaradc21822011-04-01 18:03:16 +02003247 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003249" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003251 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3252 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003253 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003254 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003255 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003256
Bram Moolenaaradc21822011-04-01 18:03:16 +02003257 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003259" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003260 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003261 let b:netrw_method = 3
3262 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3263 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003264
Bram Moolenaar9964e462007-05-05 17:54:07 +00003265 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003266 let b:netrw_method = 2
3267 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3268 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3269 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003270
Bram Moolenaaradc21822011-04-01 18:03:16 +02003271 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003272 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003273" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003274 let b:netrw_method = 9
3275 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3276 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003277
Bram Moolenaaradc21822011-04-01 18:03:16 +02003278 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003279 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003280" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003281 let b:netrw_method = 1
3282 let userid = substitute(a:choice,rcphf,'\2',"")
3283 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3284 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003285" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3286" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3287" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3288" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003289 if userid != ""
3290 let g:netrw_uid= userid
3291 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003292
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003293 " Method#10: file://user@hostname/...path-to-file {{{3
3294 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003295" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003296 let b:netrw_method = 10
3297 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003298" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003299
Bram Moolenaaradc21822011-04-01 18:03:16 +02003300 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003301 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003302 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003303 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003304 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003305 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003307 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003308
Bram Moolenaar81695252004-12-29 20:58:21 +00003309 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003310 " remove any leading [:#] from port number
3311 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3312 elseif exists("netrw_port")
3313 " retain port number as implicit for subsequent ftp operations
3314 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003315 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003316
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003317" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3318" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3319" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3320" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003321" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003323" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003324" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003325" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003326" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003327" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003328" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
3331" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003332" NetReadFixup: this sort of function is typically written by the user {{{2
3333" to handle extra junk that their system's ftp dumps
3334" into the transfer. This function is provided as an
3335" example and as a fix for a Windows 95 problem: in my
3336" experience, win95's ftp always dumped four blank lines
3337" at the end of the transfer.
3338if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3339 fun! NetReadFixup(method, line1, line2)
3340" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003341
3342 " sanity checks -- attempt to convert inputs to integers
3343 let method = a:method + 0
3344 let line1 = a:line1 + 0
3345 let line2 = a:line2 + 0
3346 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3347" call Dret("NetReadFixup")
3348 return
3349 endif
3350
Bram Moolenaar9964e462007-05-05 17:54:07 +00003351 if method == 3 " ftp (no <.netrc>)
3352 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003353 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003354 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003355 call histdel("/",-1)
3356 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003357 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003358
Bram Moolenaar9964e462007-05-05 17:54:07 +00003359" call Dret("NetReadFixup")
3360 endfun
3361endif
3362
3363" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003364" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003365" Usage: :call NetUserPass() -- will prompt for userid and password
3366" :call NetUserPass("uid") -- will prompt for password
3367" :call NetUserPass("uid","password") -- sets global userid and password
3368" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3369" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370fun! NetUserPass(...)
3371
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003372" call Dfunc("NetUserPass() a:0=".a:0)
3373
3374 if !exists('s:netrw_hup')
3375 let s:netrw_hup= {}
3376 endif
3377
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003379 " case: no input arguments
3380
3381 " change host and username if not previously entered; get new password
3382 if !exists("g:netrw_machine")
3383 let g:netrw_machine= input('Enter hostname: ')
3384 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003386 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 let g:netrw_uid= input('Enter username: ')
3388 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003389 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003390 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003391
3392 " set up hup database
3393 let host = substitute(g:netrw_machine,'\..*$','','')
3394 if !exists('s:netrw_hup[host]')
3395 let s:netrw_hup[host]= {}
3396 endif
3397 let s:netrw_hup[host].uid = g:netrw_uid
3398 let s:netrw_hup[host].passwd = s:netrw_passwd
3399
3400 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003401 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003402
3403 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003404 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003405 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003406" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003407 let host = substitute(a:1,'^ftp:','','')
3408 let host = substitute(host,'\..*','','')
3409 if exists("s:netrw_hup[host]")
3410 let g:netrw_uid = s:netrw_hup[host].uid
3411 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003412" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3413" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003414 else
3415 let g:netrw_uid = input("Enter UserId: ")
3416 let s:netrw_passwd = inputsecret("Enter Password: ")
3417 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003418
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003419 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003420 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003421" 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 +02003422 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003423 if g:netrw_machine =~ '[0-9.]\+'
3424 let host= g:netrw_machine
3425 else
3426 let host= substitute(g:netrw_machine,'\..*$','','')
3427 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003428 else
3429 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003430 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003431 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003432" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003433 if exists("g:netrw_passwd")
3434 " ask for password if one not previously entered
3435 let s:netrw_passwd= g:netrw_passwd
3436 else
3437 let s:netrw_passwd = inputsecret("Enter Password: ")
3438 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003439 endif
3440
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003441" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003442 if exists("host")
3443 if !exists('s:netrw_hup[host]')
3444 let s:netrw_hup[host]= {}
3445 endif
3446 let s:netrw_hup[host].uid = g:netrw_uid
3447 let s:netrw_hup[host].passwd = s:netrw_passwd
3448 endif
3449
3450 elseif a:0 == 2
3451 let g:netrw_uid = a:1
3452 let s:netrw_passwd = a:2
3453
3454 elseif a:0 == 3
3455 " enter hostname, user-id, and password into the hup dictionary
3456 let host = substitute(a:1,'^\a\+:','','')
3457 let host = substitute(host,'\..*$','','')
3458 if !exists('s:netrw_hup[host]')
3459 let s:netrw_hup[host]= {}
3460 endif
3461 let s:netrw_hup[host].uid = a:2
3462 let s:netrw_hup[host].passwd = a:3
3463 let g:netrw_uid = s:netrw_hup[host].uid
3464 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003465" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3466" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003468
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003469" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471
Bram Moolenaar85850f32019-07-19 22:05:51 +02003472" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003473" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003474" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003476" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003477" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3478fun! s:ExplorePatHls(pattern)
3479" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3480 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003481" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003482 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003483" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003484 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3485" call Dret("s:ExplorePatHls repat<".repat.">")
3486 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003487endfun
3488
3489" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003490" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003491" 0: (user: <mb>) bookmark current directory
3492" 1: (user: <gb>) change to the bookmarked directory
3493" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003494" 3: (browsing) records current directory history
3495" 4: (user: <u>) go up (previous) directory, using history
3496" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003497" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003498fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003499" 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 +02003500 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3501" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3502 return
3503 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003504
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003505 let ykeep = @@
3506 let curbufnr = bufnr("%")
3507
Bram Moolenaar9964e462007-05-05 17:54:07 +00003508 if a:chg == 0
3509 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003510" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003511 if exists("s:netrwmarkfilelist_{curbufnr}")
3512 call s:NetrwBookmark(0)
3513 echo "bookmarked marked files"
3514 else
3515 call s:MakeBookmark(a:curdir)
3516 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003517 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003518
3519 elseif a:chg == 1
3520 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003521" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003522 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003523" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003524 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003525 else
3526 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3527 endif
3528
3529 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003530" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003531 let didwork= 0
3532 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003533" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003534 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003535" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003536 let cnt= 1
3537 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003538" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003539 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003540 let didwork = 1
3541 let cnt = cnt + 1
3542 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003543 endif
3544
3545 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003546 " Note: history is saved only when PerformListing is done;
3547 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3548 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003549 let first = 1
3550 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552 while ( first || cnt != g:netrw_dirhistcnt )
3553" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003554 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003555" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003556 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 let didwork= 1
3558 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003559 let histcnt = histcnt + 1
3560 let first = 0
3561 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003562 if cnt < 0
3563 let cnt= cnt + g:netrw_dirhistmax
3564 endif
3565 endwhile
3566 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003567 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003568 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003569 if didwork
3570 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3571 endif
3572
3573 elseif a:chg == 3
3574 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003575" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003576 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 +02003577 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003578 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3579 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003580 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003581" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003582 endif
3583
3584 elseif a:chg == 4
3585 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003586" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003587 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003588 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3589 if g:netrw_dirhistcnt < 0
3590 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003591 endif
3592 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003593 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003594 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003595 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3596" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003597 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003598 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003599" call Decho("setl ma noro",'~'.expand("<slnum>"))
3600 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003601 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003602" call Decho("setl nomod",'~'.expand("<slnum>"))
3603" 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 +00003604 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003605" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3606 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003607 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003608 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003609 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003610 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003611 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003612 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003613 echo "Sorry, no predecessor directory exists yet"
3614 endif
3615
3616 elseif a:chg == 5
3617 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003618" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003619 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003620 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3621 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3622" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003623 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003624" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003625 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003626 sil! NetrwKeepj %d _
3627" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3628" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003629 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630" 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 +02003631 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003632" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3633 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003634 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003635 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3636 if g:netrw_dirhistcnt < 0
3637 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003638 endif
3639 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003640 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003641 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003642 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003643 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003644 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003645
3646 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003647" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003648 if exists("s:netrwmarkfilelist_{curbufnr}")
3649 call s:NetrwBookmark(1)
3650 echo "removed marked files from bookmarks"
3651 else
3652 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003653 let iremove = v:count
3654 let dremove = g:netrw_bookmarklist[iremove - 1]
3655" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003656 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003657" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3658 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3659 echo "removed ".dremove." from g:netrw_bookmarklist"
3660" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003661 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003662" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003663 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003664 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003665 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003666 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003667" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003668endfun
3669
3670" ---------------------------------------------------------------------
3671" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003672" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003673" Sister function: s:NetrwBookHistSave()
3674fun! s:NetrwBookHistRead()
3675" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003676 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003677" 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 +02003678 return
3679 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003680 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003681
3682 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683 if !exists("s:netrw_initbookhist")
3684 let home = s:NetrwHome()
3685 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003686 if filereadable(s:NetrwFile(savefile))
3687" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003688 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003689 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003690
3691 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003692 if g:netrw_dirhistmax > 0
3693 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003694 if filereadable(s:NetrwFile(savefile))
3695" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003696 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003697 endif
3698 let s:netrw_initbookhist= 1
3699 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702
Bram Moolenaar97d62492012-11-15 21:28:22 +01003703 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3705" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003706" call Dret("s:NetrwBookHistRead")
3707endfun
3708
3709" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003710" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003711" Sister function: s:NetrwBookHistRead()
3712" I used to do this via viminfo but that appears to
3713" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003714" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3715" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003716" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003717fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003718" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003719 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003720" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003721 return
3722 endif
3723
Bram Moolenaar5c736222010-01-06 20:54:52 +01003724 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003725" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003726 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003727
3728 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003729 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003730" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003731 if g:netrw_use_noswf
3732 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3733 else
3734 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3735 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003736 setl nocin noai noci magic nospell nohid wig= noaw
3737 setl ma noro write
3738 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003739 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003740
Bram Moolenaar85850f32019-07-19 22:05:51 +02003741 " rename enew'd file: .netrwhist -- no attempt to merge
3742 " record dirhistmax and current dirhistcnt
3743 " save history
3744" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003745 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003746 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003747 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3748 if g:netrw_dirhistmax > 0
3749 let lastline = line("$")
3750 let cnt = g:netrw_dirhistcnt
3751 let first = 1
3752 while ( first || cnt != g:netrw_dirhistcnt )
3753 let lastline= lastline + 1
3754 if exists("g:netrw_dirhist_{cnt}")
3755 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3756" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3757 endif
3758 let first = 0
3759 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3760 if cnt < 0
3761 let cnt= cnt + g:netrw_dirhistmax
3762 endif
3763 endwhile
3764 exe "sil! w! ".savefile
3765" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3766 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003767
Bram Moolenaar85850f32019-07-19 22:05:51 +02003768 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003769 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003770 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003771" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003772 " merge and write .netrwbook
3773 let savefile= s:NetrwHome()."/.netrwbook"
3774
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003775 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003776 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003777 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003778 for bdm in booklist
3779 if index(g:netrw_bookmarklist,bdm) == -1
3780 call add(g:netrw_bookmarklist,bdm)
3781 endif
3782 endfor
3783 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003784 endif
3785
3786 " construct and save .netrwbook
3787 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003788 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003789" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003790 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003791
3792 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793 let bgone= bufnr("%")
3794 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003795 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003796
3797" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003798endfun
3799
3800" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003801" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3802" list of the contents of a local or remote directory. It is assumed that the
3803" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3804" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003805" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806fun! s:NetrwBrowse(islocal,dirname)
3807 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003808" 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 +02003809" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3810" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3811" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003812
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003813 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3814 " This is useful when one edits a local file, then :e ., then :Rex
3815 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3816 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003817" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003818 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003819
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003820 " s:NetrwBrowse : initialize history {{{3
3821 if !exists("s:netrw_initbookhist")
3822 NetrwKeepj call s:NetrwBookHistRead()
3823 endif
3824
3825 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003826 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003827 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003828" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003829 else
3830 let dirname= a:dirname
3831 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003832
Bram Moolenaar85850f32019-07-19 22:05:51 +02003833 " repoint t:netrw_lexbufnr if appropriate
3834 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3835" call Decho("set repointlexbufnr to true!")
3836 let repointlexbufnr= 1
3837 endif
3838
3839 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003840 if exists("s:netrw_skipbrowse")
3841 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003842" 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 +01003843" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844 return
3845 endif
3846 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003847 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003848" call Dret("s:NetrwBrowse : missing shellescape()")
3849 return
3850 endif
3851 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003852 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853" call Dret("s:NetrwBrowse : missing fnameescape()")
3854 return
3855 endif
3856
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003857 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003858 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003859
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003861 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3862 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3863" call Decho("clearing marked files",'~'.expand("<slnum>"))
3864 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3865 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003866 endif
3867
3868 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3871" 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 +02003872 if s:NetrwLcd(dirname)
3873" call Dret("s:NetrwBrowse : lcd failure")
3874 return
3875 endif
3876 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003877" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003878
Bram Moolenaar5c736222010-01-06 20:54:52 +01003879 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003880 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003881" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003882 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003883" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003884 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003885 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003886 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003887" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003888
3889 " remove any filetype indicator from end of dirname, except for the
3890 " "this is a directory" indicator (/).
3891 " There shouldn't be one of those here, anyway.
3892 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003893" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003894 call s:RemotePathAnalysis(dirname)
3895
3896 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3897 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003898 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003899 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003900" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003901 let b:netrw_curdir = dirname
3902 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003903 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003904 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3905 sil call netrw#NetRead(2,url)
3906 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003907" call Decho("url<".url.">",'~'.expand("<slnum>"))
3908" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3909" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003910 if s:path =~ '.bz2'
3911 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3912 elseif s:path =~ '.gz'
3913 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3914 elseif s:path =~ '.gz'
3915 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3916 else
3917 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003919 endif
3920
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003921 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003922 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003923 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003924" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003925 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003926" 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 +00003927
Bram Moolenaar446cb832008-06-24 21:56:24 +00003928" call Dret("s:NetrwBrowse : file<".s:fname.">")
3929 return
3930 endif
3931
Bram Moolenaaradc21822011-04-01 18:03:16 +02003932 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003933 call s:UseBufWinVars()
3934
3935 " set up some variables {{{3
3936 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003937 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003938 let s:last_sort_by = g:netrw_sort_by
3939
3940 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003941 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003942
Bram Moolenaar97d62492012-11-15 21:28:22 +01003943 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003945 let svpos = winsaveview()
3946" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003948
Bram Moolenaar446cb832008-06-24 21:56:24 +00003949 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003950 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3951 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3952" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3953" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3954 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3955 else
3956" " call Decho("2match none",'~'.expand("<slnum>"))
3957 2match none
3958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003959 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003960 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003961 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003962" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003963 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003964" 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 +01003965" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003966 return
3967 endif
3968
3969 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003970" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003971 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003972 if b:netrw_curdir =~ '[/\\]$'
3973 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3974 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003975 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3976 let b:netrw_curdir= b:netrw_curdir."/"
3977 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003978 if b:netrw_curdir == ''
3979 if has("amiga")
3980 " On the Amiga, the empty string connotes the current directory
3981 let b:netrw_curdir= getcwd()
3982 else
3983 " under unix, when the root directory is encountered, the result
3984 " from the preceding substitute is an empty string.
3985 let b:netrw_curdir= '/'
3986 endif
3987 endif
3988 if !a:islocal && b:netrw_curdir !~ '/$'
3989 let b:netrw_curdir= b:netrw_curdir.'/'
3990 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003992
3993 " ------------
3994 " (local only) {{{3
3995 " ------------
3996 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003997" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998
3999 " Set up ShellCmdPost handling. Append current buffer to browselist
4000 call s:LocalFastBrowser()
4001
4002 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
4003 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004004" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
4005" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004007 if s:NetrwLcd(b:netrw_curdir)
4008" call Dret("s:NetrwBrowse : lcd failure")
4009 return
4010 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004011 endif
4012 endif
4013
4014 " --------------------------------
4015 " remote handling: {{{3
4016 " --------------------------------
4017 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004019
Bram Moolenaar97d62492012-11-15 21:28:22 +01004020 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004021" 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 +02004022 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004023 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004024" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004025 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4026 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4027 if dirname !~ '/$'
4028 let dirname= dirname.'/'
4029 endif
4030 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004031" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004032 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004033 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004034" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004035 endif
4036
4037 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4038 if dirname !~ dirpat
4039 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004040 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004041 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004042 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004044 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004045" 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 +00004046" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4047 return
4048 endif
4049 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004050" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004051 endif " (additional remote handling)
4052
Bram Moolenaar85850f32019-07-19 22:05:51 +02004053 " -------------------------------
4054 " Perform Directory Listing: {{{3
4055 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004056 NetrwKeepj call s:NetrwMaps(a:islocal)
4057 NetrwKeepj call s:NetrwCommands(a:islocal)
4058 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004060 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004061 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004062" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4063
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004064 " If there is a rexposn: restore position with rexposn
4065 " Otherwise : set rexposn
4066 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004067" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4068 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4069 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4070 NetrwKeepj exe w:netrw_bannercnt
4071 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004072 else
4073 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4074 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004075 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004076 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004077" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004078 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004079 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004080
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081 " repoint t:netrw_lexbufnr if appropriate
4082 if exists("repointlexbufnr")
4083 let t:netrw_lexbufnr= bufnr("%")
4084" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4085 endif
4086
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004087 " restore position
4088 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004089" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4090 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004091 endif
4092
Bram Moolenaara6878372014-03-22 21:02:50 +01004093 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004094 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4095 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004096" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4097" 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 +02004098" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004099 return
4100endfun
4101
4102" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004103" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4104" may not apply correctly; ie. netrw's idea of the current directory may
4105" differ from vim's. This function insures that netrw's idea of the current
4106" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004107" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004109" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4110" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4111" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4112" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4113" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114
4115 " clean up any leading treedepthstring
4116 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4117 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 else
4120 let fname= a:fname
4121 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004122
4123 if g:netrw_keepdir
4124 " vim's idea of the current directory possibly may differ from netrw's
4125 if !exists("b:netrw_curdir")
4126 let b:netrw_curdir= getcwd()
4127 endif
4128
4129 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004130 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004132 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004133" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004134 else
4135 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004136 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004137" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004138 endif
4139
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004140 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004141 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004142 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004143" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004144 else
4145 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004146 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004147" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004148 endif
4149 else
4150 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004152" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4153" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4154" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004155 endif
4156
Bram Moolenaar85850f32019-07-19 22:05:51 +02004157" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158 return ret
4159endfun
4160
4161" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004162" s:NetrwFileInfo: supports qf (query for file information) {{{2
4163fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004164" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004165 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004166 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004167 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004168 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004169 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004170 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004171 let lsopt= "-lsadh --si"
4172 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004173" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004174 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004175
4176 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004177 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004178" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004179
Bram Moolenaara6878372014-03-22 21:02:50 +01004180 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004181 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004182" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004183
4184 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004185 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004186" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004187
Bram Moolenaar446cb832008-06-24 21:56:24 +00004188 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004189" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004190 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004191" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004192 endif
4193 else
4194 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004195" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4196 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004197 let fname= substitute(a:fname,".$","","")
4198 else
4199 let fname= a:fname
4200 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004201 let t = getftime(s:NetrwFile(fname))
4202 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004203 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004204 let sz= s:NetrwHumanReadable(sz)
4205 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004206 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4207" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004208 endif
4209 else
4210 echo "sorry, \"qf\" not supported yet for remote files"
4211 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004212 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004213" call Dret("s:NetrwFileInfo")
4214endfun
4215
4216" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004217" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4218fun! s:NetrwFullPath(filename)
4219" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4220 let filename= a:filename
4221 if filename !~ '^/'
4222 let filename= resolve(getcwd().'/'.filename)
4223 endif
4224 if filename != "/" && filename =~ '/$'
4225 let filename= substitute(filename,'/$','','')
4226 endif
4227" " call Dret("s:NetrwFullPath <".filename.">")
4228 return filename
4229endfun
4230
4231" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004232" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004233" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004234" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004235" 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 +00004236fun! s:NetrwGetBuffer(islocal,dirname)
4237" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004238" 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 +02004239" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4240" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004241 let dirname= a:dirname
4242
4243 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004244" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004245 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004246" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004247 let s:netrwbuf= {}
4248 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004249" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4250" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4251
4252 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4253 let bufnum = -1
4254
4255 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4256 if has_key(s:netrwbuf,"NetrwTreeListing")
4257 let bufnum= s:netrwbuf["NetrwTreeListing"]
4258 else
4259 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4260 endif
4261" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4262 if !bufexists(bufnum)
4263 call remove(s:netrwbuf,"NetrwTreeListing"])
4264 let bufnum= -1
4265 endif
4266 elseif bufnr("NetrwTreeListing") != -1
4267 let bufnum= bufnr("NetrwTreeListing")
4268" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4269 else
4270" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4271 let bufnum= -1
4272 endif
4273
4274 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004275 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004276" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004277 if !bufexists(bufnum)
4278 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4279 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004280 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004281
Bram Moolenaar446cb832008-06-24 21:56:24 +00004282 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004283" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004284 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004285 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004286" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4287
Bram Moolenaar71badf92023-04-22 22:40:14 +01004288 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004289 " IF the buffer already has the desired name
4290 " AND it is empty
4291 let curbuf = bufname("%")
4292 if curbuf == '.'
4293 let curbuf = getcwd()
4294 endif
4295" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004296" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004297" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4298" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4299" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4300" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4301 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004302" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4303 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004304 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004305" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004306 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004307 " 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 +00004308
4309 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004310 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004311" 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 +00004312 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004313" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314 " name the buffer
4315 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4316 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004317" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004318 let w:netrw_treebufnr = bufnr("%")
4319 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004320 if g:netrw_use_noswf
4321 setl nobl bt=nofile noswf
4322 else
4323 setl nobl bt=nofile
4324 endif
4325 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4326 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4327 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4328 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004329" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004330 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004331 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004332 " enter the new buffer into the s:netrwbuf dictionary
4333 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4334" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4335" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004338
4339 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004340" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004341 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004343 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004344
4345 if &ft == "netrw"
4346" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4347 exe "sil! NetrwKeepj noswapfile b ".bufnum
4348" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004349 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004350" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4351 call s:NetrwEditBuf(bufnum)
4352" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004353 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004354" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004355 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004356 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004357 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004358
4359 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004361
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362 if line("$") <= 1 && getline(1) == ""
4363 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004364 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004365" 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>"))
4366" 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 +01004367" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4368 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004369
Bram Moolenaar97d62492012-11-15 21:28:22 +01004370 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004371" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004372 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004373 sil NetrwKeepj %d _
4374" 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>"))
4375" 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 +01004376" 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 +00004377 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004378
Bram Moolenaar446cb832008-06-24 21:56:24 +00004379 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4381" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004382 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004383 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004384 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4386" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004387" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004389
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004391" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4392" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4393" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394 return 1
4395 endif
4396 endif
4397
4398 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4399 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4400 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4401 " med 1 D H
4402 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004403" 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 +00004404 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004405 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004406 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004407
4408 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004409" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4410" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4411 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004412
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004413" 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>"))
4414" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4415" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004416 return 0
4417endfun
4418
4419" ---------------------------------------------------------------------
4420" s:NetrwGetcwd: get the current directory. {{{2
4421" Change backslashes to forward slashes, if any.
4422" If doesc is true, escape certain troublesome characters
4423fun! s:NetrwGetcwd(doesc)
4424" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4425 let curdir= substitute(getcwd(),'\\','/','ge')
4426 if curdir !~ '[\/]$'
4427 let curdir= curdir.'/'
4428 endif
4429 if a:doesc
4430 let curdir= fnameescape(curdir)
4431 endif
4432" call Dret("NetrwGetcwd <".curdir.">")
4433 return curdir
4434endfun
4435
4436" ---------------------------------------------------------------------
4437" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4438fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004439" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4440" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4441 let keepsol= &l:sol
4442 setl nosol
4443
Bram Moolenaar446cb832008-06-24 21:56:24 +00004444 call s:UseBufWinVars()
4445
4446 " insure that w:netrw_liststyle is set up
4447 if !exists("w:netrw_liststyle")
4448 if exists("g:netrw_liststyle")
4449 let w:netrw_liststyle= g:netrw_liststyle
4450 else
4451 let w:netrw_liststyle= s:THINLIST
4452 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004453" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004454 endif
4455
4456 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4457 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004458" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004459 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004460 let dirname= "./"
4461 let curline= getline('.')
4462
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004463 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004464 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465 let s:netrw_skipbrowse= 1
4466 echo 'Pressing "s" also works'
4467
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004468 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469 let s:netrw_skipbrowse= 1
4470 echo 'Press "S" to edit sorting sequence'
4471
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004472 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004473 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004474 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004476 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004477 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478 let s:netrw_skipbrowse= 1
4479 echo 'Pressing "a" also works'
4480
4481 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004482 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 endif
4484
4485 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004486" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004487 NetrwKeepj norm! 0
4488 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489
4490 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004491" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004492 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4494
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004495 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004496" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004497 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499
4500 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004501" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004502 let dirname= getline('.')
4503
4504 if !exists("b:netrw_cpf")
4505 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004506 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 +01004507 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004508" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004509 endif
4510
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004511" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004512 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004513" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4514" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004515 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004516 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004517 else
4518 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004519 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004520 endif
4521 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004522 let eofname= filestart + b:netrw_cpf + 1
4523 if eofname <= col("$")
4524 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004525 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004526 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004527 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004528 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529 let dirname = @a
4530 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004531" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004532 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004533" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534 endif
4535
4536 " symlinks are indicated by a trailing "@". Remove it before further processing.
4537 let dirname= substitute(dirname,"@$","","")
4538
4539 " executables are indicated by a trailing "*". Remove it before further processing.
4540 let dirname= substitute(dirname,"\*$","","")
4541
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004542 let &l:sol= keepsol
4543
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544" call Dret("s:NetrwGetWord <".dirname.">")
4545 return dirname
4546endfun
4547
4548" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004549" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4550" g:netrw_bufsettings will be used after the listing is produced.
4551" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552fun! s:NetrwListSettings(islocal)
4553" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004554" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004555 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004556" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4557 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4558 setl bt=nofile nobl ma nonu nowrap noro nornu
4559 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004561 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004562 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004563" call Dredir("ls!","s:NetrwListSettings")
4564" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004565 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004566 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004568 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004570 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004571 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004572" 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 +00004573" call Dret("s:NetrwListSettings")
4574endfun
4575
4576" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004577" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578" islocal=0: remote browsing
4579" =1: local browsing
4580fun! s:NetrwListStyle(islocal)
4581" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004582
Bram Moolenaar97d62492012-11-15 21:28:22 +01004583 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584 let fname = s:NetrwGetWord()
4585 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004586 let svpos = winsaveview()
4587" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004588 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004589" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4590" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4591" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592
Bram Moolenaar85850f32019-07-19 22:05:51 +02004593 " repoint t:netrw_lexbufnr if appropriate
4594 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4595" call Decho("set repointlexbufnr to true!")
4596 let repointlexbufnr= 1
4597 endif
4598
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599 if w:netrw_liststyle == s:THINLIST
4600 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004601" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4603
4604 elseif w:netrw_liststyle == s:LONGLIST
4605 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004606" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004607 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4608
4609 elseif w:netrw_liststyle == s:WIDELIST
4610 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004611" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004612 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4613
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004614 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004616 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4617
4618 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004619 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004620 let g:netrw_liststyle = s:THINLIST
4621 let w:netrw_liststyle = g:netrw_liststyle
4622 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4623 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004624 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004625" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004626
4627 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004628" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4629 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004630 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004631" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004632 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004633" 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 +00004634
4635 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004636" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004637 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004638 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004639
Bram Moolenaar85850f32019-07-19 22:05:51 +02004640 " repoint t:netrw_lexbufnr if appropriate
4641 if exists("repointlexbufnr")
4642 let t:netrw_lexbufnr= bufnr("%")
4643" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4644 endif
4645
Bram Moolenaar13600302014-05-22 18:26:40 +02004646 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004647" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4648 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004649 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004650
4651" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4652endfun
4653
4654" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004655" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4656fun! s:NetrwBannerCtrl(islocal)
4657" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4658
Bram Moolenaar97d62492012-11-15 21:28:22 +01004659 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004660 " toggle the banner (enable/suppress)
4661 let g:netrw_banner= !g:netrw_banner
4662
4663 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004664 let svpos= winsaveview()
4665" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004666 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4667
4668 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004669 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4670 let fname= s:NetrwGetWord()
4671 sil NetrwKeepj $
4672 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4673" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4674 if result <= 0 && exists("w:netrw_bannercnt")
4675 exe "NetrwKeepj ".w:netrw_bannercnt
4676 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004677 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004678 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004679" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4680endfun
4681
4682" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004683" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4684"
4685" No bang: enters files/directories into Netrw's bookmark system
4686" No argument and in netrw buffer:
4687" if there are marked files: bookmark marked files
4688" otherwise : bookmark file/directory under cursor
4689" No argument and not in netrw buffer: bookmarks current open file
4690" Has arguments: globs them individually and bookmarks them
4691"
4692" With bang: deletes files/directories from Netrw's bookmark system
4693fun! s:NetrwBookmark(del,...)
4694" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4695 if a:0 == 0
4696 if &ft == "netrw"
4697 let curbufnr = bufnr("%")
4698
4699 if exists("s:netrwmarkfilelist_{curbufnr}")
4700 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004701" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004702 let svpos = winsaveview()
4703" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004704 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004705 for fname in s:netrwmarkfilelist_{curbufnr}
4706 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4707 endfor
4708 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4709 call s:NetrwUnmarkList(curbufnr,curdir)
4710 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004711" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4712 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004713 else
4714 let fname= s:NetrwGetWord()
4715 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4716 endif
4717
4718 else
4719 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004720" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004721 let fname= expand("%")
4722 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4723 endif
4724
4725 else
4726 " bookmark specified files
4727 " attempts to infer if working remote or local
4728 " by deciding if the current file begins with an url
4729 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004730 let islocal= expand("%") !~ '^\a\{3,}://'
4731" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004732 let i = 1
4733 while i <= a:0
4734 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004735 if v:version > 704 || (v:version == 704 && has("patch656"))
4736 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004737 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004738 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004739 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004740 else
4741 let mbfiles= [a:{i}]
4742 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004743" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004744 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004745" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004746 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4747 endfor
4748 let i= i + 1
4749 endwhile
4750 endif
4751
4752 " update the menu
4753 call s:NetrwBookmarkMenu()
4754
4755" call Dret("s:NetrwBookmark")
4756endfun
4757
4758" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004759" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4760" .2.[cnt] for bookmarks, and
4761" .3.[cnt] for history
4762" (see s:NetrwMenu())
4763fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004764 if !exists("s:netrw_menucnt")
4765 return
4766 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004767" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004768
4769 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004770 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004771 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004772" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004773 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4774 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004775 endif
4776 if !exists("s:netrw_initbookhist")
4777 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004778 endif
4779
4780 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004781 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004782 let cnt= 1
4783 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004784" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004785 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004786
4787 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004788 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004789
4790 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004791 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 +01004792 let cnt= cnt + 1
4793 endfor
4794
4795 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004796
4797 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004798 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004799 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004800 let first = 1
4801 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004802 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004803 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004804 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004805 if exists("g:netrw_dirhist_{cnt}")
4806 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004807" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004808 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4809 endif
4810 let first = 0
4811 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4812 if cnt < 0
4813 let cnt= cnt + g:netrw_dirhistmax
4814 endif
4815 endwhile
4816 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004817
Bram Moolenaar9964e462007-05-05 17:54:07 +00004818 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004819" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004820endfun
4821
4822" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004823" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4824" directory and a new directory name. Also, if the
4825" "new directory name" is actually a file,
4826" NetrwBrowseChgDir() edits the file.
4827fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004828" 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 +01004829" 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 +00004830
Bram Moolenaar97d62492012-11-15 21:28:22 +01004831 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004832 if !exists("b:netrw_curdir")
4833 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4834 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004835 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004836" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4837" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004838" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004839" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004840 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004841 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004842" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004843
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004844 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004846 call s:SavePosn(s:netrw_posn)
4847 NetrwKeepj call s:NetrwOptionsSave("s:")
4848 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004849 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004850 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004851 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004852 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004853 endif
4854 let newdir = a:newdir
4855 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004856 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004857" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004858" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004859" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004860
4861 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004862" 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 +01004863 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004864" 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 +01004865 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004866 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004867" 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 +01004868 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004869" 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 +02004870 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004871 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004872 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004873 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004874" 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 +01004875 endif
4876 endif
4877" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004878" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004879 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004880
Bram Moolenaar446cb832008-06-24 21:56:24 +00004881 " set up o/s-dependent directory recognition pattern
4882 if has("amiga")
4883 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004884 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004885 let dirpat= '[\/]$'
4886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004887" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004888
4889 if dirname !~ dirpat
4890 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004891 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004893" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 endif
4895
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004896" 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 +01004897 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004898 " ------------------------------
4899 " NetrwBrowseChgDir: edit a file {{{3
4900 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004901" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004902
Bram Moolenaar97d62492012-11-15 21:28:22 +01004903 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004904 let s:rexposn_{bufnr("%")}= winsaveview()
4905" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004906" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4907" 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 +01004908
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004910" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4911" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004912" let newdir = s:NetrwTreePath(s:netrw_treetop)
4913" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004914 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004915 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4916" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4917 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004918 if dirname =~ '/$'
4919 let dirname= dirname.newdir
4920 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004921 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004922 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004923" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4924" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004925 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004926" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004927 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004928 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004929 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004930 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004931" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004932 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004933 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004934" 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 +02004935 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004936 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004937 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004938" " 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 +01004939 if type(g:netrw_browse_split) == 3
4940 " open file in server
4941 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004942" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004943 call s:NetrwServerEdit(a:islocal,dirname)
4944" call Dret("s:NetrwBrowseChgDir")
4945 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004946
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004947 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004948 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004949" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004950 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4951 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004952 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004953 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004954 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004955 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004956
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004958 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004959" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004960 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4961 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004962 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004963 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004964 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004965 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004966
Bram Moolenaar446cb832008-06-24 21:56:24 +00004967 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004968 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004969" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004970 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004971 if !exists("b:netrw_curdir")
4972 let b:netrw_curdir= getcwd()
4973 endif
4974 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004975
Bram Moolenaar446cb832008-06-24 21:56:24 +00004976 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004977 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004978" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004979 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004980 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004981" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004982 return
4983 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004984 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004985
Bram Moolenaar9964e462007-05-05 17:54:07 +00004986 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004987 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004988" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004989 call s:NetrwMenu(0)
4990 " optional change to window
4991 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004992" 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 +02004993 if winnr("$")+1 == g:netrw_chgwin
4994 " if g:netrw_chgwin is set to one more than the last window, then
4995 " vertically split the last window to make that window available.
4996 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004997 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004998 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004999 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02005000 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005001 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00005002 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005003 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00005004 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005005
Bram Moolenaar9964e462007-05-05 17:54:07 +00005006 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005007
Bram Moolenaar446cb832008-06-24 21:56:24 +00005008 " the point where netrw actually edits the (local) file
5009 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005010 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005011 if !&mod
5012 " if e the new file would fail due to &mod, then don't change any of the flags
5013 let dolockout= 1
5014 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005015 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005016" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005017 " some like c-^ to return to the last edited file
5018 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005019 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5020 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005021 call s:NetrwEditFile("e","",dirname)
5022" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005023 " COMBAK -- cuc cul related
5024 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005025 if &hidden || &bufhidden == "hide"
5026 " file came from vim's hidden storage. Don't "restore" options with it.
5027 let dorestore= 0
5028 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005029 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005030" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005031 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005032
5033 " handle g:Netrw_funcref -- call external-to-netrw functions
5034 " This code will handle g:Netrw_funcref as an individual function reference
5035 " or as a list of function references. It will ignore anything that's not
5036 " a function reference. See :help Funcref for information about function references.
5037 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005039 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005040" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005041 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005042 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005043" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005044 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005045 if type(Fncref) == 2
5046 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005047 endif
5048 endfor
5049 endif
5050 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005051 endif
5052
5053 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005054 " ----------------------------------------------------
5055 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5056 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005057" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005058 let dirname = newdir
5059 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005060 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005062
5063 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005064 " ---------------------------------------------
5065 " NetrwBrowseChgDir: refresh the directory list {{{3
5066 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005067" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005068 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005069 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005070
5071 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005072 " --------------------------------------
5073 " NetrwBrowseChgDir: go up one directory {{{3
5074 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005075" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005076
5077 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5078 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005079" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5080" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005081 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005082 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005083 endif
5084
5085 if has("amiga")
5086 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005087" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005088 if a:islocal
5089 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5090 let dirname= substitute(dirname,'/$','','')
5091 else
5092 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5093 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005094" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005095
Bram Moolenaar8d043172014-01-23 14:24:41 +01005096 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5097 " windows
5098 if a:islocal
5099 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5100 if dirname == ""
5101 let dirname= '/'
5102 endif
5103 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005104 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005105 endif
5106 if dirname =~ '^\a:$'
5107 let dirname= dirname.'/'
5108 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005109" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005110
Bram Moolenaar446cb832008-06-24 21:56:24 +00005111 else
5112 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005113" 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 +00005114 if a:islocal
5115 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5116 if dirname == ""
5117 let dirname= '/'
5118 endif
5119 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005120 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005121 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005122" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005124 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005125 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126
5127 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005128 " --------------------------------------
5129 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5130 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005131" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005132 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5133" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005134 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005136" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5137 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005139 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005140" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005141 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005142 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005143" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144
5145 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005146" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005148" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 let haskey= 1
5150 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005151" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 endif
5153
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005154 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005155" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005156 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005157 if has_key(w:netrw_treedict,treedir."/")
5158 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005159" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 let haskey = 1
5161 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005162" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 endif
5164 endif
5165
5166 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005167" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168 if !haskey && treedir =~ '/$'
5169 let treedir= substitute(treedir,'/$','','')
5170 if has_key(w:netrw_treedict,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
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005178" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005179 if haskey
5180 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005181" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005182 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005183" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5184" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005185 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005186 else
5187 " go down one directory
5188 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005189" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5190" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005191 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005192 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005194 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005195
5196 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005197 " ----------------------------------------
5198 " NetrwBrowseChgDir: Go down one directory {{{3
5199 " ----------------------------------------
5200 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005202 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005203 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005204 endif
5205
Bram Moolenaar97d62492012-11-15 21:28:22 +01005206 " --------------------------------------
5207 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5208 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005209 if dorestore
5210 " dorestore is zero'd when a local file was hidden or bufhidden;
5211 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005212" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005213 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005214" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005215" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005216 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005217 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005218" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005219 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005220" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5221" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005222 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005223" 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 +02005224 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005225" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5226" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005227 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005228" 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 +02005229 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005230 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005231 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005232 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005233
Bram Moolenaar446cb832008-06-24 21:56:24 +00005234" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5235 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005236endfun
5237
5238" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005239" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5240" for thin, long, and wide: cursor placed just after banner
5241" for tree, keeps cursor on current filename
5242fun! s:NetrwBrowseUpDir(islocal)
5243" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005244 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5245 " this test needed because occasionally this function seems to be incorrectly called
5246 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005247 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005248 " directories.
5249" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5250 return
5251 endif
5252
Bram Moolenaara6878372014-03-22 21:02:50 +01005253 norm! 0
5254 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005255" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005256 let curline= getline(".")
5257 let swwline= winline() - 1
5258 if exists("w:netrw_treetop")
5259 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005260 elseif exists("b:netrw_curdir")
5261 let w:netrw_treetop= b:netrw_curdir
5262 else
5263 let w:netrw_treetop= getcwd()
5264 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005265 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005266 let curfile = getline(".")
5267 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005268 if a:islocal
5269 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5270 else
5271 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5272 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005273" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5274" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5275 if w:netrw_treetop == '/'
5276 keepj call search('^\M'.curfile,"w")
5277 elseif curfile == '../'
5278 keepj call search('^\M'.curfile,"wb")
5279 else
5280" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5281 while 1
5282 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5283 let treepath= s:NetrwTreePath(w:netrw_treetop)
5284" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5285 if treepath == curpath
5286 break
5287 endif
5288 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005289 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005290
Bram Moolenaara6878372014-03-22 21:02:50 +01005291 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005292" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005293 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005294 if exists("b:netrw_curdir")
5295 let curdir= b:netrw_curdir
5296 else
5297 let curdir= expand(getcwd())
5298 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005299 if a:islocal
5300 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5301 else
5302 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5303 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005304 call s:RestorePosn(s:netrw_posn)
5305 let curdir= substitute(curdir,'^.*[\/]','','')
5306 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005307 endif
5308" call Dret("s:NetrwBrowseUpDir")
5309endfun
5310
5311" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005312" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005313" given filename; typically this means given their extension.
5314" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005315fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005316 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005317" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005318
Bram Moolenaar91359012019-11-30 17:57:03 +01005319 if a:remote == 0 && isdirectory(a:fname)
5320 " if its really just a local directory, then do a "gf" instead
5321" 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 +01005322" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5323 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005324" call Dret("netrw#BrowseX")
5325 return
5326 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5327 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5328" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5329" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5330" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5331" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5332 norm! gf
5333" call Dret("netrw#BrowseX")
5334 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005335 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005336" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005337
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005338 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5339 let remote = a:remote
5340 else
5341 let remote = 0
5342 endif
5343
Bram Moolenaar97d62492012-11-15 21:28:22 +01005344 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005345 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005346" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005347
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005348 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5349 let awkeep = &aw
5350 set noaw
5351
Bram Moolenaar5c736222010-01-06 20:54:52 +01005352 " special core dump handler
5353 if a:fname =~ '/core\(\.\d\+\)\=$'
5354 if exists("g:Netrw_corehandler")
5355 if type(g:Netrw_corehandler) == 2
5356 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005357" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005358 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005359 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005360 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005361" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005362 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005363 if type(Fncref) == 2
5364 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005365 endif
5366 endfor
5367 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005368" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005369 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005370 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005371 let &aw= awkeep
5372" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005373 return
5374 endif
5375 endif
5376
Bram Moolenaar446cb832008-06-24 21:56:24 +00005377 " set up the filename
5378 " (lower case the extension, make a local copy of a remote file)
5379 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5380 if has("win32") || has("win95") || has("win64") || has("win16")
5381 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005382 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005383 if exten =~ "[\\/]"
5384 let exten= ""
5385 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005386" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005387
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005388 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005389 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005390" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005391 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005392 call netrw#NetRead(3,a:fname)
5393 " attempt to rename tempfile
5394 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005395 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005396" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5397" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005398 if s:netrw_tmpfile != newname && newname != ""
5399 if rename(s:netrw_tmpfile,newname) == 0
5400 " renaming succeeded
5401" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5402 let fname= newname
5403 else
5404 " renaming failed
5405" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5406 let fname= s:netrw_tmpfile
5407 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005408 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005409 let fname= s:netrw_tmpfile
5410 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005411 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005412" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005413 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005414 " special ~ handler for local
5415 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005416" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5417 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005418 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005420" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5421" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005423 " set up redirection (avoids browser messages)
5424 " by default, g:netrw_suppress_gx_mesg is true
5425 if g:netrw_suppress_gx_mesg
5426 if &srr =~ "%s"
5427 if (has("win32") || has("win95") || has("win64") || has("win16"))
5428 let redir= substitute(&srr,"%s","nul","")
5429 else
5430 let redir= substitute(&srr,"%s","/dev/null","")
5431 endif
5432 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5433 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005434 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005435 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005437 else
5438 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005439 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005440" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005442 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005444" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 if g:netrw_browsex_viewer =~ '\s'
5446 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5447 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5448 let oviewer = ''
5449 let cnt = 1
5450 while !executable(viewer) && viewer != oviewer
5451 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5452 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5453 let cnt = cnt + 1
5454 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005455" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 endwhile
5457 else
5458 let viewer = g:netrw_browsex_viewer
5459 let viewopt = ""
5460 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005461" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005462 endif
5463
5464 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005465" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005466 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005467" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005468 let ret= netrwFileHandlers#Invoke(exten,fname)
5469
5470 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005471" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005472 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005473 let ret= v:shell_error
5474
5475 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005476" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005477 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005478 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005479 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005480 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005481 else
5482 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5483 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005484 let ret= v:shell_error
5485
Bram Moolenaar97d62492012-11-15 21:28:22 +01005486 elseif has("win32unix")
5487 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005488" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005489 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005490" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005491 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005492 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005493" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005494 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005495 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005496" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005497 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005498 else
5499 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5500 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005501 let ret= v:shell_error
5502
Bram Moolenaar85850f32019-07-19 22:05:51 +02005503 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005504" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5505 if a:fname =~ '^https\=://'
5506 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5507 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005508" call Decho("fname<".fname.">")
5509" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005510 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5511
5512 else
5513 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5514 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005515 let ret= v:shell_error
5516
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005517 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5518" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5519 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5520 let ret= v:shell_error
5521
5522 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5523" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5524 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5525 let ret= v:shell_error
5526
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005527 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005528" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005529 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005530 let ret= v:shell_error
5531
5532 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005533" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005534 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005535 let ret= v:shell_error
5536
5537 else
5538 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005539" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005540 let ret= netrwFileHandlers#Invoke(exten,fname)
5541 endif
5542
5543 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5544 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005545" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 let ret= netrwFileHandlers#Invoke(exten,fname)
5547 endif
5548
Bram Moolenaarc236c162008-07-13 17:41:49 +00005549 " restoring redraw! after external file handlers
5550 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551
5552 " cleanup: remove temporary file,
5553 " delete current buffer if success with handler,
5554 " return to prior buffer (directory listing)
5555 " Feb 12, 2008: had to de-activiate removal of
5556 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005557" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005558"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005559" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005560" endif
5561
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005562 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005563 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005564 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005565 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005566 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005567 if use_ctrlo
5568 exe "sil! NetrwKeepj norm! \<c-o>"
5569 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005570 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005571" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005572 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005573 let @@ = ykeep
5574 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005575
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005576" call Dret("netrw#BrowseX")
5577endfun
5578
5579" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005580" netrw#GX: gets word under cursor for gx support {{{2
5581" See also: netrw#BrowseXVis
5582" netrw#BrowseX
5583fun! netrw#GX()
5584" call Dfunc("netrw#GX()")
5585 if &ft == "netrw"
5586 let fname= s:NetrwGetWord()
5587 else
5588 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5589 endif
5590" call Dret("netrw#GX <".fname.">")
5591 return fname
5592endfun
5593
5594" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005595" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5596fun! netrw#BrowseXVis()
5597" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005598 let akeep = @a
5599 norm! gv"ay
5600 let gxfile= @a
5601 let @a = akeep
5602 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005603" call Dret("netrw#BrowseXVis")
5604endfun
5605
5606" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005607" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5608" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5609" to become an unlisted buffer, so in that case don't bwipe it.
5610fun! s:NetrwBufRename(newname)
5611" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5612" call Dredir("ls!","s:NetrwBufRename (before rename)")
5613 let oldbufname= bufname(bufnr("%"))
5614" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5615
5616 if oldbufname != a:newname
5617" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5618 let b:junk= 1
5619" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5620 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005621" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005622 let oldbufnr= bufnr(oldbufname)
5623" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5624" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5625 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5626" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5627 exe "bwipe! ".oldbufnr
5628" else " Decho
5629" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005630" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5631" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5632" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005633 endif
5634" call Dredir("ls!","s:NetrwBufRename (after rename)")
5635" else " Decho
5636" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5637 endif
5638
5639" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5640endfun
5641
5642" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005643" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005644fun! netrw#CheckIfRemote(...)
5645" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5646 if a:0 > 0
5647 let curfile= a:1
5648 else
5649 let curfile= expand("%")
5650 endif
5651" call Decho("curfile<".curfile.">")
5652 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005653" call Dret("netrw#CheckIfRemote 1")
5654 return 1
5655 else
5656" call Dret("netrw#CheckIfRemote 0")
5657 return 0
5658 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005659endfun
5660
5661" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005662" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5663fun! s:NetrwChgPerm(islocal,curdir)
5664" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005665 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005666 call inputsave()
5667 let newperm= input("Enter new permission: ")
5668 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005669 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5670 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5671" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005672 call system(chgperm)
5673 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005675 endif
5676 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005677 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005678 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005679 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005680" call Dret("s:NetrwChgPerm")
5681endfun
5682
5683" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005684" s:CheckIfKde: checks if kdeinit is running {{{2
5685" Returns 0: kdeinit not running
5686" 1: kdeinit is running
5687fun! s:CheckIfKde()
5688" call Dfunc("s:CheckIfKde()")
5689 " seems kde systems often have gnome-open due to dependencies, even though
5690 " gnome-open's subsidiary display tools are largely absent. Kde systems
5691 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5692 if !exists("s:haskdeinit")
5693 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005694 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005695 if v:shell_error
5696 let s:haskdeinit = 0
5697 endif
5698 else
5699 let s:haskdeinit= 0
5700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005701" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005702 endif
5703
5704" call Dret("s:CheckIfKde ".s:haskdeinit)
5705 return s:haskdeinit
5706endfun
5707
5708" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005709" s:NetrwClearExplore: clear explore variables (if any) {{{2
5710fun! s:NetrwClearExplore()
5711" call Dfunc("s:NetrwClearExplore()")
5712 2match none
5713 if exists("s:explore_match") |unlet s:explore_match |endif
5714 if exists("s:explore_indx") |unlet s:explore_indx |endif
5715 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5716 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5717 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5718 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5719 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5720 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5721 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5722" redraw!
5723 echo " "
5724 echo " "
5725" call Dret("s:NetrwClearExplore")
5726endfun
5727
5728" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005729" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5730fun! s:NetrwEditBuf(bufnum)
5731" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5732 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5733" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5734 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5735 else
5736" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005737 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005738 endif
5739" call Dret("s:NetrwEditBuf")
5740endfun
5741
5742" ---------------------------------------------------------------------
5743" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5744" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5745fun! s:NetrwEditFile(cmd,opt,fname)
5746" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5747 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5748" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5749 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5750 else
5751" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5752 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5753 endif
5754" call Dret("s:NetrwEditFile")
5755endfun
5756
5757" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005758" s:NetrwExploreListUniq: {{{2
5759fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005760" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005761
5762 " this assumes that the list is already sorted
5763 let newexplist= []
5764 for member in a:explist
5765 if !exists("uniqmember") || member != uniqmember
5766 let uniqmember = member
5767 let newexplist = newexplist + [ member ]
5768 endif
5769 endfor
5770
Bram Moolenaar15146672011-10-20 22:22:38 +02005771" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005772 return newexplist
5773endfun
5774
5775" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005776" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5777fun! s:NetrwForceChgDir(islocal,newdir)
5778" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005779 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005780 if a:newdir !~ '/$'
5781 " ok, looks like force is needed to get directory-style treatment
5782 if a:newdir =~ '@$'
5783 let newdir= substitute(a:newdir,'@$','/','')
5784 elseif a:newdir =~ '[*=|\\]$'
5785 let newdir= substitute(a:newdir,'.$','/','')
5786 else
5787 let newdir= a:newdir.'/'
5788 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005789" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005790 else
5791 " should already be getting treatment as a directory
5792 let newdir= a:newdir
5793 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005794 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005795 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005796 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005797" call Dret("s:NetrwForceChgDir")
5798endfun
5799
5800" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005801" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005802" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5803" expr : this is the expression to follow the directory. Will use s:ComposePath()
5804" pare =1: remove the current directory from the resulting glob() filelist
5805" =0: leave the current directory in the resulting glob() filelist
5806fun! s:NetrwGlob(direntry,expr,pare)
5807" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005808 if netrw#CheckIfRemote()
5809 keepalt 1sp
5810 keepalt enew
5811 let keep_liststyle = w:netrw_liststyle
5812 let w:netrw_liststyle = s:THINLIST
5813 if s:NetrwRemoteListing() == 0
5814 keepj keepalt %s@/@@
5815 let filelist= getline(1,$)
5816 q!
5817 else
5818 " remote listing error -- leave treedict unchanged
5819 let filelist= w:netrw_treedict[a:direntry]
5820 endif
5821 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005822 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5823 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5824 if a:pare
5825 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5826 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005827 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005828 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5829 if a:pare
5830 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5831 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005832 endif
5833" call Dret("s:NetrwGlob ".string(filelist))
5834 return filelist
5835endfun
5836
5837" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005838" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5839fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005840" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005841 if a:newfile =~ '[/@*=|\\]$'
5842 let newfile= substitute(a:newfile,'.$','','')
5843 else
5844 let newfile= a:newfile
5845 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005846 if a:islocal
5847 call s:NetrwBrowseChgDir(a:islocal,newfile)
5848 else
5849 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5850 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005851" call Dret("s:NetrwForceFile")
5852endfun
5853
5854" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005855" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5856" and switches the hiding mode. The actual hiding is done by
5857" s:NetrwListHide().
5858" g:netrw_hide= 0: show all
5859" 1: show not-hidden files
5860" 2: show hidden files only
5861fun! s:NetrwHide(islocal)
5862" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005863 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005864 let svpos= winsaveview()
5865" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005866
5867 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005868" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5869" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005870
5871 " hide the files in the markfile list
5872 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005873" 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 +00005874 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5875 " remove fname from hiding list
5876 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5877 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5878 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005879" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005880 else
5881 " append fname to hiding list
5882 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5883 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5884 else
5885 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005887" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005888 endif
5889 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005890 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005891 let g:netrw_hide= 1
5892
5893 else
5894
5895 " switch between show-all/show-not-hidden/show-hidden
5896 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005897 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005899 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005900 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005901" call Dret("NetrwHide")
5902 return
5903 endif
5904 endif
5905
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005906 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005907" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5908 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005909 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005910" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005911endfun
5912
5913" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005914" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5915fun! s:NetrwHideEdit(islocal)
5916" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5917
5918 let ykeep= @@
5919 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005920 let svpos= winsaveview()
5921" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005922
5923 " get new hiding list from user
5924 call inputsave()
5925 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5926 call inputrestore()
5927 let g:netrw_list_hide= newhide
5928" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5929
5930 " refresh the listing
5931 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5932
5933 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005934" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5935 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005936 let @@= ykeep
5937
5938" call Dret("NetrwHideEdit")
5939endfun
5940
5941" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005942" s:NetrwHidden: invoked by "gh" {{{2
5943fun! s:NetrwHidden(islocal)
5944" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005945 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005946 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005947 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005948" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005949
5950 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005951 " remove .file pattern from hiding list
5952" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005954 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005955" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005956 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5957 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005958" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005959 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5960 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005961 if g:netrw_list_hide =~ '^,'
5962 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5963 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005964
5965 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005966 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005967" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5968 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005969 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005970" call Dret("s:NetrwHidden")
5971endfun
5972
5973" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005974" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5975fun! s:NetrwHome()
5976 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005977 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005978 else
5979 " go to vim plugin home
5980 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005981 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005982 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005983 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005984 let home= basehome."/.vim"
5985 break
5986 endif
5987 endfor
5988 if home == ""
5989 " just pick the first directory
5990 let home= substitute(&rtp,',.*$','','')
5991 endif
5992 if (has("win32") || has("win95") || has("win64") || has("win16"))
5993 let home= substitute(home,'/','\\','g')
5994 endif
5995 endif
5996 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005997 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005998" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005999 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006000" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006001 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006002 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006003" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006004 call mkdir(home)
6005 endif
6006 endif
6007 let g:netrw_home= home
6008 return home
6009endfun
6010
6011" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006012" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6013fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006014 if exists("s:netrwdrag")
6015 return
6016 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006017 if &ft != "netrw"
6018 return
6019 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006020" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006021
Bram Moolenaar97d62492012-11-15 21:28:22 +01006022 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006023 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006024 while getchar(0) != 0
6025 "clear the input stream
6026 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006027 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006028 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006029 let mouse_lnum = v:mouse_lnum
6030 let wlastline = line('w$')
6031 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006032" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6033" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006034 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6035 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006036 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006037" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6038 return
6039 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006040 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006041 " 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 +01006042 " without this test when its disabled.
6043 " 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 +01006044" 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 +01006045 if v:mouse_col > virtcol('.')
6046 let @@= ykeep
6047" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6048 return
6049 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006050
Bram Moolenaar446cb832008-06-24 21:56:24 +00006051 if a:islocal
6052 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006053 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006054 endif
6055 else
6056 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006057 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006058 endif
6059 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006060 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006061" call Dret("s:NetrwLeftmouse")
6062endfun
6063
6064" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006065" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6066fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006067 if &ft != "netrw"
6068 return
6069 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006070" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6071 call s:NetrwMarkFileTgt(a:islocal)
6072" call Dret("s:NetrwCLeftmouse")
6073endfun
6074
6075" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006076" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6077" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006078" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006079" a:islocal=2 : <c-r> used, remote
6080" a:islocal=3 : <c-r> used, local
6081fun! s:NetrwServerEdit(islocal,fname)
6082" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6083 let islocal = a:islocal%2 " =0: remote =1: local
6084 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006089 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006092 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6094 unlet s:netrw_browse_split_{winnr()}
6095 endif
6096 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6097" call Dret("s:NetrwServerEdit")
6098 return
6099 endif
6100
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006103" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104
6105 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006106" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006107 let srvrname = g:netrw_browse_split[0]
6108 let tabnum = g:netrw_browse_split[1]
6109 let winnum = g:netrw_browse_split[2]
6110
6111 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006112" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006113
6114 if !ctrlr
6115 " user must have closed the server window and the user did not use <c-r>, but
6116 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006117" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006118 if exists("g:netrw_browse_split")
6119 unlet g:netrw_browse_split
6120 endif
6121 let g:netrw_browse_split= 0
6122 if exists("s:netrw_browse_split_".winnr())
6123 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6124 endif
6125 call s:NetrwBrowseChgDir(islocal,a:fname)
6126" call Dret("s:NetrwServerEdit")
6127 return
6128
6129 elseif has("win32") && executable("start")
6130 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006131" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006132 call system("start gvim --servername ".srvrname)
6133
6134 else
6135 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006136" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006137 call system("gvim --servername ".srvrname)
6138 endif
6139 endif
6140
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006141" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006142 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6143 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006144 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006145
6146 else
6147
6148 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6149
6150 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006151" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006152 if exists("g:netrw_browse_split")
6153 unlet g:netrw_browse_split
6154 endif
6155 let g:netrw_browse_split= 0
6156 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6157" call Dret("s:NetrwServerEdit")
6158 return
6159
6160 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006161" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006162 if has("win32") && executable("start")
6163 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006164" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006165 call system("start gvim --servername ".g:netrw_servername)
6166 else
6167 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006168" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006169 call system("gvim --servername ".g:netrw_servername)
6170 endif
6171 endif
6172 endif
6173
6174 while 1
6175 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006176" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6177 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006178 break
6179 catch /^Vim\%((\a\+)\)\=:E241/
6180 sleep 200m
6181 endtry
6182 endwhile
6183
6184 if exists("g:netrw_browse_split")
6185 if type(g:netrw_browse_split) != 3
6186 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6187 endif
6188 unlet g:netrw_browse_split
6189 endif
6190 let g:netrw_browse_split= [g:netrw_servername,1,1]
6191 endif
6192
6193 else
6194 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6195 endif
6196
6197" call Dret("s:NetrwServerEdit")
6198endfun
6199
6200" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006201" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6202fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006203 if &ft != "netrw"
6204 return
6205 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006206" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006207
Bram Moolenaar8d043172014-01-23 14:24:41 +01006208 let s:ngw= s:NetrwGetWord()
6209 call s:NetrwMarkFile(a:islocal,s:ngw)
6210
6211" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006212endfun
6213
6214" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006215" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6216" Used to mark multiple files.
6217fun! s:NetrwSLeftdrag(islocal)
6218" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6219 if !exists("s:netrwdrag")
6220 let s:netrwdrag = winnr()
6221 if a:islocal
6222 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006223 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006224 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006225 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006226 endif
6227 let ngw = s:NetrwGetWord()
6228 if !exists("s:ngw") || s:ngw != ngw
6229 call s:NetrwMarkFile(a:islocal,ngw)
6230 endif
6231 let s:ngw= ngw
6232" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6233endfun
6234
6235" ---------------------------------------------------------------------
6236" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6237fun! s:NetrwSLeftrelease(islocal)
6238" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6239 if exists("s:netrwdrag")
6240 nunmap <s-leftrelease>
6241 let ngw = s:NetrwGetWord()
6242 if !exists("s:ngw") || s:ngw != ngw
6243 call s:NetrwMarkFile(a:islocal,ngw)
6244 endif
6245 if exists("s:ngw")
6246 unlet s:ngw
6247 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006248 unlet s:netrwdrag
6249 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006250" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006251endfun
6252
6253" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006254" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6255" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006257" 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 +02006258" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006259 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006260
6261 " 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 +02006262 " How-it-works: take the hiding command, convert it into a range.
6263 " Duplicate characters don't matter.
6264 " Remove all such characters from the '/~@#...890' string.
6265 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006266" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006268 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006269" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270
6271 while listhide != ""
6272 if listhide =~ ','
6273 let hide = substitute(listhide,',.*$','','e')
6274 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6275 else
6276 let hide = listhide
6277 let listhide = ""
6278 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006279" 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 +01006280 if g:netrw_sort_by =~ '^[ts]'
6281 if hide =~ '^\^'
6282" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6283 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6284 elseif hide =~ '^\\(\^'
6285 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6286 endif
6287" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6288 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289
6290 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006291" 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 +00006292 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006293" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006294 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006295 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006296" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006297 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006298 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006299" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006301
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006303 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006304" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006305 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006306" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307 endif
6308
Bram Moolenaaradc21822011-04-01 18:03:16 +02006309 " remove any blank lines that have somehow remained.
6310 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006311 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006312
Bram Moolenaar97d62492012-11-15 21:28:22 +01006313 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006314" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315endfun
6316
6317" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006318" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006319" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006320fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006321" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006322
Bram Moolenaar97d62492012-11-15 21:28:22 +01006323 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324 " get name of new directory from user. A bare <CR> will skip.
6325 " if its currently a directory, also request will be skipped, but with
6326 " a message.
6327 call inputsave()
6328 let newdirname= input("Please give directory name: ")
6329 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006330" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006331
6332 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006333 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006334" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 return
6336 endif
6337
6338 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006339" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340
6341 " Local mkdir:
6342 " sanity checks
6343 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006344" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6345 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006346 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006347 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006348 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006349 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006350" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006351 return
6352 endif
6353 if s:FileReadable(fullnewdir)
6354 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006355 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006356 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006357 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006358" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006359 return
6360 endif
6361
6362 " requested new local directory is neither a pre-existing file or
6363 " directory, so make it!
6364 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006365 if has("unix")
6366 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6367 else
6368 call mkdir(fullnewdir,"p")
6369 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370 else
6371 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006372 if s:NetrwLcd(b:netrw_curdir)
6373" call Dret("s:NetrwMakeDir : lcd failure")
6374 return
6375 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006376" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006377 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006378 if v:shell_error != 0
6379 let @@= ykeep
6380 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 +01006381" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006382 return
6383 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006384 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006385" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006386 if s:NetrwLcd(netrw_origdir)
6387" call Dret("s:NetrwBrowse : lcd failure")
6388 return
6389 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006390 endif
6391 endif
6392
6393 if v:shell_error == 0
6394 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006395" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006396 let svpos= winsaveview()
6397" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006398 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006399" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6400 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006401 elseif !exists("g:netrw_quiet")
6402 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6403 endif
6404" redraw!
6405
6406 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006407 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006408" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6410 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006411 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006412 if v:shell_error == 0
6413 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006414 let svpos= winsaveview()
6415" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006416 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006417" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6418 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006419 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006420 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006421 endif
6422" redraw!
6423
6424 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006425 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006426 let svpos= winsaveview()
6427" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006428" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006429 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006431 let remotepath= b:netrw_fname
6432 else
6433 let remotepath= ""
6434 endif
6435 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006436 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006437" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6438 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006439
Bram Moolenaar446cb832008-06-24 21:56:24 +00006440 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006441 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006442 let svpos= winsaveview()
6443" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006444" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006445 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006446" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006447 let remotepath= b:netrw_fname
6448 else
6449 let remotepath= ""
6450 endif
6451 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006452 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006453" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6454 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006455 endif
6456
Bram Moolenaar97d62492012-11-15 21:28:22 +01006457 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006458" call Dret("s:NetrwMakeDir")
6459endfun
6460
6461" ---------------------------------------------------------------------
6462" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6463fun! s:TreeSqueezeDir(islocal)
6464" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6465 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6466 " its a tree-listing style
6467 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006468 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006469 let depth = strchars(substitute(curdepth,' ','','g'))
6470 let srch = -1
6471" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6472" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006473" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006474" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6475 if depth >= 2
6476 NetrwKeepj norm! 0
6477 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6478 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6479" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6480" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6481 elseif depth == 1
6482 NetrwKeepj norm! 0
6483 let treedepthchr= substitute(s:treedepthstring,' ','','')
6484 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6485" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6486 endif
6487 if srch > 0
6488" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6489 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6490 exe srch
6491 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006492 endif
6493" call Dret("s:TreeSqueezeDir")
6494endfun
6495
6496" ---------------------------------------------------------------------
6497" s:NetrwMaps: {{{2
6498fun! s:NetrwMaps(islocal)
6499" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6500
Bram Moolenaar85850f32019-07-19 22:05:51 +02006501 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006502 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006503" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006504 if !hasmapto("<Plug>NetrwReturn")
6505 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006506" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006507 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6508 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006509" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006510 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6511 endif
6512 endif
6513 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006514" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006515 endif
6516
Bram Moolenaar85850f32019-07-19 22:05:51 +02006517 " generate default <Plug> maps {{{3
6518 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006519 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006520 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6521 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6522 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6523 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6524 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6525 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6526 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6527 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6528 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6529 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6530" ---------------------------------------------------------------------
6531" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6532" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6533" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6534" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6535" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6536" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6537" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6538" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6539" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6540" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6541" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6542" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6543" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6544" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6545" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6546" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6547" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6548" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6549" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6550" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6551" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6552" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6553" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6554" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6555" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6556" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6557" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6558" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6559" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6560" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6561" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6562" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6563" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6564" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6565" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6566" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6567" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6568" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6569" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6570" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6571" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6572" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6573" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6574" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6575" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6576" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6577" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6578
Bram Moolenaara6878372014-03-22 21:02:50 +01006579 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006580" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006581 " local normal-mode maps {{{3
6582 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6583 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6584 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6585 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6586 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6587 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6588 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6589 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6590 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6591 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6592 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6593" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006594 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6595 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6596 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006597 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006598 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006599 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6602 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006603 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6604 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6605 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6606 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6607 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6608 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6609 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6610 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6611 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6612 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6613 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6614 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6615 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006616 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006617 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6619 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6620 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6621 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6622 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006623 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006624 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006625 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6626 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006627 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6628 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6629 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006631 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006632 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6633 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006634 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006635 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006636 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6637 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6638 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006639 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6640 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006641
6642 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 +01006643 if !hasmapto('<Plug>NetrwHideEdit')
6644 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006645 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006647 if !hasmapto('<Plug>NetrwRefresh')
6648 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006649 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006650 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 +01006651 if s:didstarstar || !mapcheck("<s-down>","n")
6652 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006653 endif
6654 if s:didstarstar || !mapcheck("<s-up>","n")
6655 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006656 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006657 if !hasmapto('<Plug>NetrwTreeSqueeze')
6658 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006659 endif
6660 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006661 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6662 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006663 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6664 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6665 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6666 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6667 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6668 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6669 imap <buffer> <leftmouse> <Plug>ILeftmouse
6670 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006671 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006672 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006673 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006674 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006675 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006676 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006677 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6678 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006680 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6681 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6682 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6683 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6684 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6685 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6686 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006687 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6688
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 " support user-specified maps
6690 call netrw#UserMaps(1)
6691
Bram Moolenaar85850f32019-07-19 22:05:51 +02006692 else
6693 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006694" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006695 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006696 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6697 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6698 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6699 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6700 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6701 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6702 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6703 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6704 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6705 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6706 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6707" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006708 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6709 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6710 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6712 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6713 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6715 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006716 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006717 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006718 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6720 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6722 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6723 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6724 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6725 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6726 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6727 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006729 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006730 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006731 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6732 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6733 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6734 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6735 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006736 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6737 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6738 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6739 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006740 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006741 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6742 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006743 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006744 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 +01006745 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6746 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6747 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6748 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6749 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6750 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6751 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6752 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6753 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006754 if !hasmapto('<Plug>NetrwHideEdit')
6755 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006756 endif
6757 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6758 if !hasmapto('<Plug>NetrwRefresh')
6759 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006760 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006761 if !hasmapto('<Plug>NetrwTreeSqueeze')
6762 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006763 endif
6764 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006765
6766 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006767 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006768
6769 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6770 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6772 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6773 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6774 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6775 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6776 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6777 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6778 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6779 nmap <middlemouse> <Plug>NetrwMiddlemouse
6780 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6781 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6782 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6783 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006784 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006785 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006786 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6787 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006788 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006789 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6790 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6791 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6792 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6793 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6794 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6795 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006796 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006797
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006798 " support user-specified maps
6799 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006800 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006801
6802" call Dret("s:NetrwMaps")
6803endfun
6804
6805" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006806" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006807" If -buffer, the command is only available from within netrw buffers
6808" Otherwise, the command is available from any window, so long as netrw
6809" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006810fun! s:NetrwCommands(islocal)
6811" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6812
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006813 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6814 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006815 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 +01006816 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006817 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006818 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006819 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006820 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006821 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006822
6823" call Dret("s:NetrwCommands")
6824endfun
6825
6826" ---------------------------------------------------------------------
6827" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6828" glob()ing only works with local files
6829fun! s:NetrwMarkFiles(islocal,...)
6830" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006831 let curdir = s:NetrwGetCurdir(a:islocal)
6832 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006833 while i <= a:0
6834 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006835 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006836 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006837 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006838 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006839 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006840 else
6841 let mffiles= [a:{i}]
6842 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006843" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006844 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006846 call s:NetrwMarkFile(a:islocal,mffile)
6847 endfor
6848 let i= i + 1
6849 endwhile
6850" call Dret("s:NetrwMarkFiles")
6851endfun
6852
6853" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006854" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006855fun! s:NetrwMarkTarget(...)
6856" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6857 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006858 let curdir = s:NetrwGetCurdir(1)
6859 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006860 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006861 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6862 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006863 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006864" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006865 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006866 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6867 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006868 let svpos = winsaveview()
6869" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006870 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006871" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6872 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006873" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006874endfun
6875
6876" ---------------------------------------------------------------------
6877" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6878" mark and unmark files. If a markfile list exists,
6879" then the rename and delete functions will use it instead
6880" of whatever may happen to be under the cursor at that
6881" moment. When the mouse and gui are available,
6882" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006883"
6884" Creates two lists
6885" s:netrwmarkfilelist -- holds complete paths to all marked files
6886" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6887"
6888" Creates a marked file match string
6889" s:netrwmarfilemtch_# -- used with 2match to display marked files
6890"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006891" Creates a buffer version of islocal
6892" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006893fun! s:NetrwMarkFile(islocal,fname)
6894" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006895" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006896
6897 " sanity check
6898 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006899" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006900 return
6901 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006902 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006903
Bram Moolenaar97d62492012-11-15 21:28:22 +01006904 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006905 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006906 if a:fname =~ '^\a'
6907 let leader= '\<'
6908 else
6909 let leader= ''
6910 endif
6911 if a:fname =~ '\a$'
6912 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6913 else
6914 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6915 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006916
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006917 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006918 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006919" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6920" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6921" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006922 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006923
6924 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006925 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006926" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006928 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006929
6930 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006931 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006932" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006933 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6934 if s:netrwmarkfilelist_{curbufnr} == []
6935 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006936" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006937 call s:NetrwUnmarkList(curbufnr,curdir)
6938 else
6939 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006940" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006942 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006943 for fname in s:netrwmarkfilelist_{curbufnr}
6944 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006945 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006947 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006948 endif
6949 let first= 0
6950 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006951" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 endif
6953 endif
6954
6955 else
6956 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006957" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006958
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006959" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006960 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006961 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6962" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006963
6964 " build initial markfile matching pattern
6965 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006966 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006968 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006970" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971 endif
6972
6973 " handle global markfilelist
6974 if exists("s:netrwmarkfilelist")
6975 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6976 if index(s:netrwmarkfilelist,dname) == -1
6977 " append new filename to global markfilelist
6978 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006979" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006980 else
6981 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006982" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6983" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006984 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006985" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006986 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006987" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006988 unlet s:netrwmarkfilelist
6989 endif
6990 endif
6991 else
6992 " initialize new global-directory markfilelist
6993 let s:netrwmarkfilelist= []
6994 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006995" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006996 endif
6997
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006998 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006999 if has("syntax") && exists("g:syntax_on") && g:syntax_on
7000 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
7001" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
7002 if exists("g:did_drchip_netrwlist_syntax")
7003 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
7004 endif
7005 else
7006" " call Decho("2match none",'~'.expand("<slnum>"))
7007 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007008 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007009 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007010 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007011" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7012" 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 +00007013endfun
7014
7015" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007016" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7017" mA: move the argument list to marked file list (tomflist=1)
7018" Uses the global marked file list
7019fun! s:NetrwMarkFileArgList(islocal,tomflist)
7020" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7021
7022 let svpos = winsaveview()
7023" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7024 let curdir = s:NetrwGetCurdir(a:islocal)
7025 let curbufnr = bufnr("%")
7026
7027 if a:tomflist
7028 " mA: move argument list to marked file list
7029 while argc()
7030 let fname= argv(0)
7031" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7032 exe "argdel ".fnameescape(fname)
7033 call s:NetrwMarkFile(a:islocal,fname)
7034 endwhile
7035
7036 else
7037 " ma: move marked file list to argument list
7038 if exists("s:netrwmarkfilelist")
7039
7040 " for every filename in the marked list
7041 for fname in s:netrwmarkfilelist
7042" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7043 exe "argadd ".fnameescape(fname)
7044 endfor " for every file in the marked list
7045
7046 " unmark list and refresh
7047 call s:NetrwUnmarkList(curbufnr,curdir)
7048 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7049" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7050 NetrwKeepj call winrestview(svpos)
7051 endif
7052 endif
7053
7054" call Dret("s:NetrwMarkFileArgList")
7055endfun
7056
7057" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007058" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7059" compress/decompress files using the programs
7060" in g:netrw_compress and g:netrw_uncompress,
7061" using g:netrw_compress_suffix to know which to
7062" do. By default:
7063" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007064" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007065fun! s:NetrwMarkFileCompress(islocal)
7066" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007067 let svpos = winsaveview()
7068" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007069 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007070 let curbufnr = bufnr("%")
7071
Bram Moolenaarff034192013-04-24 18:51:19 +02007072 " sanity check
7073 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007074 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007075" call Dret("s:NetrwMarkFileCompress")
7076 return
7077 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007078" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007079
Bram Moolenaar446cb832008-06-24 21:56:24 +00007080 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007081
7082 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007083 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007084 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007085" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007086 if exists("g:netrw_decompress['".sfx."']")
7087 " fname has a suffix indicating that its compressed; apply associated decompression routine
7088 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007089" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007090 let exe= netrw#WinPath(exe)
7091 if a:islocal
7092 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007093 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007095 call system(exe." ".fname)
7096 if v:shell_error
7097 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007098 endif
7099 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007100 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7101 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007102 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007103
Bram Moolenaarff034192013-04-24 18:51:19 +02007104 endif
7105 unlet sfx
7106
Bram Moolenaar446cb832008-06-24 21:56:24 +00007107 if exists("exe")
7108 unlet exe
7109 elseif a:islocal
7110 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007111 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007112 if v:shell_error
7113 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7114 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007115 else
7116 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007117 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007118 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007119 endfor " for every file in the marked list
7120
Bram Moolenaar446cb832008-06-24 21:56:24 +00007121 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007122 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007123" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7124 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007125 endif
7126" call Dret("s:NetrwMarkFileCompress")
7127endfun
7128
7129" ---------------------------------------------------------------------
7130" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7131" If no marked files, then set up directory as the
7132" target. Currently does not support copying entire
7133" directories. Uses the local-buffer marked file list.
7134" Returns 1=success (used by NetrwMarkFileMove())
7135" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007136fun! s:NetrwMarkFileCopy(islocal,...)
7137" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007139 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007140 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007141 if b:netrw_curdir !~ '/$'
7142 if !exists("b:netrw_curdir")
7143 let b:netrw_curdir= curdir
7144 endif
7145 let b:netrw_curdir= b:netrw_curdir."/"
7146 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007147
Bram Moolenaarff034192013-04-24 18:51:19 +02007148 " sanity check
7149 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007150 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007151" call Dret("s:NetrwMarkFileCopy")
7152 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007153 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007154" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007155
Bram Moolenaar446cb832008-06-24 21:56:24 +00007156 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007157 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007158" call Dret("s:NetrwMarkFileCopy 0")
7159 return 0
7160 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007161" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007162
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007163 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007164 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007165" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007166 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007167 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7168" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7169 return
7170 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007171
7172 " copy marked files while within the same directory (ie. allow renaming)
7173 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7174 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7175 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007176" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007177 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007178 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7179 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007180" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007181 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007182 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007183 let oldname = a:1
7184 else
7185 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007186" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007187 let s:recursive= 1
7188 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7189 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7190 if ret == 0
7191 break
7192 endif
7193 endfor
7194 unlet s:recursive
7195 call s:NetrwUnmarkList(curbufnr,curdir)
7196" call Dret("s:NetrwMarkFileCopy ".ret)
7197 return ret
7198 endif
7199
7200 call inputsave()
7201 let newname= input("Copy ".oldname." to : ",oldname,"file")
7202 call inputrestore()
7203 if newname == ""
7204" call Dret("s:NetrwMarkFileCopy 0")
7205 return 0
7206 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207 let args= s:ShellEscape(oldname)
7208 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007209 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007210 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7211 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007212 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007213 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7214 let args= substitute(args,'/','\\','g')
7215 let tgt = substitute(tgt, '/','\\','g')
7216 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007217 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7218 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7219 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7220 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7221" call Decho("args <".args.">",'~'.expand("<slnum>"))
7222" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007223 if isdirectory(s:NetrwFile(args))
7224" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007225 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007226" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007227 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7228 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7229 " contents to a target. One must append the source directory name to the target to get xcopy to
7230 " do the right thing.
7231 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007232" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007233 endif
7234 else
7235 let copycmd= g:netrw_localcopycmd
7236 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007237 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007238 let copycmd = substitute(copycmd,'\s.*$','','')
7239 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007240 let copycmd = netrw#WinPath(copycmd).copycmdargs
7241 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007242 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007243 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007244" call Decho("args <".args.">",'~'.expand("<slnum>"))
7245" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7246" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7247" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007248 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007249 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007250 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007251 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 +01007252 else
7253 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7254 endif
7255" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007256 return 0
7257 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007258
7259 elseif a:islocal && !s:netrwmftgt_islocal
7260 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007261" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007262 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007263
7264 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007265 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007266" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007267 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268
7269 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007270 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007272 let curdir = getcwd()
7273 let tmpdir = s:GetTempfile("")
7274 if tmpdir !~ '/'
7275 let tmpdir= curdir."/".tmpdir
7276 endif
7277 if exists("*mkdir")
7278 call mkdir(tmpdir)
7279 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007280 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007281 if v:shell_error != 0
7282 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 +01007283" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007284 return
7285 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007286 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007287 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007288 if s:NetrwLcd(tmpdir)
7289" call Dret("s:NetrwMarkFileCopy : lcd failure")
7290 return
7291 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007292 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007293 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007294 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295 if getcwd() == tmpdir
7296 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007297 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007298 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007299 if s:NetrwLcd(curdir)
7300" call Dret("s:NetrwMarkFileCopy : lcd failure")
7301 return
7302 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007303 if delete(tmpdir,"d")
7304 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007305 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007306 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007307 if s:NetrwLcd(curdir)
7308" call Dret("s:NetrwMarkFileCopy : lcd failure")
7309 return
7310 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007311 endif
7312 endif
7313 endif
7314
7315 " -------
7316 " cleanup
7317 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007318" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007319 " remove markings from local buffer
7320 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007321" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7322" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7323" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7324" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7325" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7326" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7327 if exists("s:recursive")
7328" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7329 else
7330" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007331 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007332 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007333 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007334 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007335 else
7336 " refresh local and targets for fast browsing
7337 if !exists("s:recursive")
7338 " remove markings from local buffer
7339" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7340 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7341 endif
7342
7343 " refresh buffers
7344 if s:netrwmftgt_islocal
7345" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7346 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7347 endif
7348 if a:islocal && s:netrwmftgt != curdir
7349" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7350 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7351 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007352 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007353
Bram Moolenaar446cb832008-06-24 21:56:24 +00007354" call Dret("s:NetrwMarkFileCopy 1")
7355 return 1
7356endfun
7357
7358" ---------------------------------------------------------------------
7359" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7360" invoke vim's diff mode on the marked files.
7361" Either two or three files can be so handled.
7362" Uses the global marked file list.
7363fun! s:NetrwMarkFileDiff(islocal)
7364" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7365 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007366
Bram Moolenaarff034192013-04-24 18:51:19 +02007367 " sanity check
7368 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007369 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007370" call Dret("s:NetrwMarkFileDiff")
7371 return
7372 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007373 let curdir= s:NetrwGetCurdir(a:islocal)
7374" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007375
Bram Moolenaara6878372014-03-22 21:02:50 +01007376 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007378 for fname in s:netrwmarkfilelist
7379 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007381" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007382 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007383 diffthis
7384 elseif cnt == 2 || cnt == 3
7385 vsplit
7386 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007387" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007388 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007389 diffthis
7390 else
7391 break
7392 endif
7393 endfor
7394 call s:NetrwUnmarkList(curbufnr,curdir)
7395 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007396
Bram Moolenaar446cb832008-06-24 21:56:24 +00007397" call Dret("s:NetrwMarkFileDiff")
7398endfun
7399
7400" ---------------------------------------------------------------------
7401" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7402" Uses global markfilelist
7403fun! s:NetrwMarkFileEdit(islocal)
7404" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7405
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007406 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007407 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007408
7409 " sanity check
7410 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007411 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007412" call Dret("s:NetrwMarkFileEdit")
7413 return
7414 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007415" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007416
Bram Moolenaar446cb832008-06-24 21:56:24 +00007417 if exists("s:netrwmarkfilelist_{curbufnr}")
7418 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007419 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007420 " unmark markedfile list
7421" call s:NetrwUnmarkList(curbufnr,curdir)
7422 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007424 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007425 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007426 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007427
Bram Moolenaar446cb832008-06-24 21:56:24 +00007428" call Dret("s:NetrwMarkFileEdit")
7429endfun
7430
7431" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007432" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007433fun! s:NetrwMarkFileQFEL(islocal,qfel)
7434" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7435 call s:NetrwUnmarkAll()
7436 let curbufnr= bufnr("%")
7437
7438 if !empty(a:qfel)
7439 for entry in a:qfel
7440 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007441" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007442 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007443" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007444 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7445 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7446 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7447 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007448" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007449 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7450 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007451" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007452 endif
7453 endfor
7454 echo "(use me to edit marked files)"
7455 else
7456 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7457 endif
7458
7459" call Dret("s:NetrwMarkFileQFEL")
7460endfun
7461
7462" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7464" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7465" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7466fun! s:NetrwMarkFileExe(islocal,enbloc)
7467" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007468 let svpos = winsaveview()
7469" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007470 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007471 let curbufnr = bufnr("%")
7472
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007473 if a:enbloc == 0
7474 " individually apply command to files, one at a time
7475 " sanity check
7476 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7477 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7478" call Dret("s:NetrwMarkFileExe")
7479 return
7480 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007481" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007482
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 if exists("s:netrwmarkfilelist_{curbufnr}")
7484 " get the command
7485 call inputsave()
7486 let cmd= input("Enter command: ","","file")
7487 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007488" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007489 if cmd == ""
7490" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7491 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007492 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007493
7494 " apply command to marked files, individually. Substitute: filename -> %
7495 " If no %, then append a space and the filename to the command
7496 for fname in s:netrwmarkfilelist_{curbufnr}
7497 if a:islocal
7498 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007499 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007500 endif
7501 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007502 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007503 endif
7504 if cmd =~ '%'
7505 let xcmd= substitute(cmd,'%',fname,'g')
7506 else
7507 let xcmd= cmd.' '.fname
7508 endif
7509 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007510" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007511 let ret= system(xcmd)
7512 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007513" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007514 let ret= s:RemoteSystem(xcmd)
7515 endif
7516 if v:shell_error < 0
7517 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7518 break
7519 else
7520 echo ret
7521 endif
7522 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007523
7524 " unmark marked file list
7525 call s:NetrwUnmarkList(curbufnr,curdir)
7526
7527 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007528 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007529" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7530 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007531 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007532 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007533 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007534
7535 else " apply command to global list of files, en bloc
7536
7537 call inputsave()
7538 let cmd= input("Enter command: ","","file")
7539 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007540" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007541 if cmd == ""
7542" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7543 return
7544 endif
7545 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007546 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007547 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007548 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007549 endif
7550 if a:islocal
7551 call system(cmd)
7552 if v:shell_error < 0
7553 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7554 endif
7555 else
7556 let ret= s:RemoteSystem(cmd)
7557 endif
7558 call s:NetrwUnmarkAll()
7559
7560 " refresh the listing
7561 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007562" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7563 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007564
7565 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007566
Bram Moolenaar446cb832008-06-24 21:56:24 +00007567" call Dret("s:NetrwMarkFileExe")
7568endfun
7569
7570" ---------------------------------------------------------------------
7571" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7572" as the marked file(s) (toggles suffix presence)
7573" Uses the local marked file list.
7574fun! s:NetrwMarkHideSfx(islocal)
7575" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007576 let svpos = winsaveview()
7577" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007578 let curbufnr = bufnr("%")
7579
7580 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7581 if exists("s:netrwmarkfilelist_{curbufnr}")
7582
7583 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007584" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007585 " construct suffix pattern
7586 if fname =~ '\.'
7587 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7588 else
7589 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7590 endif
7591 " determine if its in the hiding list or not
7592 let inhidelist= 0
7593 if g:netrw_list_hide != ""
7594 let itemnum = 0
7595 let hidelist= split(g:netrw_list_hide,',')
7596 for hidepat in hidelist
7597 if sfxpat == hidepat
7598 let inhidelist= 1
7599 break
7600 endif
7601 let itemnum= itemnum + 1
7602 endfor
7603 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007604" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605 if inhidelist
7606 " remove sfxpat from list
7607 call remove(hidelist,itemnum)
7608 let g:netrw_list_hide= join(hidelist,",")
7609 elseif g:netrw_list_hide != ""
7610 " append sfxpat to non-empty list
7611 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7612 else
7613 " set hiding list to sfxpat
7614 let g:netrw_list_hide= sfxpat
7615 endif
7616 endfor
7617
7618 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007619 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007620" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7621 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007622 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007623 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007624 endif
7625
7626" call Dret("s:NetrwMarkHideSfx")
7627endfun
7628
7629" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007630" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007631" Uses the local marked-file list.
7632fun! s:NetrwMarkFileVimCmd(islocal)
7633" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007634 let svpos = winsaveview()
7635" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007636 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007637 let curbufnr = bufnr("%")
7638
Bram Moolenaarff034192013-04-24 18:51:19 +02007639 " sanity check
7640 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007641 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007642" call Dret("s:NetrwMarkFileVimCmd")
7643 return
7644 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007645" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007646
Bram Moolenaar15146672011-10-20 22:22:38 +02007647 if exists("s:netrwmarkfilelist_{curbufnr}")
7648 " get the command
7649 call inputsave()
7650 let cmd= input("Enter vim command: ","","file")
7651 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007653 if cmd == ""
7654" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7655 return
7656 endif
7657
7658 " apply command to marked files. Substitute: filename -> %
7659 " If no %, then append a space and the filename to the command
7660 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007661" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007662 if a:islocal
7663 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007664 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007665" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007666 exe cmd
7667 exe "sil! keepalt wq!"
7668 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007669" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007670 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007671 endif
7672 endfor
7673
7674 " unmark marked file list
7675 call s:NetrwUnmarkList(curbufnr,curdir)
7676
7677 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007678 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007679" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7680 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007681 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007682 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007683 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007684
Bram Moolenaar15146672011-10-20 22:22:38 +02007685" call Dret("s:NetrwMarkFileVimCmd")
7686endfun
7687
7688" ---------------------------------------------------------------------
7689" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7690" as the marked file(s) (toggles suffix presence)
7691" Uses the local marked file list.
7692fun! s:NetrwMarkHideSfx(islocal)
7693" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007694 let svpos = winsaveview()
7695" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007696 let curbufnr = bufnr("%")
7697
7698 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7699 if exists("s:netrwmarkfilelist_{curbufnr}")
7700
7701 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007702" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007703 " construct suffix pattern
7704 if fname =~ '\.'
7705 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7706 else
7707 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7708 endif
7709 " determine if its in the hiding list or not
7710 let inhidelist= 0
7711 if g:netrw_list_hide != ""
7712 let itemnum = 0
7713 let hidelist= split(g:netrw_list_hide,',')
7714 for hidepat in hidelist
7715 if sfxpat == hidepat
7716 let inhidelist= 1
7717 break
7718 endif
7719 let itemnum= itemnum + 1
7720 endfor
7721 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007722" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007723 if inhidelist
7724 " remove sfxpat from list
7725 call remove(hidelist,itemnum)
7726 let g:netrw_list_hide= join(hidelist,",")
7727 elseif g:netrw_list_hide != ""
7728 " append sfxpat to non-empty list
7729 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7730 else
7731 " set hiding list to sfxpat
7732 let g:netrw_list_hide= sfxpat
7733 endif
7734 endfor
7735
7736 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007737 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007738" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7739 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007740 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007741 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007742 endif
7743
7744" call Dret("s:NetrwMarkHideSfx")
7745endfun
7746
7747" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007748" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7749" Uses the global markfilelist
7750fun! s:NetrwMarkFileGrep(islocal)
7751" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007752 let svpos = winsaveview()
7753" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007754 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007756
7757 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007758" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007759 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007760" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007761 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007762 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007763" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007764 let netrwmarkfilelist= "*"
7765 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007766
Bram Moolenaarff034192013-04-24 18:51:19 +02007767 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007768" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007769 call inputsave()
7770 let pat= input("Enter pattern: ","")
7771 call inputrestore()
7772 let patbang = ""
7773 if pat =~ '^!'
7774 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007775 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007776 endif
7777 if pat =~ '^\i'
7778 let pat = escape(pat,'/')
7779 let pat = '/'.pat.'/'
7780 else
7781 let nonisi = pat[0]
7782 endif
7783
7784 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007785" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007786 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007787 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007788 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007789 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007790" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7791 return
7792 endtry
7793 echo "(use :cn, :cp to navigate, :Rex to return)"
7794
7795 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007796" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7797 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007798
7799 if exists("nonisi")
7800 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007801" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007802 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007803 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007804 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007805 endif
7806
7807" call Dret("s:NetrwMarkFileGrep")
7808endfun
7809
7810" ---------------------------------------------------------------------
7811" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7812" uses the global marked file list
7813" s:netrwmfloc= 0: target directory is remote
7814" = 1: target directory is local
7815fun! s:NetrwMarkFileMove(islocal)
7816" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007817 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007818 let curbufnr = bufnr("%")
7819
7820 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007821 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007822 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823" call Dret("s:NetrwMarkFileMove")
7824 return
7825 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007826" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007827
Bram Moolenaar446cb832008-06-24 21:56:24 +00007828 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007829 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830" call Dret("s:NetrwMarkFileCopy 0")
7831 return 0
7832 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007834
7835 if a:islocal && s:netrwmftgt_islocal
7836 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007837" call Decho("move from local to local",'~'.expand("<slnum>"))
7838" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007839 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007840 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7841" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7842 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007843 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007844 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007845" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007846 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007847 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007848" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007849 if g:netrw_localmovecmd =~ '\s'
7850 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7851 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7852 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007854 else
7855 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007857 endif
7858 else
7859 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007861 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007862 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007863 if g:netrw_keepdir
7864 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7865 let fname= b:netrw_curdir."/".fname
7866 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007867 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7868 let fname= substitute(fname,'/','\\','g')
Bram Moolenaar71badf92023-04-22 22:40:14 +01007869 if g:netrw_keepdir
7870 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7871 let fname= b:netrw_curdir."\\".fname
7872 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007873 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007874" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007875 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007876 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007878 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 +01007879 else
7880 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7881 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007882 break
7883 endif
7884 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007885
7886 elseif a:islocal && !s:netrwmftgt_islocal
7887 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007888" call Decho("move from local to remote",'~'.expand("<slnum>"))
7889" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007890 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007891 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007892" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007893 for fname in mflist
7894 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7895 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7896 endfor
7897 unlet mflist
7898
7899 elseif !a:islocal && s:netrwmftgt_islocal
7900 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007901" call Decho("move from remote to local",'~'.expand("<slnum>"))
7902" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007903 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007904 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007905" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007906 for fname in mflist
7907 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7908 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7909 endfor
7910 unlet mflist
7911
7912 elseif !a:islocal && !s:netrwmftgt_islocal
7913 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007914" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7915" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007916 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007917 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007918" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007919 for fname in mflist
7920 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7921 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7922 endfor
7923 unlet mflist
7924 endif
7925
7926 " -------
7927 " cleanup
7928 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007929" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007930
7931 " remove markings from local buffer
7932 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7933
7934 " refresh buffers
7935 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007936" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007937 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007938 endif
7939 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007940" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007941 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007942 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007943 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007944" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007945 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007946 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007947
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948" call Dret("s:NetrwMarkFileMove")
7949endfun
7950
7951" ---------------------------------------------------------------------
7952" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7953" using the hardcopy command. Local marked-file list only.
7954fun! s:NetrwMarkFilePrint(islocal)
7955" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7956 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007957
7958 " sanity check
7959 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007960 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007961" call Dret("s:NetrwMarkFilePrint")
7962 return
7963 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007964" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7965 let curdir= s:NetrwGetCurdir(a:islocal)
7966
Bram Moolenaar446cb832008-06-24 21:56:24 +00007967 if exists("s:netrwmarkfilelist_{curbufnr}")
7968 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007969 call s:NetrwUnmarkList(curbufnr,curdir)
7970 for fname in netrwmarkfilelist
7971 if a:islocal
7972 if g:netrw_keepdir
7973 let fname= s:ComposePath(curdir,fname)
7974 endif
7975 else
7976 let fname= curdir.fname
7977 endif
7978 1split
7979 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007980" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007981 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007982" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007983 hardcopy
7984 q
7985 endfor
7986 2match none
7987 endif
7988" call Dret("s:NetrwMarkFilePrint")
7989endfun
7990
7991" ---------------------------------------------------------------------
7992" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7993" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007994" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007995fun! s:NetrwMarkFileRegexp(islocal)
7996" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7997
7998 " get the regular expression
7999 call inputsave()
8000 let regexp= input("Enter regexp: ","","file")
8001 call inputrestore()
8002
8003 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008004 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008005" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008006 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008007" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008008 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008009 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008010 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008011 else
8012 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008013 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008014 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008015" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016
8017 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008018 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008019 if fname =~ '^'.fnameescape(curdir)
8020" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8021 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8022 else
8023" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8024 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8025 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008026 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027
8028 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008029" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030
8031 " convert displayed listing into a filelist
8032 let eikeep = &ei
8033 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008034 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008035 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008036" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008037 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008038 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008039 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008040 sil NetrwKeepj norm! "ap
8041 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008043 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008044 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008046 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008047 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008049 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008050 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8053 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008054 call histdel("/",-1)
8055 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056 endif
8057 " convert regexp into the more usual glob-style format
8058 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008059" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008060 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008061 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062 let filelist= getline(1,line("$"))
8063 q!
8064 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008065 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008066 endfor
8067 unlet filelist
8068 let @a = areg
8069 let &ei = eikeep
8070 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008071 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008072
8073" call Dret("s:NetrwMarkFileRegexp")
8074endfun
8075
8076" ---------------------------------------------------------------------
8077" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8078" Uses the local marked file list.
8079fun! s:NetrwMarkFileSource(islocal)
8080" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8081 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008082
8083 " sanity check
8084 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008085 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008086" call Dret("s:NetrwMarkFileSource")
8087 return
8088 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008089" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8090 let curdir= s:NetrwGetCurdir(a:islocal)
8091
Bram Moolenaar446cb832008-06-24 21:56:24 +00008092 if exists("s:netrwmarkfilelist_{curbufnr}")
8093 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008094 call s:NetrwUnmarkList(curbufnr,curdir)
8095 for fname in netrwmarkfilelist
8096 if a:islocal
8097 if g:netrw_keepdir
8098 let fname= s:ComposePath(curdir,fname)
8099 endif
8100 else
8101 let fname= curdir.fname
8102 endif
8103 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008104" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008105 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008106 endfor
8107 2match none
8108 endif
8109" call Dret("s:NetrwMarkFileSource")
8110endfun
8111
8112" ---------------------------------------------------------------------
8113" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8114" Uses the global markfilelist
8115fun! s:NetrwMarkFileTag(islocal)
8116" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008117 let svpos = winsaveview()
8118" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008119 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008120 let curbufnr = bufnr("%")
8121
Bram Moolenaarff034192013-04-24 18:51:19 +02008122 " sanity check
8123 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008124 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008125" call Dret("s:NetrwMarkFileTag")
8126 return
8127 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008128" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008129
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008131" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8132 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008133 call s:NetrwUnmarkAll()
8134
8135 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008136
8137" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8138 call system(g:netrw_ctags." ".netrwmarkfilelist)
8139 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008140 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8141 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008142
Bram Moolenaar446cb832008-06-24 21:56:24 +00008143 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008144 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008145 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146 let curdir= b:netrw_curdir
8147 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008148 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008151 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008152 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008153 wq!
8154 endif
8155 2match none
8156 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008157" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8158 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 endif
8160
8161" call Dret("s:NetrwMarkFileTag")
8162endfun
8163
8164" ---------------------------------------------------------------------
8165" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008166" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008167" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008168" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008169" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008170fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008171" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8172 let svpos = winsaveview()
8173" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008174 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008175 let hadtgt = exists("s:netrwmftgt")
8176 if !exists("w:netrw_bannercnt")
8177 let w:netrw_bannercnt= b:netrw_bannercnt
8178 endif
8179
8180 " set up target
8181 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008182" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008183 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8184 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008185" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008186 unlet s:netrwmftgt s:netrwmftgt_islocal
8187 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008188 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008189 endif
8190 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008191" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8192 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008193" call Dret("s:NetrwMarkFileTgt : removed target")
8194 return
8195 else
8196 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008198 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008199
8200 else
8201 " get word under cursor.
8202 " * If directory, use it for the target.
8203 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008204" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008205 let curword= s:NetrwGetWord()
8206 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008207 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008208 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008209" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008210 elseif !a:islocal && tgtdir =~ '/$'
8211 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008212" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008213 else
8214 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008215" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008216 endif
8217 endif
8218 if a:islocal
8219 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8220 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 endif
8223 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008224 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008225 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8226 endif
8227 let s:netrwmftgt_islocal= a:islocal
8228
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008229 " need to do refresh so that the banner will be updated
8230 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008231 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008232" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008233 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008234 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008235" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008236 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8238 else
8239 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8240 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008241" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8242 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008243 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008244 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008245 endif
8246
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008247" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8248" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008249" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8250endfun
8251
8252" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008253" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8254fun! s:NetrwGetCurdir(islocal)
8255" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8256
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008257 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008258 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8259" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8260 elseif !exists("b:netrw_curdir")
8261 let b:netrw_curdir= getcwd()
8262" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8263 endif
8264
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008265" 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 +01008266 if b:netrw_curdir !~ '\<\a\{3,}://'
8267 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008268" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008269 if g:netrw_keepdir == 0
8270 call s:NetrwLcd(curdir)
8271 endif
8272 endif
8273
8274" call Dret("s:NetrwGetCurdir <".curdir.">")
8275 return b:netrw_curdir
8276endfun
8277
8278" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008279" s:NetrwOpenFile: query user for a filename and open it {{{2
8280fun! s:NetrwOpenFile(islocal)
8281" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008282 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008283 call inputsave()
8284 let fname= input("Enter filename: ")
8285 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008286" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8287
8288 " determine if Lexplore is in use
8289 if exists("t:netrw_lexbufnr")
8290 " check if t:netrw_lexbufnr refers to a netrw window
8291" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8292 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8293 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8294" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8295 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8296 exe "NetrwKeepj e ".fnameescape(fname)
8297 let @@= ykeep
8298" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8299 endif
8300 endif
8301
8302 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008303 if fname !~ '[/\\]'
8304 if exists("b:netrw_curdir")
8305 if exists("g:netrw_quiet")
8306 let netrw_quiet_keep = g:netrw_quiet
8307 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008308 let g:netrw_quiet = 1
8309 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008310 let s:rexposn_{bufnr("%")}= winsaveview()
8311" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008312 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008313 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008314 else
8315 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8316 endif
8317 if exists("netrw_quiet_keep")
8318 let g:netrw_quiet= netrw_quiet_keep
8319 else
8320 unlet g:netrw_quiet
8321 endif
8322 endif
8323 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008324 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008325 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008326 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008327" call Dret("s:NetrwOpenFile")
8328endfun
8329
8330" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008331" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8332" For the mapping to this function be made via
8333" netrwPlugin, you'll need to have had
8334" g:netrw_usetab set to non-zero.
8335fun! netrw#Shrink()
8336" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8337 let curwin = winnr()
8338 let wiwkeep = &wiw
8339 set wiw=1
8340
8341 if &ft == "netrw"
8342 if winwidth(0) > g:netrw_wiw
8343 let t:netrw_winwidth= winwidth(0)
8344 exe "vert resize ".g:netrw_wiw
8345 wincmd l
8346 if winnr() == curwin
8347 wincmd h
8348 endif
8349" call Decho("vert resize 0",'~'.expand("<slnum>"))
8350 else
8351 exe "vert resize ".t:netrw_winwidth
8352" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8353 endif
8354
8355 elseif exists("t:netrw_lexbufnr")
8356 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8357 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8358 let t:netrw_winwidth= winwidth(0)
8359 exe "vert resize ".g:netrw_wiw
8360 wincmd l
8361 if winnr() == curwin
8362 wincmd h
8363 endif
8364" call Decho("vert resize 0",'~'.expand("<slnum>"))
8365 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8366 exe "vert resize ".t:netrw_winwidth
8367" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8368 else
8369 call netrw#Lexplore(0,0)
8370 endif
8371
8372 else
8373 call netrw#Lexplore(0,0)
8374 endif
8375 let wiw= wiwkeep
8376
8377" call Dret("netrw#Shrink")
8378endfun
8379
8380" ---------------------------------------------------------------------
8381" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8382fun! s:NetSortSequence(islocal)
8383" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8384
8385 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008386 let svpos= winsaveview()
8387" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008388 call inputsave()
8389 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8390 call inputrestore()
8391
8392 " refresh the listing
8393 let g:netrw_sort_sequence= newsortseq
8394 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008395" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8396 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008397 let @@= ykeep
8398
8399" call Dret("NetSortSequence")
8400endfun
8401
8402" ---------------------------------------------------------------------
8403" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8404" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008405" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008406fun! s:NetrwUnmarkList(curbufnr,curdir)
8407" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8408
8409 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008410 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008411 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8412 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8413 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8414 call remove(s:netrwmarkfilelist,idx) " remove from global list
8415 endfor
8416 if s:netrwmarkfilelist == []
8417 unlet s:netrwmarkfilelist
8418 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008419
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420 " getting rid of the local marked-file lists is easy
8421 unlet s:netrwmarkfilelist_{a:curbufnr}
8422 endif
8423 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8424 unlet s:netrwmarkfilemtch_{a:curbufnr}
8425 endif
8426 2match none
8427" call Dret("s:NetrwUnmarkList")
8428endfun
8429
8430" ---------------------------------------------------------------------
8431" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8432fun! s:NetrwUnmarkAll()
8433" call Dfunc("s:NetrwUnmarkAll()")
8434 if exists("s:netrwmarkfilelist")
8435 unlet s:netrwmarkfilelist
8436 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008437 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008438 2match none
8439" call Dret("s:NetrwUnmarkAll")
8440endfun
8441
8442" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008443" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008444fun! s:NetrwUnmarkAll2()
8445" call Dfunc("s:NetrwUnmarkAll2()")
8446 redir => netrwmarkfilelist_let
8447 let
8448 redir END
8449 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008450 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008451 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8452 for flist in netrwmarkfilelist_list
8453 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8454 unlet s:netrwmarkfilelist_{curbufnr}
8455 unlet s:netrwmarkfilemtch_{curbufnr}
8456 endfor
8457" call Dret("s:NetrwUnmarkAll2")
8458endfun
8459
8460" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008461" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8462"
8463" Marked files are in two types of lists:
8464" s:netrwmarkfilelist -- holds complete paths to all marked files
8465" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8466"
8467" Marked files suitable for use with 2match are in:
8468" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469fun! s:NetrwUnMarkFile(islocal)
8470" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008471 let svpos = winsaveview()
8472" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008473 let curbufnr = bufnr("%")
8474
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008475 " unmark marked file list
8476 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8477 if exists("s:netrwmarkfilelist")
8478" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008479 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008480 endif
8481
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008482 let ibuf= 1
8483 while ibuf < bufnr("$")
8484 if exists("s:netrwmarkfilelist_".ibuf)
8485 unlet s:netrwmarkfilelist_{ibuf}
8486 unlet s:netrwmarkfilemtch_{ibuf}
8487 endif
8488 let ibuf = ibuf + 1
8489 endwhile
8490 2match none
8491
Bram Moolenaar446cb832008-06-24 21:56:24 +00008492" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008493"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8494call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008495" call Dret("s:NetrwUnMarkFile")
8496endfun
8497
8498" ---------------------------------------------------------------------
8499" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8500fun! s:NetrwMenu(domenu)
8501
8502 if !exists("g:NetrwMenuPriority")
8503 let g:NetrwMenuPriority= 80
8504 endif
8505
Bram Moolenaaradc21822011-04-01 18:03:16 +02008506 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008507" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8508
8509 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008510" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008511 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008512 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8516 if g:netrw_dirhistmax > 0
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8521 else
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8523 endif
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8538 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 +01008539 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 +02008540 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8559 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8560 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8561 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8562 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8563 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8564 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8565 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8566 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8567 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8568 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8569 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>'
8570 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>'
8571 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>'
8572 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8573 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>'
8574 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>'
8575 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 +01008576 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 +02008577 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8578 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008580 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8581 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008582
8583 elseif !a:domenu
8584 let s:netrwcnt = 0
8585 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008586 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587 exe curwin."wincmd w"
8588
8589 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008590" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008591 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008592" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008593 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 endif
8595 endif
8596" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008597 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598 endif
8599
8600endfun
8601
8602" ---------------------------------------------------------------------
8603" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8604" Used by the O maps (as <SID>NetrwObtain())
8605fun! s:NetrwObtain(islocal)
8606" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8607
Bram Moolenaar97d62492012-11-15 21:28:22 +01008608 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008609 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008610 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008611 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8613 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008614 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008616 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008617
8618" call Dret("NetrwObtain")
8619endfun
8620
8621" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008622" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8623" If there's only one window, then the window will first be split.
8624" Returns:
8625" choice = 0 : didn't have to choose
8626" choice = 1 : saved modified file in window first
8627" choice = 2 : didn't save modified file, opened window
8628" choice = 3 : cancel open
8629fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008630" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631
Bram Moolenaar97d62492012-11-15 21:28:22 +01008632 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008633 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008634 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008635" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636
8637 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008638 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008640" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8641" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8642 let curword = s:NetrwGetWord()
8643 let choice = 0
8644 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8645" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008646 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008647" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008648 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008649" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008650" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008651" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008652
Bram Moolenaar8d043172014-01-23 14:24:41 +01008653 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008654 if lastwinnr == 1
8655 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656" 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 +02008657 " g:netrw_preview=0: preview window shown in a horizontally split window
8658 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008659 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008660 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008661 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008663 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008665 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008666 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008667" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008668 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008669 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008670 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008671" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672
8673 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008674" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008675 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008676" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008677 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008678" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008679 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008680" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008681 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008683" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008684" call Decho("COMBAK#12: mod=".&mod)
8685
8686 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8687 " whoops -- user trying to open file in the Lexplore window.
8688 " Use Lexplore's opening-file window instead.
8689" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8690" exe g:netrw_chgwin."wincmd w"
8691 wincmd p
8692 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8693 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008694
8695 " prevwinnr: the window number of the "prev" window
8696 " prevbufnr: the buffer number of the buffer in the "prev" window
8697 " bnrcnt : the qty of windows open on the "prev" buffer
8698 let prevwinnr = winnr()
8699 let prevbufnr = bufnr("%")
8700 let prevbufname = bufname("%")
8701 let prevmod = &mod
8702 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008703" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008704 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008705" 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 +01008706" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008707
8708 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709 " and it doesn't appear in any other extant window, then ask the
8710 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008711 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008712" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008713 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008714" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008715 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008716" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008717
8718 if bnrcnt == 1 && &hidden == 0
8719 " only one copy of the modified buffer in a window, and
8720 " hidden not set, so overwriting will lose the modified file. Ask first...
8721 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008722" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008724" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725
8726 if choice == 1
8727 " Yes -- write file & then browse
8728 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008729 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008731 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008732 exe origwin."wincmd w"
8733 let &ei = eikeep
8734 let @@ = ykeep
8735" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008736 return choice
8737 endif
8738
8739 elseif choice == 2
8740 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008741" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008742 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008743
8744 else
8745 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008746" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008747 exe origwin."wincmd w"
8748 let &ei= eikeep
8749 let @@ = ykeep
8750" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008751 return choice
8752 endif
8753 endif
8754 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008755 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008756 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008757" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008758
8759 " restore b:netrw_curdir (window split/enew may have lost it)
8760 let b:netrw_curdir= curdir
8761 if a:islocal < 2
8762 if a:islocal
8763 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8764 else
8765 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8766 endif
8767 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008768 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008769" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770 return choice
8771endfun
8772
8773" ---------------------------------------------------------------------
8774" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8775" Always assumed to be local -> remote
8776" call s:NetrwUpload(filename, target)
8777" call s:NetrwUpload(filename, target, fromdirectory)
8778fun! s:NetrwUpload(fname,tgt,...)
8779" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8780
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008781 if a:tgt =~ '^\a\{3,}://'
8782 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008783 else
8784 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8785 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008787
8788 if a:0 > 0
8789 let fromdir= a:1
8790 else
8791 let fromdir= getcwd()
8792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008793" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008794
8795 if type(a:fname) == 1
8796 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008797" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008798 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8800 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8801" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802 if a:tgt =~ '/$'
8803 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008804" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008805 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008808 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008809" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 endif
8811 q!
8812
8813 elseif type(a:fname) == 3
8814 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008816 let curdir= getcwd()
8817 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008818 if s:NetrwLcd(fromdir)
8819" call Dret("s:NetrwUpload : lcd failure")
8820 return
8821 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008822 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824 if exists("g:netrw_port") && g:netrw_port != ""
8825 let useport= " ".g:netrw_scpport." ".g:netrw_port
8826 else
8827 let useport= ""
8828 endif
8829 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8830 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831 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 +02008832 if s:NetrwLcd(curdir)
8833" call Dret("s:NetrwUpload : lcd failure")
8834 return
8835 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836
8837 elseif a:tgt =~ '^ftp:'
8838 call s:NetrwMethod(a:tgt)
8839
8840 if b:netrw_method == 2
8841 " handle uploading a list of files via ftp+.netrc
8842 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008843 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008844" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008846 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008847" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008848
8849 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008850 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008851" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852 endif
8853
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008854 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008855" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856
Bram Moolenaaradc21822011-04-01 18:03:16 +02008857 if tgtdir == ""
8858 let tgtdir= '/'
8859 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008860 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008861" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008862
8863 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008864 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8865" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 endfor
8867
8868 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008869 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 +00008870 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008871" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8872 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008873 endif
8874 " 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 +01008875 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008876 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008877 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8878 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8879 else
8880 bw!|q
8881 endif
8882
8883 elseif b:netrw_method == 3
8884 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8885 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008887 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008888 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008889
8890 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008891 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008892" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008894 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008895" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008896 endif
8897
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008898 if exists("g:netrw_uid") && g:netrw_uid != ""
8899 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008902 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008903 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008905" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008906 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008907 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008908" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008909 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008910 endif
8911
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008912 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008913" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008914
8915 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008916 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008917" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008918 endif
8919
8920 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008921 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008922" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 endif
8924
8925 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008926 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008927" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008928 endfor
8929
8930 " perform ftp:
8931 " -i : turns off interactive prompting from ftp
8932 " -n unix : DON'T use <.netrc>, even though it exists
8933 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008934 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008935 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008936 " 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 +01008937 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008938 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008939 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8940 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008941 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008942 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8943 let &debug = debugkeep
8944 let mod = 1
8945 else
8946 bw!|q
8947 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008948 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008949" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008950 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008951 endif
8952 else
8953 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8954 endif
8955 endif
8956
8957" call Dret("s:NetrwUpload")
8958endfun
8959
8960" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008961" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962fun! s:NetrwPreview(path) range
8963" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008964" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8965" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008966 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008967 NetrwKeepj call s:NetrwOptionsSave("s:")
8968 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8969 NetrwKeepj call s:NetrwOptionsSafe(1)
8970 else
8971 NetrwKeepj call s:NetrwOptionsSafe(0)
8972 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008973 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008974" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008975 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008976" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8977 if g:netrw_preview
8978 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008979 let pvhkeep = &pvh
8980 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8981 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008982" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8983 else
8984 " horizontal split
8985 let pvhkeep = &pvh
8986 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8987 let &pvh = winheight(0) - winsz
8988" 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 +02008989 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008990 " g:netrw_preview g:netrw_alto
8991 " 1 : vert 1: top -- preview window is vertically split off and on the left
8992 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8993 " 0 : 1: top -- preview window is horizontally split off and on the top
8994 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8995 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008996 " 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 +02008997 " the BufEnter event set up in netrwPlugin.vim
8998" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8999 let eikeep = &ei
9000 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009001 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009002 let &ei= eikeep
9003" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009004 if exists("pvhkeep")
9005 let &pvh= pvhkeep
9006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009007 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009008 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009009 endif
9010 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009011 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 +00009012 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009013 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009014 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009015" call Dret("NetrwPreview")
9016endfun
9017
9018" ---------------------------------------------------------------------
9019" s:NetrwRefresh: {{{2
9020fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009021" 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 +00009022 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009023 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009024" call Decho("setl ma noro",'~'.expand("<slnum>"))
9025" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009026 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009027 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9028 if !exists("w:netrw_treetop")
9029 if exists("b:netrw_curdir")
9030 let w:netrw_treetop= b:netrw_curdir
9031 else
9032 let w:netrw_treetop= getcwd()
9033 endif
9034 endif
9035 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9036 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009037
9038 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009039 let screenposn = winsaveview()
9040" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009041
9042" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9043" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9044 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009045 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009046 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009047 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009048 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009049 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009050
9051 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009052" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9053 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054
9055 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009056 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9057 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9058" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9059 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9060 else
9061" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9062 2match none
9063 endif
9064 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065
Bram Moolenaar97d62492012-11-15 21:28:22 +01009066" restore
9067 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009068" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009069endfun
9070
9071" ---------------------------------------------------------------------
9072" s:NetrwRefreshDir: refreshes a directory by name {{{2
9073" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009074" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009076" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077 if g:netrw_fastbrowse == 0
9078 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009079" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009080 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009081" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009082
9083 if tgtwin > 0
9084 " tgtwin is being displayed, so refresh it
9085 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009086" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009087 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009088 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009089 exe curwin."wincmd w"
9090
9091 elseif bufnr(a:dirname) > 0
9092 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009093" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9094 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009095 endif
9096
9097 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009098" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009100 endif
9101" call Dret("s:NetrwRefreshDir")
9102endfun
9103
9104" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009105" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9106" window number to do its editing in.
9107" Supports [count]C where the count, if present, is used to specify
9108" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009109fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009110" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009111 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009112" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009113 if a:1 == "" " :NetrwC win#
9114 let g:netrw_chgwin= winnr()
9115 else " :NetrwC
9116 let g:netrw_chgwin= a:1
9117 endif
9118 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009119 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009120 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009121 let g:netrw_chgwin= winnr()
9122 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009123 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009124" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009125endfun
9126
9127" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009128" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9129" What this function does is to compute a priority for the patterns
9130" in the g:netrw_sort_sequence. It applies a substitute to any
9131" "files" that satisfy each pattern, putting the priority / in
9132" front. An "*" pattern handles the default priority.
9133fun! s:NetrwSetSort()
9134" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009135 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136 if w:netrw_liststyle == s:LONGLIST
9137 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9138 else
9139 let seqlist = g:netrw_sort_sequence
9140 endif
9141 " sanity check -- insure that * appears somewhere
9142 if seqlist == ""
9143 let seqlist= '*'
9144 elseif seqlist !~ '\*'
9145 let seqlist= seqlist.',*'
9146 endif
9147 let priority = 1
9148 while seqlist != ""
9149 if seqlist =~ ','
9150 let seq = substitute(seqlist,',.*$','','e')
9151 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9152 else
9153 let seq = seqlist
9154 let seqlist = ""
9155 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009156 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009157 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009158 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009159 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009160 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009161 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009162 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009163" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164
9165 " sanity check
9166 if w:netrw_bannercnt > line("$")
9167 " apparently no files were left after a Hiding pattern was used
9168" call Dret("SetSort : no files left after hiding")
9169 return
9170 endif
9171 if seq == '*'
9172 let starpriority= spriority
9173 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009174 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009175 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009176 " sometimes multiple sorting patterns will match the same file or directory.
9177 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009178 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9179 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009180 endif
9181 let priority = priority + 1
9182 endwhile
9183 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009184 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9185 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009186 endif
9187
9188 " Following line associated with priority -- items that satisfy a priority
9189 " pattern get prefixed by ###/ which permits easy sorting by priority.
9190 " Sometimes files can satisfy multiple priority patterns -- only the latest
9191 " priority pattern needs to be retained. So, at this point, these excess
9192 " priority prefixes need to be removed, but not directories that happen to
9193 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009194 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9195 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009196 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009197
9198" call Dret("SetSort")
9199endfun
9200
Bram Moolenaarff034192013-04-24 18:51:19 +02009201" ---------------------------------------------------------------------
9202" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9203" Implements [count]Tb (bookhist<b>)
9204" [count]Th (bookhist<h>)
9205" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009206fun! s:NetrwSetTgt(islocal,bookhist,choice)
9207" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009208
9209 if a:bookhist == 'b'
9210 " supports choosing a bookmark as a target using a qb-generated list
9211 let choice= a:choice - 1
9212 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009213 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009214 else
9215 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9216 endif
9217
9218 elseif a:bookhist == 'h'
9219 " supports choosing a history stack entry as a target using a qb-generated list
9220 let choice= (a:choice % g:netrw_dirhistmax) + 1
9221 if exists("g:netrw_dirhist_".choice)
9222 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009223 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009224 else
9225 echomsg "Sorry, history#".a:choice." not available!"
9226 endif
9227 endif
9228
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009229 " refresh the display
9230 if !exists("b:netrw_curdir")
9231 let b:netrw_curdir= getcwd()
9232 endif
9233 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9234
Bram Moolenaarff034192013-04-24 18:51:19 +02009235" call Dret("s:NetrwSetTgt")
9236endfun
9237
Bram Moolenaar446cb832008-06-24 21:56:24 +00009238" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009239" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009240fun! s:NetrwSortStyle(islocal)
9241" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009242 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009243 let svpos= winsaveview()
9244" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009245
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009246 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 +01009247 NetrwKeepj norm! 0
9248 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009249" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9250 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251
9252" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9253endfun
9254
9255" ---------------------------------------------------------------------
9256" s:NetrwSplit: mode {{{2
9257" =0 : net and o
9258" =1 : net and t
9259" =2 : net and v
9260" =3 : local and o
9261" =4 : local and t
9262" =5 : local and v
9263fun! s:NetrwSplit(mode)
9264" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9265
Bram Moolenaar97d62492012-11-15 21:28:22 +01009266 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 call s:SaveWinVars()
9268
9269 if a:mode == 0
9270 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009271 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009272 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009274 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009276 NetrwKeepj call s:RestoreWinVars()
9277 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 unlet s:didsplit
9279
9280 elseif a:mode == 1
9281 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009282 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009283" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 tabnew
9285 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009286 NetrwKeepj call s:RestoreWinVars()
9287 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009288 unlet s:didsplit
9289
9290 elseif a:mode == 2
9291 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009292 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009293 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009294" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009295 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009296 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009297 NetrwKeepj call s:RestoreWinVars()
9298 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009299 unlet s:didsplit
9300
9301 elseif a:mode == 3
9302 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009303 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009304 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009305" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009306 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009307 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009308 NetrwKeepj call s:RestoreWinVars()
9309 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009310 unlet s:didsplit
9311
9312 elseif a:mode == 4
9313 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009314 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009315 let eikeep = &ei
9316 let netrw_winnr = winnr()
9317 let netrw_line = line(".")
9318 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009319 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009320 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009321 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009322 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9323 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009324 let &ei = eikeep
9325 let netrw_curdir = s:NetrwTreeDir(0)
9326" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009327 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009328 let b:netrw_curdir = netrw_curdir
9329 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009330 NetrwKeepj call s:RestoreWinVars()
9331 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009332 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009333 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009334 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9335 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009336 let &ei= eikeep
9337 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009338 unlet s:didsplit
9339
9340 elseif a:mode == 5
9341 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009342 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009343 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009344" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009345 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009346 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009347 NetrwKeepj call s:RestoreWinVars()
9348 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009349 unlet s:didsplit
9350
9351 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009352 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009353 endif
9354
Bram Moolenaar97d62492012-11-15 21:28:22 +01009355 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009356" call Dret("s:NetrwSplit")
9357endfun
9358
9359" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009360" s:NetrwTgtMenu: {{{2
9361fun! s:NetrwTgtMenu()
9362 if !exists("s:netrw_menucnt")
9363 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009364 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009365" call Dfunc("s:NetrwTgtMenu()")
9366
9367 " the following test assures that gvim is running, has menus available, and has menus enabled.
9368 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9369 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009370" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009371 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9372 endif
9373 if !exists("s:netrw_initbookhist")
9374 call s:NetrwBookHistRead()
9375 endif
9376
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009377 " try to cull duplicate entries
9378 let tgtdict={}
9379
Bram Moolenaarff034192013-04-24 18:51:19 +02009380 " target bookmarked places
9381 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009383 let cnt= 1
9384 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385 if has_key(tgtdict,bmd)
9386 let cnt= cnt + 1
9387 continue
9388 endif
9389 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009390 let ebmd= escape(bmd,g:netrw_menu_escape)
9391 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009392" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009393 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 +02009394 let cnt= cnt + 1
9395 endfor
9396 endif
9397
9398 " target directory browsing history
9399 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009400" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009401 let histcnt = 1
9402 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009403 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009404 if exists("g:netrw_dirhist_{histcnt}")
9405 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009406 if has_key(tgtdict,histentry)
9407 let histcnt = histcnt + 1
9408 continue
9409 endif
9410 let tgtdict[histentry] = histcnt
9411 let ehistentry = escape(histentry,g:netrw_menu_escape)
9412" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009413 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 +02009414 endif
9415 let histcnt = histcnt + 1
9416 endwhile
9417 endif
9418 endif
9419" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009420endfun
9421
9422" ---------------------------------------------------------------------
9423" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9424" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009425fun! s:NetrwTreeDir(islocal)
9426" 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 +02009427" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009428" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9429" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9430" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009431" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009433 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009434 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009435" 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 +01009436 let treedir= s:treedir
9437 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009438 unlet s:prevwinopen
9439" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009440 return treedir
9441 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009442 if exists("s:prevwinopen")
9443 unlet s:prevwinopen
9444 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009445" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009446
Bram Moolenaar8d043172014-01-23 14:24:41 +01009447 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9448 let b:netrw_curdir= getcwd()
9449 endif
9450 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009452" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009453
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009454 let s:treecurpos= winsaveview()
9455" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009456" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009457
9458 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9460" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009461" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009462
9463 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009464 let curline= substitute(getline('.'),"\t -->.*$",'','')
9465 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009466" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009467 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009468" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9469 elseif curline =~ '@$'
9470" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9471 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9472" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009475 let treedir= ""
9476 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009477" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009478
9479 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009480" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9481" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009482" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009483 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009484" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009485 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009486" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9487 sil! NetrwKeepj %d _
9488" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009489 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009490" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009491" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009492 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009493" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009494
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009495" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009496 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9497" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009498" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009499
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009500 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9501" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9502" let newdir = w:netrw_treetop.'/'.potentialdir
9503" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9504" let treedir = s:NetrwTreePath(newdir)
9505" let w:netrw_treetop = newdir
9506" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9507" else
9508" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009509 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009510" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009511 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009512" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009513
9514 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009517" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009518
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009519" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009520 return treedir
9521endfun
9522
9523" ---------------------------------------------------------------------
9524" s:NetrwTreeDisplay: recursive tree display {{{2
9525fun! s:NetrwTreeDisplay(dir,depth)
9526" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9527
9528 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009529 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009530
9531 " install ../ and shortdir
9532 if a:depth == ""
9533 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009534" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009536 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009537 if a:dir == w:netrw_treetop
9538 let shortdir= a:dir
9539 else
9540 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9541 endif
9542 call setline(line("$")+1,a:depth.shortdir)
9543 else
9544 let shortdir= substitute(a:dir,'^.*/','','e')
9545 call setline(line("$")+1,a:depth.shortdir.'/')
9546 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009547" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009548 " append a / to dir if its missing one
9549 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009550
9551 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009552 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009553" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009554
Bram Moolenaar85850f32019-07-19 22:05:51 +02009555 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9556 if g:netrw_hide == 1
9557 " hide given patterns
9558 let listhide= split(g:netrw_list_hide,',')
9559" call Decho("listhide=".string(listhide))
9560 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009561 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009562 endfor
9563
9564 elseif g:netrw_hide == 2
9565 " show given patterns (only)
9566 let listhide= split(g:netrw_list_hide,',')
9567" call Decho("listhide=".string(listhide))
9568 let entries=[]
9569 for entry in w:netrw_treedict[dir]
9570 for pat in listhide
9571 if entry =~ pat
9572 call add(entries,entry)
9573 break
9574 endif
9575 endfor
9576 endfor
9577 let w:netrw_treedict[dir]= entries
9578 endif
9579 if depth != ""
9580 " always remove "." and ".." entries when there's depth
9581 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9582 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9583 endif
9584
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009585" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009586 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009587 if dir =~ '/$'
9588 let direntry= substitute(dir.entry,'[@/]$','','e')
9589 else
9590 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9591 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009592" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009593 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009594" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009595 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009596 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009597" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9598 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9599 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9600" 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 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009603" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009604 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009605 endif
9606 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009607" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009608
Bram Moolenaar446cb832008-06-24 21:56:24 +00009609" call Dret("NetrwTreeDisplay")
9610endfun
9611
9612" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009613" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9614fun! s:NetrwRefreshTreeDict(dir)
9615" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009616 if !exists("w:netrw_treedict")
9617" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9618 return
9619 endif
9620
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009621 for entry in w:netrw_treedict[a:dir]
9622 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9623" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9624
9625 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9626" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9627 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009628 let liststar = s:NetrwGlob(direntry,'*',1)
9629 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009630 let w:netrw_treedict[direntry] = liststar + listdotstar
9631" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9632
9633 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9634" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9635 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009636 let liststar = s:NetrwGlob(direntry.'/','*',1)
9637 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009638 let w:netrw_treedict[direntry]= liststar + listdotstar
9639" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9640
9641 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9642" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9643 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009644 let liststar = s:NetrwGlob(direntry.'/','*',1)
9645 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009646" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9647
9648 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009649" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009650 endif
9651 endfor
9652" call Dret("s:NetrwRefreshTreeDict")
9653endfun
9654
9655" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009657" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009659 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009660" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009661" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9662" 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>"))
9663" 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 +00009664
9665 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009667" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009669 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009670" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009671 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 +02009672" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009673 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009674 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009675" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009676 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009677 if exists("w:netrw_treetop")
9678 let s:netrw_treetop= w:netrw_treetop
9679 else
9680 let w:netrw_treetop= getcwd()
9681 let s:netrw_treetop= w:netrw_treetop
9682 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009683
Bram Moolenaar446cb832008-06-24 21:56:24 +00009684 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009685 " insure that we have a treedict, albeit empty
9686" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009687 let w:netrw_treedict= {}
9688 endif
9689
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009690 " update the dictionary for the current directory
9691" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009692" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009693 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009694 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009695" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009696 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009697
9698 " if past banner, record word
9699 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9700 let fname= expand("<cword>")
9701 else
9702 let fname= ""
9703 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009704" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9705" 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 +00009706
9707 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009708" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009709 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009710" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009711
9712 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9713 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009714" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009715 1d
9716 endwhile
9717
Bram Moolenaar13600302014-05-22 18:26:40 +02009718 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009719
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009720" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009721 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009722 endif
9723endfun
9724
9725" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009726" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009727" Normally, treetop is w:netrw_treetop, but a
9728" user of the function ( netrw#SetTreetop() )
9729" wipes that out prior to calling this function
9730fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009731" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9732 if line(".") < w:netrw_bannercnt + 2
9733 let treedir= a:treetop
9734 if treedir !~ '/$'
9735 let treedir= treedir.'/'
9736 endif
9737" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9738 return treedir
9739 endif
9740
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009741 let svpos = winsaveview()
9742" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009743 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009745 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009746" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9747 let curline= getline('.')
9748" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9749 if curline =~ '/$'
9750" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9751 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9752" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9753 elseif curline =~ '@\s\+-->'
9754" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9755 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9756 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9757" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009758 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009759" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009760 let treedir= ""
9761 endif
9762 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009763" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9764" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009765 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9766 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9767 let treedir= dirname.treedir
9768 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009769" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009770 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009771" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009772 if a:treetop =~ '/$'
9773 let treedir= a:treetop.treedir
9774 else
9775 let treedir= a:treetop.'/'.treedir
9776 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009777" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009778 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009779" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009780" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9781 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009782" call Dret("s:NetrwTreePath <".treedir.">")
9783 return treedir
9784endfun
9785
9786" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009787" s:NetrwWideListing: {{{2
9788fun! s:NetrwWideListing()
9789
9790 if w:netrw_liststyle == s:WIDELIST
9791" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9792 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009793 " cpf: characters per filename
9794 " fpl: filenames per line
9795 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009796 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009797 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009798" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009799 let b:netrw_cpf= 0
9800 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009801 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009802 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9803 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009805 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009806" call Dret("NetrwWideListing")
9807 return
9808 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009809 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009810 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009811" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812
9813 " determine qty files per line (fpl)
9814 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9815 if w:netrw_fpl <= 0
9816 let w:netrw_fpl= 1
9817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009818" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009819
9820 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009821 " fpc: files per column of wide listing
9822 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009823 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009824 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9825 let newcolstart = w:netrw_bannercnt + fpc
9826 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009827" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009828 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009829" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009830 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009831 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009832 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009833 while line("$") >= newcolstart
9834 if newcolend > line("$") | let newcolend= line("$") | endif
9835 let newcolqty= newcolend - newcolstart
9836 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009837 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009838 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009839 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009840 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009841 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009843 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009844 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009846 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009847" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009848 if @* != keepregstar | sil! let @* = keepregstar | endif
9849 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009850 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009851 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9852 NetrwKeepj call histdel("/",-1)
9853 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9854 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009855" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009856 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009857 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009858" 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 +00009859" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009860 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009861 else
9862 if hasmapto("w","n")
9863 sil! nunmap <buffer> w
9864 endif
9865 if hasmapto("b","n")
9866 sil! nunmap <buffer> b
9867 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868 endif
9869
9870endfun
9871
9872" ---------------------------------------------------------------------
9873" s:PerformListing: {{{2
9874fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009875" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9876" 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 +02009877" 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>"))
9878 sil! NetrwKeepj %d _
9879" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009880
Bram Moolenaar15146672011-10-20 22:22:38 +02009881 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009883 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009884
Bram Moolenaar85850f32019-07-19 22:05:51 +02009885 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009886 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009888
9889" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009890" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009891" endif " Decho
9892
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009894 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9895 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009896" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9897 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898 endif
9899
9900 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009901 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009902
9903 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009904 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009905" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009906 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009907 if exists("g:netrw_pchk")
9908 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9909 " failure detections.
9910 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009911 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009912 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9913 endif
9914 if exists("g:netrw_pchk")
9915 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9916 else
9917 let curdir= b:netrw_curdir
9918 endif
9919 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9920 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9921 else
9922 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009923 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009924 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009925 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009926 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009927" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009928 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009929 let w:netrw_bannercnt= 1
9930 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009931" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9932" 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 +00009933
Bram Moolenaar85850f32019-07-19 22:05:51 +02009934 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009935 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009936 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009937 let sortby= sortby." reversed"
9938 endif
9939
9940 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009942" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009943 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009944" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009945 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009946 NetrwKeepj put ='\" Sorted by '.sortby
9947 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009948 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9949 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009950" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009951 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009952 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009953 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9954 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009955 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009956" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009957" 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 +00009958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009959
Bram Moolenaar85850f32019-07-19 22:05:51 +02009960 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009961 if g:netrw_banner
9962 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009964 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009965 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009966 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009967 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009968 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009969 endif
9970 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009971 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009972" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009973 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009974 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009976
9977 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009978 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009979" 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 +01009980 if g:netrw_list_hide != "" && g:netrw_hide
9981 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009982 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009983 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009985 endif
9986 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009987 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009988 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009989
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009990" 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 +01009991 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009992" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009993 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009994" 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 +01009995 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009996 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009997" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" 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 +00009999 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000
10001 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010002 if g:netrw_banner
10003 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010004 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010005" 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 +010010006" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010007" 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 +010010008 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010013 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010014 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010015 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010016 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010017" 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 +010010018" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10019 return
10020 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010021 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010022
10023 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010024 if !exists("w:netrw_bannercnt")
10025 let w:netrw_bannercnt= 0
10026 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010027" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10028" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10029" 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 +010010030
Bram Moolenaar5c736222010-01-06 20:54:52 +010010031 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010032" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033" 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 +000010034 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010035 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010036 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010037 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010038" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010039
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010040 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010042" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010043 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044
Bram Moolenaar5c736222010-01-06 20:54:52 +010010045 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010046" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010047 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010048 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050 else
10051 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010052 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010053 endif
10054 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010055
Bram Moolenaar446cb832008-06-24 21:56:24 +000010056 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010057" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010058 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10059 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010060
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010061 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010062 " exten: sort by extension
10063 " The histdel(...,-1) calls remove the last search from the search history
10064" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010065 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10066 NetrwKeepj call histdel("/",-1)
10067 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10068 NetrwKeepj call histdel("/",-1)
10069 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10070 NetrwKeepj call histdel("/",-1)
10071 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10072" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010073 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010074 " normal direction sorting
10075 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10076 else
10077 " reverse direction sorting
10078 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10079 endif
10080 endif
10081 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10082 NetrwKeepj call histdel("/",-1)
10083
Bram Moolenaar446cb832008-06-24 21:56:24 +000010084 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010085 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010086" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010087 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010088" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010089 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010090 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010091" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010092 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010093 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010094" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010095 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10096 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010097 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010098 endif
10099
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010100 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010101" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010102 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010103 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010104 call histdel("/",-1)
10105 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010106 endif
10107 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010108" 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 +000010109
10110 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10112" 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 +010010113 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" 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 +010010115 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116" 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 +000010117
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010118 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010119 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010121 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010122 endif
10123
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010125 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10127 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010128 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010129" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10130 else
10131" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10132" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10133" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10134" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010135 endif
10136
10137 " record previous current directory
10138 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010139" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010140
10141 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10143" 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 +010010144 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" 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 +020010146 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" 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 +000010148
10149 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010151 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" 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 +010010153 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010154" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010155 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10156 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010157" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010158" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010159
Bram Moolenaar8d043172014-01-23 14:24:41 +010010160 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010161" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10162" 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 +010010163" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10164 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010165 unlet s:treecurpos
10166 endif
10167
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" 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>"))
10169" 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 +000010170" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10171endfun
10172
10173" ---------------------------------------------------------------------
10174" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010175fun! s:SetupNetrwStatusLine(statline)
10176" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10177
10178 if !exists("s:netrw_setup_statline")
10179 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010180" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010181
10182 if !exists("s:netrw_users_stl")
10183 let s:netrw_users_stl= &stl
10184 endif
10185 if !exists("s:netrw_users_ls")
10186 let s:netrw_users_ls= &laststatus
10187 endif
10188
10189 " set up User9 highlighting as needed
10190 let keepa= @a
10191 redir @a
10192 try
10193 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010194 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010195 if &bg == "dark"
10196 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10197 else
10198 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10199 endif
10200 endtry
10201 redir END
10202 let @a= keepa
10203 endif
10204
10205 " set up status line (may use User9 highlighting)
10206 " insure that windows have a statusline
10207 " make sure statusline is displayed
10208 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010209 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010210" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010211 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010212
10213" call Dret("SetupNetrwStatusLine : stl=".&stl)
10214endfun
10215
Bram Moolenaar85850f32019-07-19 22:05:51 +020010216" =========================================
10217" Remote Directory Browsing Support: {{{1
10218" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010219
10220" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010221" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10222" This function assumes that a long listing will be received. Size, time,
10223" and reverse sorts will be requested of the server but not otherwise
10224" enforced here.
10225fun! s:NetrwRemoteFtpCmd(path,listcmd)
10226" 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 +010010227" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010228 " sanity check: {{{3
10229 if !exists("w:netrw_method")
10230 if exists("b:netrw_method")
10231 let w:netrw_method= b:netrw_method
10232 else
10233 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10234" call Dret("NetrwRemoteFtpCmd")
10235 return
10236 endif
10237 endif
10238
10239 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10240 let ffkeep= &ff
10241 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010242" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010243
10244 " clear off any older non-banner lines " {{{3
10245 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010246" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10247 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010248
10249 ".........................................
10250 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10251 " ftp + <.netrc>: Method #2
10252 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010253 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010254 endif
10255 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010256 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010257" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010258 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010259 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010260" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010261 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010262" 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>"))
10263 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 +010010264 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010265" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10266 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 +010010267 endif
10268
10269 ".........................................
10270 elseif w:netrw_method == 3 " {{{3
10271 " ftp + machine,id,passwd,filename: Method #3
10272 setl ff=unix
10273 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010274 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010276 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010277 endif
10278
10279 " handle userid and password
10280 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010281" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10283 call NetUserPass("ftp:".host)
10284 endif
10285 if exists("g:netrw_uid") && g:netrw_uid != ""
10286 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010287 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010288 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 endif
10291 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010293 endif
10294 endif
10295
10296 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010297 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010298 endif
10299 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010300 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010301" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010302 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010304
10305 " perform ftp:
10306 " -i : turns off interactive prompting from ftp
10307 " -n unix : DON'T use <.netrc>, even though it exists
10308 " -n win32: quit being obnoxious about password
10309 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010310" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010311 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010312" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010313" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10314" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010315 endif
10316
10317 ".........................................
10318 elseif w:netrw_method == 9 " {{{3
10319 " sftp username@machine: Method #9
10320 " s:netrw_sftp_cmd
10321 setl ff=unix
10322
10323 " restore settings
10324 let &ff= ffkeep
10325" call Dret("NetrwRemoteFtpCmd")
10326 return
10327
10328 ".........................................
10329 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010330 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010331 endif
10332
10333 " cleanup for Windows " {{{3
10334 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010335 sil! NetrwKeepj %s/\r$//e
10336 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010337 endif
10338 if a:listcmd == "dir"
10339 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010340 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10341 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10342 NetrwKeepj call histdel("/",-1)
10343 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010344 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 +010010345 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10346 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010347 endif
10348 endif
10349
10350 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10351 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010352 exe 'NetrwKeepj '.w:netrw_bannercnt
10353 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010354 endif
10355 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010356 exe 'NetrwKeepj '.w:netrw_bannercnt
10357 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010358 endif
10359
10360 " restore settings " {{{3
10361 let &ff= ffkeep
10362" call Dret("NetrwRemoteFtpCmd")
10363endfun
10364
10365" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010366" s:NetrwRemoteListing: {{{2
10367fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010368" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010369
Bram Moolenaara6878372014-03-22 21:02:50 +010010370 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10371 let w:netrw_bannercnt= s:bannercnt
10372 endif
10373 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10374 let w:netrw_bannercnt= s:bannercnt
10375 endif
10376
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010378
Bram Moolenaar446cb832008-06-24 21:56:24 +000010379 " sanity check:
10380 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010381" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010383" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010384 if !exists("g:netrw_quiet")
10385 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10386 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010387 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010388" call Dret("s:NetrwRemoteListing -1")
10389 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010390 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010391
Bram Moolenaar8d043172014-01-23 14:24:41 +010010392 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010393" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010394 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010395 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010396 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 +000010397 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010398 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 +000010399 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010400 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010401
Bram Moolenaar85850f32019-07-19 22:05:51 +020010402 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010403" call Dret("s:NetrwRemoteListing -1")
10404 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010405 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010406" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010407
Bram Moolenaar446cb832008-06-24 21:56:24 +000010408 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010409" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010410 let w:netrw_method= b:netrw_method
10411 endif
10412
Bram Moolenaar13600302014-05-22 18:26:40 +020010413 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010414 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010416 let s:method = "ftp"
10417 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010418 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010419 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010420 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010421 let listcmd= g:netrw_ftp_sizelist_cmd
10422 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010423" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010424 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010425" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426
Bram Moolenaara6878372014-03-22 21:02:50 +010010427 " report on missing file or directory messages
10428 if search('[Nn]o such file or directory\|Failed to change directory')
10429 let mesg= getline(".")
10430 if exists("w:netrw_bannercnt")
10431 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010432 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010433 setl noma
10434 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010435 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010436 call netrw#ErrorMsg(s:WARNING,mesg,96)
10437" call Dret("s:NetrwRemoteListing : -1")
10438 return -1
10439 endif
10440
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010441 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 +000010442 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010443" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010444 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445
10446 " cleanup
10447 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010448 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10449 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010450 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010451 sil! NetrwKeepj %s/\r$//e
10452 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010453
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010454 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010455 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010456 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010457 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010461 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010462 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010463 exe "sil! NetrwKeepj ".line1
10464 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010466" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010468" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010469 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10470 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010472" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010473 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10474 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10475 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10476 NetrwKeepj call histdel("/",-1)
10477 NetrwKeepj call histdel("/",-1)
10478 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 endif
10480 endif
10481
Bram Moolenaar13600302014-05-22 18:26:40 +020010482 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010484" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010486" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010488" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10489 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010490 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010491 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10492 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10493 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10494 NetrwKeepj call histdel("/",-1)
10495 NetrwKeepj call histdel("/",-1)
10496 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010498 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10499 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010500 endif
10501 else
10502 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010503" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010504 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010506" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10507 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10508" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509 endif
10510 endif
10511
10512 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010513 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010514" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010515 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10516 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010517 endif
10518 endif
10519
10520 if w:netrw_liststyle == s:LONGLIST
10521 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010522" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523
10524 if s:method == "ftp"
10525 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010526 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010527 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010528 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010530 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010532 sil! NetrwKeepj 1
10533 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 let line2= line(".")
10535 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010537 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010538 endif
10539 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010540 exe "sil! NetrwKeepj ".line1
10541 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542 endif
10543
10544 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010545" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010546 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 +000010547 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010548" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010549 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010550 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010551 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10552 NetrwKeepj call histdel("/",-1)
10553 NetrwKeepj call histdel("/",-1)
10554 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555 endif
10556 endif
10557
10558" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010561
10562" call Dret("s:NetrwRemoteListing 0")
10563 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010564endfun
10565
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566" ---------------------------------------------------------------------
10567" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10568fun! s:NetrwRemoteRm(usrhost,path) range
10569" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010570" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010571 let svpos= winsaveview()
10572" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573
10574 let all= 0
10575 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10576 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010577" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578 for fname in s:netrwmarkfilelist_{bufnr("%")}
10579 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010580 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010582 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583 let all= 1
10584 endif
10585 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010586 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587
10588 else
10589 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010590" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010591
10592 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010593 let keepsol = &l:sol
10594 setl nosol
10595 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596
10597 " remove multiple files and directories
10598 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010599 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010601 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010603 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010604 let all= 1
10605 endif
10606 let ctr= ctr + 1
10607 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010608 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010609 endif
10610
10611 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010612" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010613 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010614" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10615 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616
10617" call Dret("s:NetrwRemoteRm")
10618endfun
10619
10620" ---------------------------------------------------------------------
10621" s:NetrwRemoteRmFile: {{{2
10622fun! s:NetrwRemoteRmFile(path,rmfile,all)
10623" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10624
10625 let all= a:all
10626 let ok = ""
10627
10628 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10629 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010631 if !all
10632 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634 call inputsave()
10635 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10636 call inputrestore()
10637 echohl NONE
10638 if ok == ""
10639 let ok="no"
10640 endif
10641 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010642 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 let all= 1
10644 endif
10645 endif
10646
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010647 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010648" 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 +000010649 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010652 if path =~ '^\a\{3,}://'
10653 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010655 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010656 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10657 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010660" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010662 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010663 let ok="q"
10664 else
10665 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10667" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10668" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010670 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010671 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010673 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676 if v:shell_error != 0
10677 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010678 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 +010010679 else
10680 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10681 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010682 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010684 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010685" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010686 endif
10687 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010688 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010689" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010690 endif
10691
10692 else
10693 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010694" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010695 if !all
10696 call inputsave()
10697 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10698 call inputrestore()
10699 if ok == ""
10700 let ok="no"
10701 endif
10702 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010703 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010704 let all= 1
10705 endif
10706 endif
10707
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010708 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010710 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010711 else
10712 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010713 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10714" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010715 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010716" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010717
10718 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010719" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10720 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10721" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010722 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010723" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010724
10725 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010726 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010727 endif
10728 endif
10729 endif
10730
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010731 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010732" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010733 endif
10734 endif
10735
10736" call Dret("s:NetrwRemoteRmFile ".ok)
10737 return ok
10738endfun
10739
10740" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010741" s:NetrwRemoteRename: rename a remote file or directory {{{2
10742fun! s:NetrwRemoteRename(usrhost,path) range
10743" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10744
10745 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010746 let svpos = winsaveview()
10747" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010748 let ctr = a:firstline
10749 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10750
10751 " rename files given by the markfilelist
10752 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10753 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010754" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010755 if exists("subfrom")
10756 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010757" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010758 else
10759 call inputsave()
10760 let newname= input("Moving ".oldname." to : ",oldname)
10761 call inputrestore()
10762 if newname =~ '^s/'
10763 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10764 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10765 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010766" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010767 endif
10768 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010769
Bram Moolenaar446cb832008-06-24 21:56:24 +000010770 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010771 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010772 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010773 let oldname= s:ShellEscape(a:path.oldname)
10774 let newname= s:ShellEscape(a:path.newname)
10775" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010776 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010777 endif
10778
10779 endfor
10780 call s:NetrwUnMarkFile(1)
10781
10782 else
10783
10784 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010785 let keepsol= &l:sol
10786 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010787 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010788 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010789
10790 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010791" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010792
10793 call inputsave()
10794 let newname= input("Moving ".oldname." to : ",oldname)
10795 call inputrestore()
10796
10797 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10798 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10799 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010800 let oldname= s:ShellEscape(a:path.oldname)
10801 let newname= s:ShellEscape(a:path.newname)
10802" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010803 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010804 endif
10805
10806 let ctr= ctr + 1
10807 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010808 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010809 endif
10810
10811 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010812 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010813" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10814 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010815
10816" call Dret("NetrwRemoteRename")
10817endfun
10818
Bram Moolenaar85850f32019-07-19 22:05:51 +020010819" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010820" Local Directory Browsing Support: {{{1
10821" ==========================================
10822
10823" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010824" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010825" Should accept: file://localhost/etc/fstab
10826" file:///etc/fstab
10827" file:///c:/WINDOWS/clock.avi
10828" file:///c|/WINDOWS/clock.avi
10829" file://localhost/c:/WINDOWS/clock.avi
10830" file://localhost/c|/WINDOWS/clock.avi
10831" file://c:/foo.txt
10832" file:///c:/foo.txt
10833" 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 +020010834fun! netrw#FileUrlEdit(fname)
10835" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010836 let fname = a:fname
10837 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010839 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010841 endif
10842 if (has("win32") || has("win95") || has("win64") || has("win16"))
10843 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010844" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010845 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010847 endif
10848 endif
10849 let fname2396 = netrw#RFC2396(fname)
10850 let fname2396e= fnameescape(fname2396)
10851 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10852 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010853" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010854 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010856 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10857 endif
10858 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010859
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010860" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10861" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010862 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010863 exe 'NetrwKeepj keepalt edit '.plainfname
10864 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10865
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010866" 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 +020010867" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010868 exe "sil doau BufReadPost ".fname2396e
10869endfun
10870
10871" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010872" netrw#LocalBrowseCheck: {{{2
10873fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010874 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010875 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10876 "
10877 " unfortunate interaction -- split window debugging can't be used here, must use
10878 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10879 " another call to LocalBrowseCheck() when attempts to write
10880 " to the DBG buffer are made.
10881 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010882 " The &ft == "netrw" test was installed because the BufEnter event
10883 " would hit when re-entering netrw windows, creating unexpected
10884 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010885" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010886" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" 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 +010010888 " getting E930: Cannot use :redir inside execute
10889"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010890" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10891" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010892
Bram Moolenaar97d62492012-11-15 21:28:22 +010010893 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010894 if isdirectory(s:NetrwFile(a:dirname))
10895" 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 +010010896
Bram Moolenaar97d62492012-11-15 21:28:22 +010010897 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010898" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10899" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010900 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010901
Bram Moolenaar446cb832008-06-24 21:56:24 +000010902 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010904 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010905
Bram Moolenaar5c736222010-01-06 20:54:52 +010010906 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010907" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010908 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010909 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010911" 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 +010010912" call Dret("netrw#LocalBrowseCheck")
10913 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010914 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010915
Bram Moolenaar85850f32019-07-19 22:05:51 +020010916 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010917 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10918 " AND IF the listing style is not a tree listing
10919 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010920" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010921 let ibuf = 1
10922 let buflast = bufnr("$")
10923 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010924 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10925 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010926 endif
10927 let ibuf= ibuf + 1
10928 endwhile
10929 endif
10930 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010931" 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>"))
10932" 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 +000010933 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010934" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010935endfun
10936
10937" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010938" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939" performed any shell command. The idea is to cause all local-browsing
10940" buffers to be refreshed after a user has executed some shell command,
10941" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010942fun! s:LocalBrowseRefresh()
10943" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010944" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10945" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010946
Bram Moolenaar446cb832008-06-24 21:56:24 +000010947 " determine which buffers currently reside in a tab
10948 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010949" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010950 return
10951 endif
10952 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010953" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010954 return
10955 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010956 if exists("s:netrw_events") && s:netrw_events == 1
10957 " s:LocalFastBrowser gets called (indirectly) from a
10958 let s:netrw_events= 2
10959" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10960 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010961 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962 let itab = 1
10963 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010964 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010965 while itab <= tabpagenr("$")
10966 let buftablist = buftablist + tabpagebuflist()
10967 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010968 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010969 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010970" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10971" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010972 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10973 " | refresh any netrw window
10974 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010975 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010976 let ibl = 0
10977 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010978" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010979 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10980 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010981 " (ibuf not shown in a current window AND
10982 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010983" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10984 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010985 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010987 continue
10988 elseif index(tabpagebuflist(),ibuf) != -1
10989 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010990" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010992 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010993 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10994 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10995 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10996 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010998 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10999 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11000 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011001 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011002 endif
11003 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011004" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011005 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011006" call Decho("restore window: win_gotoid(".curwinid.")")
11007 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011008 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011009
Bram Moolenaara6878372014-03-22 21:02:50 +010011010" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011011endfun
11012
11013" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11015"
11016" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011018" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11019" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011020" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011021"
11022" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11023" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011024" (re-using a buffer may not be as accurate)
11025"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011026" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011027" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11028" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11029" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11030" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011031fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011032" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11033" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11034" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11035" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011036
11037 " initialize browselist, a list of buffer numbers that the local browser has used
11038 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011040 let s:netrw_browselist= []
11041 endif
11042
11043 " append current buffer to fastbrowse list
11044 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011045" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011046 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011047" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011048 endif
11049
11050 " enable autocmd events to handle refreshing/removing local browser buffers
11051 " If local browse buffer is currently showing: refresh it
11052 " If local browse buffer is currently hidden : wipe it
11053 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11054 " =1 : medium speed, re-use directory listing for remote only
11055 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011056 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11057 let s:netrw_events= 1
11058 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011059 au!
11060 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011061" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011062 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011063 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011064" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011065 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011066 endif
11067 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011068
11069 " user must have changed fastbrowse to its fast setting, so remove
11070 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011071 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011072" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011073 unlet s:netrw_events
11074 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011075 au!
11076 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011077 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011078 endif
11079
Bram Moolenaar85850f32019-07-19 22:05:51 +020011080" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011081endfun
11082
11083" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011084" s:LocalListing: does the job of "ls" for local directories {{{2
11085fun! s:LocalListing()
11086" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011087" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11088" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11089" 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 +010011090
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011091" 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
11092" 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
11093" 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 +010011094
11095 " get the list of files contained in the current directory
11096 let dirname = b:netrw_curdir
11097 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011098 let filelist = s:NetrwGlob(dirname,"*",0)
11099 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011100" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011101
11102 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011103" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011104 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11105 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011106" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011107 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011109 endif
11110
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011111" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011112" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011113" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011114
11115 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11116 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11117 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11119" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011120 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" 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 +010011122
11123 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho(" ",'~'.expand("<slnum>"))
11125" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126
11127 if getftype(filename) == "link"
11128 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011129" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011130 let pfile= filename."@"
11131
11132 elseif getftype(filename) == "socket"
11133 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011134" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011135 let pfile= filename."="
11136
11137 elseif getftype(filename) == "fifo"
11138 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011139" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011140 let pfile= filename."|"
11141
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011142 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011143 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011144" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011145 let pfile= filename."/"
11146
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011148 if (has("win32") || has("win95") || has("win64") || has("win16"))
11149 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11150 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011152 let pfile= filename."*"
11153 else
11154 " normal file
11155 let pfile= filename
11156 endif
11157 elseif executable(filename)
11158 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011159" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011160 let pfile= filename."*"
11161 else
11162 " normal file
11163 let pfile= filename
11164 endif
11165
11166 else
11167 " normal file
11168 let pfile= filename
11169 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011170" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011171
11172 if pfile =~ '//$'
11173 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011174" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011175 endif
11176 let pfile= strpart(pfile,dirnamelen)
11177 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011178" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11179" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011180
11181 if w:netrw_liststyle == s:LONGLIST
11182 let sz = getfsize(filename)
Bram Moolenaar71badf92023-04-22 22:40:14 +010011183 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11184 let szlen = (szlen > 0) ? szlen : 0
11185 let fsz = printf("%".szlen."S",sz)
11186
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011187 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011188 let sz= s:NetrwHumanReadable(sz)
11189 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +010011190 let longfile= printf("%-".g:netrw_maxfilenamelen."S",pfile)
11191 let pfile = longfile." ".sz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011192" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011193 endif
11194
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011195 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011196 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011197 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011198" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011199" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011200 let t = getftime(filename)
11201 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar91359012019-11-30 17:57:03 +010011202" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011203 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011204 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011205
11206 elseif g:netrw_sort_by =~ "^s"
11207 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011208" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011209" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011210 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011211 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011212 let sz= s:NetrwHumanReadable(sz)
11213 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011214 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011216 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011217 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011218
11219 else
11220 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011221" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011222" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011223 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011224 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011225" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011226 endfor
11227
11228 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011229 sil! NetrwKeepj g/^$/d
11230 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011231 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011232" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011233 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11234
11235" call Dret("s:LocalListing")
11236endfun
11237
11238" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011239" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11240fun! s:NetrwLocalExecute(cmd)
11241" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11242 let ykeep= @@
11243 " sanity check
11244 if !executable(a:cmd)
11245 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11246 let @@= ykeep
11247" call Dret("s:NetrwLocalExecute")
11248 return
11249 endif
11250
11251 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011252" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011253 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011254" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011255
11256 " strip any ansi escape sequences off
11257 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11258
11259 " show user the result(s)
11260 echomsg result
11261 let @@= ykeep
11262
11263" call Dret("s:NetrwLocalExecute")
11264endfun
11265
11266" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011267" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011268fun! s:NetrwLocalRename(path) range
11269" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11270
11271 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011272 let ykeep = @@
11273 let ctr = a:firstline
11274 let svpos = winsaveview()
11275 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011276" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011277
11278 " rename files given by the markfilelist
11279 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11280 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011281" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011282 if exists("subfrom")
11283 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011284" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011285 else
11286 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011287 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011288 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011289 if newname =~ ''
11290 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11291 let newname = substitute(newname,'^.*','','')
11292 elseif newname =~ ''
11293 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11294 let newname = substitute(newname,'[^/]*','','')
11295 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011296 if newname =~ '^s/'
11297 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11298 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011299" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011300 let newname = substitute(oldname,subfrom,subto,'')
11301 endif
11302 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011303 if !all && filereadable(newname)
11304 call inputsave()
11305 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11306 call inputrestore()
11307 if response == "all"
11308 let all= 1
11309 elseif response != "y" && response != "yes"
11310 " refresh the directory
11311" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11312 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11313" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11314 NetrwKeepj call winrestview(svpos)
11315 let @@= ykeep
11316" call Dret("NetrwLocalRename")
11317 return
11318 endif
11319 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011320 call rename(oldname,newname)
11321 endfor
11322 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011323
Bram Moolenaar97d62492012-11-15 21:28:22 +010011324 else
11325
11326 " attempt to rename files/directories
11327 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011328 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011329
11330 " sanity checks
11331 if line(".") < w:netrw_bannercnt
11332 let ctr= ctr + 1
11333 continue
11334 endif
11335 let curword= s:NetrwGetWord()
11336 if curword == "./" || curword == "../"
11337 let ctr= ctr + 1
11338 continue
11339 endif
11340
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011341 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011342 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011343" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011344
11345 call inputsave()
11346 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11347 call inputrestore()
11348
11349 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011350" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011351
11352 let ctr= ctr + 1
11353 endwhile
11354 endif
11355
11356 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011357" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011358 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011359" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11360 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011361 let @@= ykeep
11362
11363" call Dret("NetrwLocalRename")
11364endfun
11365
11366" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011367" s:NetrwLocalRm: {{{2
11368fun! s:NetrwLocalRm(path) range
11369" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011370" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011371
11372 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011373 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011374 let ret = 0
11375 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011376 let svpos = winsaveview()
11377" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011378
11379 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11380 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011381" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011382 for fname in s:netrwmarkfilelist_{bufnr("%")}
11383 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011384 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011385 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011386 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011387 let all= 1
11388 endif
11389 endfor
11390 call s:NetrwUnMarkFile(1)
11391
11392 else
11393 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011394" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011395
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011396 let keepsol= &l:sol
11397 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011398 let ctr = a:firstline
11399 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011400 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011401
11402 " sanity checks
11403 if line(".") < w:netrw_bannercnt
11404 let ctr= ctr + 1
11405 continue
11406 endif
11407 let curword= s:NetrwGetWord()
11408 if curword == "./" || curword == "../"
11409 let ctr= ctr + 1
11410 continue
11411 endif
11412 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011413 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011415 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011416 let all= 1
11417 endif
11418 let ctr= ctr + 1
11419 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011420 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011421 endif
11422
11423 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011424" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011425 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011426 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011427" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11428 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011429 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011430 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011431
11432" call Dret("s:NetrwLocalRm")
11433endfun
11434
11435" ---------------------------------------------------------------------
11436" s:NetrwLocalRmFile: remove file fname given the path {{{2
11437" Give confirmation prompt unless all==1
11438fun! s:NetrwLocalRmFile(path,fname,all)
11439" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011440
Bram Moolenaar446cb832008-06-24 21:56:24 +000011441 let all= a:all
11442 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011443 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011444 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11445" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011446
11447 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11448 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011449" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011450 if !all
11451 echohl Statement
11452 call inputsave()
11453 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11454 call inputrestore()
11455 echohl NONE
11456 if ok == ""
11457 let ok="no"
11458 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011459" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011460 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011461" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011462 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011463 let all= 1
11464 endif
11465 endif
11466
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011467 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011468 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011469" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011470 endif
11471
11472 else
11473 " attempt to remove directory
11474 if !all
11475 echohl Statement
11476 call inputsave()
11477 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11478 call inputrestore()
11479 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11480 if ok == ""
11481 let ok="no"
11482 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011483 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011484 let all= 1
11485 endif
11486 endif
11487 let rmfile= substitute(rmfile,'[\/]$','','e')
11488
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011489 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011490 if delete(rmfile,"d")
11491 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011492 endif
11493 endif
11494 endif
11495
11496" call Dret("s:NetrwLocalRmFile ".ok)
11497 return ok
11498endfun
11499
Bram Moolenaar85850f32019-07-19 22:05:51 +020011500" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011501" Support Functions: {{{1
11502
Bram Moolenaar488c6512005-08-11 20:09:58 +000011503" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011504" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11505" 0: marked file list of current buffer
11506" 1: marked file target
11507fun! netrw#Access(ilist)
11508 if a:ilist == 0
11509 if exists("s:netrwmarkfilelist_".bufnr('%'))
11510 return s:netrwmarkfilelist_{bufnr('%')}
11511 else
11512 return "no-list-buf#".bufnr('%')
11513 endif
11514 elseif a:ilist == 1
11515 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011516 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011517endfun
11518
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011519" ---------------------------------------------------------------------
11520" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11521fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011522 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011523endfun
11524
Bram Moolenaara6878372014-03-22 21:02:50 +010011525" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011526" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11527" I expect this function to be used in
11528" :PChkAssert netrw#Expose("netrwmarkfilelist")
11529" for example.
11530fun! netrw#Expose(varname)
11531" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011532 if exists("s:".a:varname)
11533 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011534" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011535 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011536" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011537 if type(retval) == 3
11538 let retval = copy(retval)
11539 let i = 0
11540 while i < len(retval)
11541 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11542 let i = i + 1
11543 endwhile
11544 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011545" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011546 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011547 else
11548" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011549 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011550 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011551" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011552 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011553 endif
11554
11555" call Dret("netrw#Expose ".string(retval))
11556 return retval
11557endfun
11558
11559" ---------------------------------------------------------------------
11560" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11561fun! netrw#Modify(varname,newvalue)
11562" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11563 exe "let s:".a:varname."= ".string(a:newvalue)
11564" call Dret("netrw#Modify")
11565endfun
11566
11567" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011568" netrw#RFC2396: converts %xx into characters {{{2
11569fun! netrw#RFC2396(fname)
11570" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11571 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11572" call Dret("netrw#RFC2396 ".fname)
11573 return fname
11574endfun
11575
11576" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011577" netrw#UserMaps: supports user-specified maps {{{2
11578" see :help function()
11579"
11580" g:Netrw_UserMaps is a List with members such as:
11581" [[keymap sequence, function reference],...]
11582"
11583" The referenced function may return a string,
11584" refresh : refresh the display
11585" -other- : this string will be executed
11586" or it may return a List of strings.
11587"
11588" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011589" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011590" Related functions:
11591" netrw#Expose(varname) -- see s:varname variables
11592" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11593" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11594fun! netrw#UserMaps(islocal)
11595" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11596" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11597
11598 " set up usermaplist
11599 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11600" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11601 for umap in g:Netrw_UserMaps
11602" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11603" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11604 " if umap[0] is a string and umap[1] is a string holding a function name
11605 if type(umap[0]) == 1 && type(umap[1]) == 1
11606" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11607 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11608 else
11609 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11610 endif
11611 endfor
11612 endif
11613" call Dret("netrw#UserMaps")
11614endfun
11615
11616" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011617" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11618fun! netrw#WinPath(path)
11619" call Dfunc("netrw#WinPath(path<".a:path.">)")
11620 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11621 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011622 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011623 " remove trailing slash (Win95)
11624 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11625 " remove escaped spaces
11626 let path = substitute(path, '\ ', ' ', 'g')
11627 " convert slashes to backslashes
11628 let path = substitute(path, '/', '\', 'g')
11629 else
11630 let path= a:path
11631 endif
11632" call Dret("netrw#WinPath <".path.">")
11633 return path
11634endfun
11635
11636" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011637" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11638" cb : bl2mf=0 add marked files to buffer list
11639" cB : bl2mf=1 use bufferlist to mark files
11640" (mnemonic: cb = copy (marked files) to buffer list)
11641fun! s:NetrwBadd(islocal,bl2mf)
11642" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11643 if a:bl2mf
11644 " cB: add buffer list to marked files
11645 redir => bufl
11646 ls
11647 redir END
11648 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11649 for fname in bufl
11650 call s:NetrwMarkFile(a:islocal,fname)
11651 endfor
11652 else
11653 " cb: add marked files to buffer list
11654 for fname in s:netrwmarkfilelist_{bufnr("%")}
11655" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11656 exe "badd ".fnameescape(fname)
11657 endfor
11658 let curbufnr = bufnr("%")
11659 let curdir = s:NetrwGetCurdir(a:islocal)
11660 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11661 endif
11662" call Dret("s:NetrwBadd")
11663endfun
11664
11665" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011666" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11667fun! s:ComposePath(base,subdir)
11668" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11669
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011670 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011671" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011672 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011673 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011674 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011675 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011676 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011677 endif
11678
Bram Moolenaar85850f32019-07-19 22:05:51 +020011679 " COMBAK: test on windows with changing to root directory: :e C:/
11680 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011681" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011682 let ret= a:subdir
11683
Bram Moolenaar85850f32019-07-19 22:05:51 +020011684 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011685" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011686 if a:base =~ '[/\\]$'
11687 let ret= a:base.a:subdir
11688 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011689 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011690 endif
11691
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011692 elseif a:base =~ '^\a\{3,}://'
11693" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011694 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11695 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11696 if a:subdir == '../'
11697 if curpath =~ '[^/]/[^/]\+/$'
11698 let curpath= substitute(curpath,'[^/]\+/$','','')
11699 else
11700 let curpath=""
11701 endif
11702 let ret= urlbase.curpath
11703 else
11704 let ret= urlbase.curpath.a:subdir
11705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011706" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11707" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11708" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011709
11710 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011711" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011712 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11713 if a:base =~ '^//'
11714 " keeping initial '//' for the benefit of network share listing support
11715 let ret= '/'.ret
11716 endif
11717 let ret= simplify(ret)
11718 endif
11719
11720" call Dret("s:ComposePath ".ret)
11721 return ret
11722endfun
11723
11724" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011725" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11726" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11727fun! s:DeleteBookmark(fname)
11728" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11729 call s:MergeBookmarks()
11730
11731 if exists("g:netrw_bookmarklist")
11732 let indx= index(g:netrw_bookmarklist,a:fname)
11733 if indx == -1
11734 let indx= 0
11735 while indx < len(g:netrw_bookmarklist)
11736 if g:netrw_bookmarklist[indx] =~ a:fname
11737 call remove(g:netrw_bookmarklist,indx)
11738 let indx= indx - 1
11739 endif
11740 let indx= indx + 1
11741 endwhile
11742 else
11743 " remove exact match
11744 call remove(g:netrw_bookmarklist,indx)
11745 endif
11746 endif
11747
11748" call Dret("s:DeleteBookmark")
11749endfun
11750
11751" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011752" s:FileReadable: o/s independent filereadable {{{2
11753fun! s:FileReadable(fname)
11754" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11755
11756 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011757 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011758 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011759 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011760 endif
11761
11762" call Dret("s:FileReadable ".ret)
11763 return ret
11764endfun
11765
11766" ---------------------------------------------------------------------
11767" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11768" Places correct suffix on end of temporary filename,
11769" using the suffix provided with fname
11770fun! s:GetTempfile(fname)
11771" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11772
11773 if !exists("b:netrw_tmpfile")
11774 " get a brand new temporary filename
11775 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011776" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011777
Bram Moolenaarc236c162008-07-13 17:41:49 +000011778 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011779" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011780
Bram Moolenaar9964e462007-05-05 17:54:07 +000011781 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011782 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11783" 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 +010011784 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011785" call Dret("s:GetTempfile getcwd<".getcwd().">")
11786 return ""
11787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011788
Bram Moolenaar9964e462007-05-05 17:54:07 +000011789 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011790 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011791" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011792
Bram Moolenaar9964e462007-05-05 17:54:07 +000011793 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011794 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011795 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011796 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011797 if !exists("+shellslash") || !&ssl
11798 let tmpfile = substitute(tmpfile,'/','\','g')
11799 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011800 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011801 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011802 endif
11803 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011804" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011805 else
11806 " re-use temporary filename
11807 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011808" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011809 endif
11810
11811 " use fname's suffix for the temporary file
11812 if a:fname != ""
11813 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011814" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011815 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011816 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011817 elseif a:fname =~ '.txz$'
11818 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011819 else
11820 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011823 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011824" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011825 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011826" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011827 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11828 endif
11829 endif
11830
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011831" 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 +000011832" call Dret("s:GetTempfile <".tmpfile.">")
11833 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011834endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835
11836" ---------------------------------------------------------------------
11837" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011838" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011839fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011840" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011841 if s:user == ""
11842 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11843 else
11844 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11845 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011846 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011847 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011848 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011849 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011850 else
11851 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11852 endif
11853" call Dret("s:MakeSshCmd <".sshcmd.">")
11854 return sshcmd
11855endfun
11856
11857" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011858" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11859fun! s:MakeBookmark(fname)
11860" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11861
11862 if !exists("g:netrw_bookmarklist")
11863 let g:netrw_bookmarklist= []
11864 endif
11865
11866 if index(g:netrw_bookmarklist,a:fname) == -1
11867 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011868 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011869 call add(g:netrw_bookmarklist,a:fname.'/')
11870 elseif a:fname !~ '/'
11871 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11872 else
11873 call add(g:netrw_bookmarklist,a:fname)
11874 endif
11875 call sort(g:netrw_bookmarklist)
11876 endif
11877
11878" call Dret("s:MakeBookmark")
11879endfun
11880
11881" ---------------------------------------------------------------------
11882" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11883fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011884" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011885 " get bookmarks from .netrwbook file
11886 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011887 if filereadable(s:NetrwFile(savefile))
11888" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011889 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011890" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011891 NetrwKeepj call delete(savefile)
11892 endif
11893" call Dret("s:MergeBookmarks")
11894endfun
11895
11896" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011897" s:NetrwBMShow: {{{2
11898fun! s:NetrwBMShow()
11899" call Dfunc("s:NetrwBMShow()")
11900 redir => bmshowraw
11901 menu
11902 redir END
11903 let bmshowlist = split(bmshowraw,'\n')
11904 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011905 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011906 if bmshowfuncs != []
11907 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011908 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011909 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011910 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011911 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011912 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011913" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11914endfun
11915
11916" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011917" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011918fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011919 if !exists("w:netrw_liststyle")
11920 let w:netrw_liststyle= g:netrw_liststyle
11921 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011922" 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 +020011923
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011924" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11925
Bram Moolenaaradc21822011-04-01 18:03:16 +020011926 if &ft != "netrw"
11927 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11928 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011929" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011930
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011931 elseif g:netrw_cursor == 8
11932 if w:netrw_liststyle == s:WIDELIST
11933 setl cursorline
11934 setl cursorcolumn
11935 else
11936 setl cursorline
11937 endif
11938 elseif g:netrw_cursor == 7
11939 setl cursorline
11940 elseif g:netrw_cursor == 6
11941 if w:netrw_liststyle == s:WIDELIST
11942 setl cursorline
11943 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011944 elseif g:netrw_cursor == 4
11945 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011946" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011947 setl cursorline
11948 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011949
11950 elseif g:netrw_cursor == 3
11951 " thin-long-tree: cursorline, user's cursorcolumn
11952 " wide : cursorline, cursorcolumn
11953 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011954" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011955 setl cursorline
11956 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011957 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011958" 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 +020011959 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011960 endif
11961
11962 elseif g:netrw_cursor == 2
11963 " thin-long-tree: cursorline, user's cursorcolumn
11964 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011965" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011966 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011967
11968 elseif g:netrw_cursor == 1
11969 " thin-long-tree: user's cursorline, user's cursorcolumn
11970 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011971 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011972" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011973 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011974 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011975" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011976 endif
11977
11978 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011981 let &l:cursorline = s:netrw_usercul
11982 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011983 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011984
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011985" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011986" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011987endfun
11988
11989" ---------------------------------------------------------------------
11990" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11991fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011992" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011993 if exists("s:netrw_usercul")
11994 let &l:cursorline = s:netrw_usercul
11995 endif
11996 if exists("s:netrw_usercuc")
11997 let &l:cursorcolumn = s:netrw_usercuc
11998 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011999" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012000" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12001endfun
12002
12003" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012004" s:NetrwDelete: Deletes a file. {{{2
12005" Uses Steve Hall's idea to insure that Windows paths stay
12006" acceptable. No effect on Unix paths.
12007" Examples of use: let result= s:NetrwDelete(path)
12008fun! s:NetrwDelete(path)
12009" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12010
Bram Moolenaar5c736222010-01-06 20:54:52 +010012011 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012012 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
12013 if exists("+shellslash")
12014 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012015 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012016 let result = delete(path)
12017 let &shellslash = sskeep
12018 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012019" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012020 let result= delete(path)
12021 endif
12022 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012023" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012024 let result= delete(path)
12025 endif
12026 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012027 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012028 endif
12029
12030" call Dret("s:NetrwDelete ".result)
12031 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012032endfun
12033
12034" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012035" s:NetrwBufRemover: removes a buffer that: {{{2s
12036" has buffer-id > 1
12037" is unlisted
12038" is unnamed
12039" does not appear in any window
12040fun! s:NetrwBufRemover(bufid)
12041" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12042" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12043" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12044" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12045" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12046
12047 if a:bufid > 1 && !buflisted(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
12048" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
12049 exe "bd! ".a:bufid
12050 endif
12051
12052" call Dret("s:NetrwBufRemover")
12053endfun
12054
12055" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012056" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012057fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012058" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012059" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012060
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012061 " Clean out the last buffer:
12062 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12063 " If so, delete it.
12064 call s:NetrwBufRemover(bufnr("$"))
12065
Bram Moolenaar446cb832008-06-24 21:56:24 +000012066 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012067" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012068 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12069 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12070 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12071 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12072 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12073 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12074 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12075 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12076 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12077 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12078 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12079 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12080 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12081 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12082 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12083 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12084
Bram Moolenaar85850f32019-07-19 22:05:51 +020012085 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012086" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012087 " when tree listing uses file TreeListing... a new buffer is made.
12088 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012089 " COMBAK: this causes a problem, see P43
12090" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012091 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012092 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012093 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012094" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012095 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012096
Bram Moolenaar446cb832008-06-24 21:56:24 +000012097 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012098" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012099 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12100 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12101 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12102 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12103 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12104 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12105 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12106 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12107 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12108 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12109 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12110 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12111 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12112 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12113 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12114 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12115
Bram Moolenaar5c736222010-01-06 20:54:52 +010012116 if a:0 > 0
12117 let b:netrw_curdir= a:1
12118 if b:netrw_curdir =~ '/$'
12119 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012120 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012121 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012122 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012123 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12124 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012125 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012126 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012127 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012128 endif
12129 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012130 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12131 let &l:bexpr = "netrw#BalloonHelp()"
12132 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012133
Bram Moolenaar8d043172014-01-23 14:24:41 +010012134" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012135endfun
12136
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012137" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012138" s:NetrwExe: executes a string using "!" {{{2
12139fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012140" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012141 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012142" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012143 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12144 set shell& shellcmdflag& shellxquote& shellxescape&
12145 set shellquote& shellpipe& shellredir& shellslash&
12146 exe a:cmd
12147 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12148 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012149" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012150 exe a:cmd
12151 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012152 if v:shell_error
12153 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12154 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012155" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012156endfun
12157
12158" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012159" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12160fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012161 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012162" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012163 let curbuf = bufnr("%")
12164 let curwin = winnr()
12165 let iwin = 1
12166 while iwin <= winnr("$")
12167 exe iwin."wincmd w"
12168 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12169 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12170 let winvars= w:
12171 break
12172 endif
12173 let iwin= iwin + 1
12174 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012175 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012176 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012177" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012178 for k in keys(winvars)
12179 let w:{k}= winvars[k]
12180 endfor
12181 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012182" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012183 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012184endfun
12185
Bram Moolenaara6878372014-03-22 21:02:50 +010012186" ---------------------------------------------------------------------
12187" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012188" Returns: 0=success
12189" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012190fun! s:NetrwLcd(newdir)
12191" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012192" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012193
Bram Moolenaar85850f32019-07-19 22:05:51 +020012194 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012195 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012196 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012197 catch /^Vim\%((\a\+)\)\=:E344/
12198 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12199 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012200 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012201 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12202 " forward slashes by earlier code; so check for both.
12203 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12204 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12205 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012206 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012207 endif
12208 endif
12209 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012210 let err472= 1
12211 endtry
12212
12213 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012214 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12215 if exists("w:netrw_prvdir")
12216 let a:newdir= w:netrw_prvdir
12217 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012218 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012219" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012220 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012221" 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 +010012222 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012223 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012224" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12225 return -1
12226 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012227
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012228" call Decho("getcwd <".getcwd().">")
12229" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012230" call Dret("s:NetrwLcd 0")
12231 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012232endfun
12233
Bram Moolenaar9964e462007-05-05 17:54:07 +000012234" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012235" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12236" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12237fun! s:NetrwSaveWordPosn()
12238" call Dfunc("NetrwSaveWordPosn()")
12239 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12240" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12241endfun
12242
12243" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012244" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12245" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12246fun! s:NetrwHumanReadable(sz)
12247" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12248
12249 if g:netrw_sizestyle == 'h'
12250 if a:sz >= 1000000000
12251 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12252 elseif a:sz >= 10000000
12253 let sz = printf("%d",a:sz/1000000)."m"
12254 elseif a:sz >= 1000000
12255 let sz = printf("%.1f",a:sz/1000000.0)."m"
12256 elseif a:sz >= 10000
12257 let sz = printf("%d",a:sz/1000)."k"
12258 elseif a:sz >= 1000
12259 let sz = printf("%.1f",a:sz/1000.0)."k"
12260 else
12261 let sz= a:sz
12262 endif
12263
12264 elseif g:netrw_sizestyle == 'H'
12265 if a:sz >= 1073741824
12266 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12267 elseif a:sz >= 10485760
12268 let sz = printf("%d",a:sz/1048576)."M"
12269 elseif a:sz >= 1048576
12270 let sz = printf("%.1f",a:sz/1048576.0)."M"
12271 elseif a:sz >= 10240
12272 let sz = printf("%d",a:sz/1024)."K"
12273 elseif a:sz >= 1024
12274 let sz = printf("%.1f",a:sz/1024.0)."K"
12275 else
12276 let sz= a:sz
12277 endif
12278
12279 else
12280 let sz= a:sz
12281 endif
12282
12283" call Dret("s:NetrwHumanReadable ".sz)
12284 return sz
12285endfun
12286
12287" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012288" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12289" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12290fun! s:NetrwRestoreWordPosn()
12291" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012292 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012293" call Dret("NetrwRestoreWordPosn")
12294endfun
12295
12296" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012297" s:RestoreBufVars: {{{2
12298fun! s:RestoreBufVars()
12299" call Dfunc("s:RestoreBufVars()")
12300
12301 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12302 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12303 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12304 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12305 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12306 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12307
12308" call Dret("s:RestoreBufVars")
12309endfun
12310
12311" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012312" s:RemotePathAnalysis: {{{2
12313fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012314" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012315
Bram Moolenaara6878372014-03-22 21:02:50 +010012316 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012317 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012318 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012319 let s:user = substitute(a:dirname,dirpat,'\3','')
12320 let s:machine = substitute(a:dirname,dirpat,'\4','')
12321 let s:port = substitute(a:dirname,dirpat,'\5','')
12322 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012323 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012324 if s:machine =~ '@'
12325 let dirpat = '^\(.*\)@\(.\{-}\)$'
12326 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12327 let s:machine = substitute(s:machine,dirpat,'\2','')
12328 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012329
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012330" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12331" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12332" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12333" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12334" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12335" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012336
12337" call Dret("s:RemotePathAnalysis")
12338endfun
12339
12340" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012341" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12342" Returns status
12343" Runs system() on
12344" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012345" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012346fun! s:RemoteSystem(cmd)
12347" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12348 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012349 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 +000012350 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012351 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012352 else
12353 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12354 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12355 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012356 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012357 else
12358 let cmd= cmd.' '
12359 endif
12360 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012361" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012362 let ret= system(cmd)
12363 endif
12364" call Dret("s:RemoteSystem ".ret)
12365 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012366endfun
12367
12368" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012369" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012370fun! s:RestoreWinVars()
12371" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012372 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012373 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12374 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12375 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12376 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12377 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12378 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12379 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12380 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12381 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12382 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12383 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12384 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012385 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12386 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012387 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12388 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12389 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12390" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012391endfun
12392
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012393" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012394" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12395"
12396" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12397" is true) and a command, :Rexplore, which call this function.
12398"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012399" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012400"
12401" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012402fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012403 if exists("s:netrwdrag")
12404 return
12405 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012406" 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 +010012407" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12408" 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 +010012409
12410 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012411 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012412" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012413 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012414 unlet w:netrw_rexfile
12415" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012416 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012417" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012418" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12419" 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 +020012420 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012421
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012422 " ---------------------------
12423 " :Rex issued while in a file
12424 " ---------------------------
12425
Bram Moolenaara6878372014-03-22 21:02:50 +010012426 " record current file so :Rex can return to it from netrw
12427 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012428" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012429
12430 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012431" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012432 return
12433 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012434" 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 +020012435 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012436 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012437 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012438 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012439 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012440 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012441 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012442 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012443 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012444" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12445 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012446" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12447 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012448 if exists("s:rexposn_".bufnr('%'))
12449 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012450 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012451 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012452" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012453 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012454
Bram Moolenaar85850f32019-07-19 22:05:51 +020012455 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12456 if exists("s:explore_match")
12457 exe "2match netrwMarkFile /".s:explore_match."/"
12458 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012459 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012460
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012461" 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 +010012462" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012463endfun
12464
12465" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012466" s:SaveBufVars: save selected b: variables to s: variables {{{2
12467" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012468fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012469" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012470
12471 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12472 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12473 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12474 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12475 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12476 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12477
12478" call Dret("s:SaveBufVars")
12479endfun
12480
12481" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012482" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12483fun! s:SavePosn(posndict)
12484" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12485
Bram Moolenaar85850f32019-07-19 22:05:51 +020012486 if !exists("a:posndict[bufnr('%')]")
12487 let a:posndict[bufnr("%")]= []
12488 endif
12489" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12490 call add(a:posndict[bufnr("%")],winsaveview())
12491" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012492
12493" call Dret("s:SavePosn posndict")
12494 return a:posndict
12495endfun
12496
12497" ---------------------------------------------------------------------
12498" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12499fun! s:RestorePosn(posndict)
12500" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012501 if exists("a:posndict")
12502 if has_key(a:posndict,bufnr("%"))
12503" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12504 let posnlen= len(a:posndict[bufnr("%")])
12505 if posnlen > 0
12506 let posnlen= posnlen - 1
12507" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12508 call winrestview(a:posndict[bufnr("%")][posnlen])
12509 call remove(a:posndict[bufnr("%")],posnlen)
12510" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12511 endif
12512 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012513 endif
12514" call Dret("s:RestorePosn")
12515endfun
12516
12517" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012518" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012519fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012520" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012521 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12522 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12523 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12524 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12525 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12526 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12527 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12528 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12529 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12530 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12531 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12532 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12533 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12534 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12535 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12536 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12537 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12538 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12539" call Dret("s:SaveWinVars")
12540endfun
12541
12542" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012543" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012544" To allow separate windows to have their own activities, such as
12545" Explore **/pattern, several variables have been made window-oriented.
12546" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012547" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012548" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012549fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012550" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012551 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12552 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12553 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12554 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12555 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12556 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12557 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12558 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12559 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12560 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12561" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012562endfun
12563
12564" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012565" s:SetRexDir: set directory for :Rexplore {{{2
12566fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012567" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012568 let w:netrw_rexdir = a:dirname
12569 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012570 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012571" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12572" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012573" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012574" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012575" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012576endfun
12577
12578" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012579" s:ShowLink: used to modify thin and tree listings to show links {{{2
12580fun! s:ShowLink()
12581" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012582" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12583" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012584 if exists("b:netrw_curdir")
12585 norm! $?\a
12586 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12587 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012588" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12589" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12590" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12591 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012592 let dirlen = strlen(b:netrw_curdir)
12593 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012594" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012595 endif
12596 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012597" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12598" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012599 setl noro ma
12600 call setline(".",modline)
12601 setl ro noma nomod
12602 endif
12603" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12604endfun
12605
12606" ---------------------------------------------------------------------
12607" s:ShowStyle: {{{2
12608fun! s:ShowStyle()
12609 if !exists("w:netrw_liststyle")
12610 let liststyle= g:netrw_liststyle
12611 else
12612 let liststyle= w:netrw_liststyle
12613 endif
12614 if liststyle == s:THINLIST
12615 return s:THINLIST.":thin"
12616 elseif liststyle == s:LONGLIST
12617 return s:LONGLIST.":long"
12618 elseif liststyle == s:WIDELIST
12619 return s:WIDELIST.":wide"
12620 elseif liststyle == s:TREELIST
12621 return s:TREELIST.":tree"
12622 else
12623 return 'n/a'
12624 endif
12625endfun
12626
12627" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012628" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12629" Solution from Nicolai Weibull, vim docs (:help strlen()),
12630" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012631fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012632" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12633
12634 if v:version >= 703 && exists("*strdisplaywidth")
12635 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012636
Bram Moolenaar8d043172014-01-23 14:24:41 +010012637 elseif type(g:Align_xstrlen) == 1
12638 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12639 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012640
Bram Moolenaar8d043172014-01-23 14:24:41 +010012641 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012642 " number of codepoints (Latin a + combining circumflex is two codepoints)
12643 " (comment from TM, solution from NW)
12644 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012645
Bram Moolenaar8d043172014-01-23 14:24:41 +010012646 elseif g:Align_xstrlen == 2
12647 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012648 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12649 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012650 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012651
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 elseif g:Align_xstrlen == 3
12653 " virtual length (counting, for instance, tabs as anything between 1 and
12654 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012655 " preceded by lam, one otherwise, etc.)
12656 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012657 let modkeep= &l:mod
12658 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012659 call setline(line("."),a:x)
12660 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012661 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012662 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012663 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012664
Bram Moolenaar446cb832008-06-24 21:56:24 +000012665 else
12666 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012667 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012668 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012669" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012670 return ret
12671endfun
12672
12673" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012674" s:ShellEscape: shellescape(), or special windows handling {{{2
12675fun! s:ShellEscape(s, ...)
12676 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12677 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12678 endif
12679 let f = a:0 > 0 ? a:1 : 0
12680 return shellescape(a:s, f)
12681endfun
12682
12683" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012684" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012685fun! s:TreeListMove(dir)
12686" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012687 let curline = getline('.')
12688 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12689 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12690 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12691 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12692 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12693 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12694" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12695" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12696" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12697" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12698" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12699 " COMBAK : need to handle when on a directory
12700 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012701 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012702 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012703 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012704 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012705" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012706 elseif a:dir == '[]' && nxtline != ''
12707 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012708" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012709 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12710 if nl != 0
12711 NetrwKeepj norm! k
12712 else
12713 NetrwKeepj norm! G
12714 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012715" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012716 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012717 endif
12718
12719" call Dret("s:TreeListMove")
12720endfun
12721
12722" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012723" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12724" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12725" can't be called except via emenu. But due to locale, that menu line may not be called
12726" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12727fun! s:UpdateBuffersMenu()
12728" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012729 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012730 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012731 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012732 catch /^Vim\%((\a\+)\)\=:E/
12733 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012734 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012735 endtry
12736 endif
12737" call Dret("s:UpdateBuffersMenu")
12738endfun
12739
12740" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012741" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012742" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012743fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012744" call Dfunc("s:UseBufWinVars()")
12745 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012746 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12747 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12748 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12749 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12750 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12751 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12752 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12753 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12754 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 +000012755" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012756endfun
12757
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012758" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012759" s:UserMaps: supports user-defined UserMaps {{{2
12760" * calls a user-supplied funcref(islocal,curdir)
12761" * interprets result
12762" See netrw#UserMaps()
12763fun! s:UserMaps(islocal,funcname)
12764" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12765
12766 if !exists("b:netrw_curdir")
12767 let b:netrw_curdir= getcwd()
12768 endif
12769 let Funcref = function(a:funcname)
12770 let result = Funcref(a:islocal)
12771
12772 if type(result) == 1
12773 " if result from user's funcref is a string...
12774" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12775 if result == "refresh"
12776" call Decho("refreshing display",'~'.expand("<slnum>"))
12777 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12778 elseif result != ""
12779" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12780 exe result
12781 endif
12782
12783 elseif type(result) == 3
12784 " if result from user's funcref is a List...
12785" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12786 for action in result
12787 if action == "refresh"
12788" call Decho("refreshing display",'~'.expand("<slnum>"))
12789 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12790 elseif action != ""
12791" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12792 exe action
12793 endif
12794 endfor
12795 endif
12796
12797" call Dret("s:UserMaps")
12798endfun
12799
Bram Moolenaar85850f32019-07-19 22:05:51 +020012800" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012801" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012802" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012803let &cpo= s:keepcpo
12804unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012805
Bram Moolenaar85850f32019-07-19 22:05:51 +020012806" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012807" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012808" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012809" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012810" doing autoload/netrw.vim version v172g ~57
12811" varname<g:netrw_dirhistcnt> value=0 ~1
12812" varname<s:THINLIST> value=0 ~1
12813" varname<s:LONGLIST> value=1 ~1
12814" varname<s:WIDELIST> value=2 ~1
12815" varname<s:TREELIST> value=3 ~1
12816" varname<s:MAXLIST> value=4 ~1
12817" varname<g:netrw_use_errorwindow> value=2 ~1
12818" varname<g:netrw_http_xcmd> value=-q -O ~1
12819" varname<g:netrw_http_put_cmd> value=curl -T ~1
12820" varname<g:netrw_keepj> value=keepj ~1
12821" varname<g:netrw_rcp_cmd> value=rcp ~1
12822" varname<g:netrw_rsync_cmd> value=rsync ~1
12823" varname<g:netrw_rsync_sep> value=/ ~1
12824" varname<g:netrw_scp_cmd> value=scp -q ~1
12825" varname<g:netrw_sftp_cmd> value=sftp ~1
12826" varname<g:netrw_ssh_cmd> value=ssh ~1
12827" varname<g:netrw_alto> value=0 ~1
12828" varname<g:netrw_altv> value=1 ~1
12829" varname<g:netrw_banner> value=1 ~1
12830" varname<g:netrw_browse_split> value=0 ~1
12831" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12832" varname<g:netrw_chgwin> value=-1 ~1
12833" varname<g:netrw_clipboard> value=1 ~1
12834" varname<g:netrw_compress> value=gzip ~1
12835" varname<g:netrw_ctags> value=ctags ~1
12836" varname<g:netrw_cursor> value=2 ~1
12837" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12838" varname<g:netrw_cygdrive> value=/cygdrive ~1
12839" varname<s:didstarstar> value=0 ~1
12840" varname<g:netrw_dirhistcnt> value=0 ~1
12841" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12842" varname<g:netrw_dirhistmax> value=10 ~1
12843" varname<g:netrw_errorlvl> value=0 ~1
12844" varname<g:netrw_fastbrowse> value=1 ~1
12845" 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
12846" varname<g:netrw_ftpmode> value=binary ~1
12847" varname<g:netrw_hide> value=1 ~1
12848" varname<g:netrw_keepdir> value=1 ~1
12849" varname<g:netrw_list_hide> value= ~1
12850" varname<g:netrw_localmkdir> value=mkdir ~1
12851" varname<g:netrw_remote_mkdir> value=mkdir ~1
12852" varname<g:netrw_liststyle> value=0 ~1
12853" varname<g:netrw_markfileesc> value=*./[\~ ~1
12854" varname<g:netrw_maxfilenamelen> value=32 ~1
12855" varname<g:netrw_menu> value=1 ~1
12856" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12857" varname<g:netrw_mousemaps> value=1 ~1
12858" varname<g:netrw_retmap> value=0 ~1
12859" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12860" varname<g:netrw_preview> value=0 ~1