blob: d2df84666290e0c72bc68409da9cca6f8154363f [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
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001169" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001170 endif
1171
Bram Moolenaara6878372014-03-22 21:02:50 +01001172 " since Explore may be used to initialize netrw's browser,
1173 " there's no danger of a late FocusGained event on initialization.
1174 " Consequently, set s:netrw_events to 2.
1175 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001176 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001177" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001178 if @* != keepregstar | sil! let @* = keepregstar | endif
1179 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001180 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001181 sil! let @/ = keepregslash
1182" call Dret("netrw#Explore : @/<".@/.">")
1183endfun
1184
1185" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001186" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001187" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1188" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1189" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1190" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1191" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001192fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001193" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194 let curwin= winnr()
1195
Bram Moolenaara6878372014-03-22 21:02:50 +01001196 if a:0 > 0 && a:1 != ""
1197 " if a netrw window is already on the left-side of the tab
1198 " and a directory has been specified, explore with that
1199 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001200" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001202" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001203 exe "1wincmd w"
1204 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001205" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 exe "Explore ".fnameescape(a1)
1207 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001208 let s:lexplore_win= curwin
1209 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001211" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 unlet t:netrw_lexposn
1213 endif
1214" call Dret("netrw#Lexplore")
1215 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001216 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 exe curwin."wincmd w"
1218 else
1219 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001220" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001221 endif
1222
Bram Moolenaar8d043172014-01-23 14:24:41 +01001223 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001224 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001225 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 else
1228 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001231" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232
1233 if lexwinnr > 0
1234 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001235" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 exe lexwinnr."wincmd w"
1237 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001238 let t:netrw_lexposn = winsaveview()
1239" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001240" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001241 close
1242 if lexwinnr < curwin
1243 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001244 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001245 if lexwinnr != curwin
1246 exe curwin."wincmd w"
1247 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001248 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001249" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001250
1251 else
1252 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001253" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001254 exe "1wincmd w"
1255 let keep_altv = g:netrw_altv
1256 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001257 if a:count != 0
1258 let netrw_winsize = g:netrw_winsize
1259 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001260 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001261 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001262" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 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 +02001264" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001266" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001267 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269 elseif curfile =~ '^\a\{3,}://'
1270" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001271 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001273" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001274 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 endif
1276 if a:count != 0
1277 let g:netrw_winsize = netrw_winsize
1278 endif
1279 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001280 let g:netrw_altv = keep_altv
1281 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001282 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1283 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001284 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001285 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001286" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1287" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001288 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001289" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001290" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1291 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001292 unlet t:netrw_lexposn
1293 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001294 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295
1296 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001297 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001298 if a:rightside
1299 let g:netrw_chgwin= 1
1300 else
1301 let g:netrw_chgwin= 2
1302 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001303" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001304 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001305
Bram Moolenaar8d043172014-01-23 14:24:41 +01001306" call Dret("netrw#Lexplore")
1307endfun
1308
1309" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001310" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001311" supports :NetrwClean -- remove netrw from first directory on runtimepath
1312" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001313fun! netrw#Clean(sys)
1314" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001315
1316 if a:sys
1317 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1318 else
1319 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1320 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001321" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001322 let diddel= 0
1323 let diddir= ""
1324
1325 if choice == 1
1326 for dir in split(&rtp,',')
1327 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001328" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001329 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1330 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1331 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1332 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1333 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1334 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 +00001335 let diddir= dir
1336 let diddel= diddel + 1
1337 if !a:sys|break|endif
1338 endif
1339 endfor
1340 endif
1341
1342 echohl WarningMsg
1343 if diddel == 0
1344 echomsg "netrw is either not installed or not removable"
1345 elseif diddel == 1
1346 echomsg "removed one copy of netrw from <".diddir.">"
1347 else
1348 echomsg "removed ".diddel." copies of netrw"
1349 endif
1350 echohl None
1351
Bram Moolenaara6878372014-03-22 21:02:50 +01001352" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001353endfun
1354
Bram Moolenaar5c736222010-01-06 20:54:52 +01001355" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001356" netrw#MakeTgt: make a target out of the directory name provided {{{2
1357fun! netrw#MakeTgt(dname)
1358" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1359 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001360 let svpos = winsaveview()
1361" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001362 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1363" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001364 if s:netrwmftgt_islocal
1365 let netrwmftgt= simplify(a:dname)
1366 else
1367 let netrwmftgt= a:dname
1368 endif
1369 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1370 " re-selected target, so just clear it
1371 unlet s:netrwmftgt s:netrwmftgt_islocal
1372 else
1373 let s:netrwmftgt= netrwmftgt
1374 endif
1375 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001376 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001377 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001378" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1379 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001380" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001381endfun
1382
Bram Moolenaara6878372014-03-22 21:02:50 +01001383" ---------------------------------------------------------------------
1384" netrw#Obtain: {{{2
1385" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001386" islocal=0 obtain from remote source
1387" =1 obtain from local source
1388" fname : a filename or a list of filenames
1389" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001390fun! netrw#Obtain(islocal,fname,...)
1391" 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 +02001392 " NetrwStatusLine support - for obtaining support
1393
1394 if type(a:fname) == 1
1395 let fnamelist= [ a:fname ]
1396 elseif type(a:fname) == 3
1397 let fnamelist= a:fname
1398 else
1399 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 +01001400" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 return
1402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001403" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 if a:0 > 0
1405 let tgtdir= a:1
1406 else
1407 let tgtdir= getcwd()
1408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001410
1411 if exists("b:netrw_islocal") && b:netrw_islocal
1412 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001413" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1415 let topath= s:ComposePath(tgtdir,"")
1416 if (has("win32") || has("win95") || has("win64") || has("win16"))
1417 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001418" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001419 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001420" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001421 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 if v:shell_error != 0
1423 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 +01001424" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 return
1426 endif
1427 endfor
1428 else
1429 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001430" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1431 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1432" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001433 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001434 if v:shell_error != 0
1435 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 +01001436" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 return
1438 endif
1439 endif
1440 elseif !exists("b:netrw_curdir")
1441 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1442 else
1443 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1444 endif
1445
1446 else
1447 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001448" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001449 if type(a:fname) == 1
1450 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1451 endif
1452 call s:NetrwMethod(b:netrw_curdir)
1453
1454 if b:netrw_method == 4
1455 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001456" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001457 if exists("g:netrw_port") && g:netrw_port != ""
1458 let useport= " ".g:netrw_scpport." ".g:netrw_port
1459 else
1460 let useport= ""
1461 endif
1462 if b:netrw_fname =~ '/'
1463 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1464 else
1465 let path= ""
1466 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001467 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001468 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 +02001469
1470 elseif b:netrw_method == 2
1471 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001472" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001473 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 let tmpbufnr= bufnr("%")
1475 setl ff=unix
1476 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001477 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001478" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001479 endif
1480
1481 if exists("b:netrw_fname") && b:netrw_fname != ""
1482 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 endif
1485
1486 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001487 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001488" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001489 endif
1490 for fname in fnamelist
1491 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 endfor
1494 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495 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 +02001496 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001497 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001498 endif
1499 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1500 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1501 let debugkeep= &debug
1502 setl debug=msg
1503 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1504 let &debug= debugkeep
1505 endif
1506
1507 elseif b:netrw_method == 3
1508 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001509" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001510 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 let tmpbufnr= bufnr("%")
1512 setl ff=unix
1513
1514 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001516" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001517 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 endif
1521
1522 if exists("g:netrw_uid") && g:netrw_uid != ""
1523 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001524 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001529" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001530 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001531 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 endif
1534 endif
1535
1536 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001538" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001539 endif
1540
1541 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001544 endif
1545
1546 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001547 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001548" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001549 endif
1550
1551 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001552 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001553" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001554 endif
1555 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001556 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001557 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001558" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001559
1560 " perform ftp:
1561 " -i : turns off interactive prompting from ftp
1562 " -n unix : DON'T use <.netrc>, even though it exists
1563 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001564 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1565 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001566 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001567 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1568 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001569" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001571 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001572 endif
1573 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001574
1575 elseif b:netrw_method == 9
1576 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001577" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001578 if a:fname =~ '/'
1579 let localfile= substitute(a:fname,'^.*/','','')
1580 else
1581 let localfile= a:fname
1582 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001583 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 +02001584
Bram Moolenaarff034192013-04-24 18:51:19 +02001585 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001586 " probably a badly formed url; protocol not recognized
1587" call Dret("netrw#Obtain : unsupported method")
1588 return
1589
1590 else
1591 " protocol recognized but not supported for Obtain (yet?)
1592 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001593 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001594 endif
1595" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001596 return
1597 endif
1598
1599 " restore status line
1600 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001601 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001602 endif
1603
1604 endif
1605
1606 " cleanup
1607 if exists("tmpbufnr")
1608 if bufnr("%") != tmpbufnr
1609 exe tmpbufnr."bw!"
1610 else
1611 q!
1612 endif
1613 endif
1614
Bram Moolenaara6878372014-03-22 21:02:50 +01001615" call Dret("netrw#Obtain")
1616endfun
1617
1618" ---------------------------------------------------------------------
1619" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1620fun! netrw#Nread(mode,fname)
1621" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001622 let svpos= winsaveview()
1623" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001624 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001625" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1626 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001627
1628 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1629 if exists("w:netrw_bannercnt")
1630 " start with cursor just after the banner
1631 exe w:netrw_bannercnt
1632 endif
1633 endif
1634" call Dret("netrw#Nread")
1635endfun
1636
1637" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001638" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1639" Options get restored by s:NetrwOptionsRestore()
1640"
1641" Option handling:
1642" * save user's options (s:NetrwOptionsSave)
1643" * set netrw-safe options (s:NetrwOptionsSafe)
1644" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1645" * restore user's options (s:netrwOPtionsRestore)
1646" - restore a user option when != safe option (s:NetrwRestoreSetting)
1647" vt: (variable type) normally its either "w:" or "s:"
1648fun! s:NetrwOptionsSave(vt)
1649" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1650" 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 +02001651" 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>"))
1652" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001653
1654 if !exists("{a:vt}netrw_optionsave")
1655 let {a:vt}netrw_optionsave= 1
1656 else
1657" call Dret("s:NetrwOptionsSave : options already saved")
1658 return
1659 endif
1660" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1661
1662 " Save current settings and current directory
1663" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1664 let s:yykeep = @@
1665 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1666 let {a:vt}netrw_aikeep = &l:ai
1667 let {a:vt}netrw_awkeep = &l:aw
1668 let {a:vt}netrw_bhkeep = &l:bh
1669 let {a:vt}netrw_blkeep = &l:bl
1670 let {a:vt}netrw_btkeep = &l:bt
1671 let {a:vt}netrw_bombkeep = &l:bomb
1672 let {a:vt}netrw_cedit = &cedit
1673 let {a:vt}netrw_cikeep = &l:ci
1674 let {a:vt}netrw_cinkeep = &l:cin
1675 let {a:vt}netrw_cinokeep = &l:cino
1676 let {a:vt}netrw_comkeep = &l:com
1677 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001678 let {a:vt}netrw_cuckeep = &l:cuc
1679 let {a:vt}netrw_culkeep = &l:cul
1680" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001681 let {a:vt}netrw_diffkeep = &l:diff
1682 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001683 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1684 let {a:vt}netrw_ffkeep = &l:ff
1685 endif
1686 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1687 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001688 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001689 let {a:vt}netrw_hidkeep = &l:hidden
1690 let {a:vt}netrw_imkeep = &l:im
1691 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001692 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001693 let {a:vt}netrw_lskeep = &l:ls
1694 let {a:vt}netrw_makeep = &l:ma
1695 let {a:vt}netrw_magickeep = &l:magic
1696 let {a:vt}netrw_modkeep = &l:mod
1697 let {a:vt}netrw_nukeep = &l:nu
1698 let {a:vt}netrw_rnukeep = &l:rnu
1699 let {a:vt}netrw_repkeep = &l:report
1700 let {a:vt}netrw_rokeep = &l:ro
1701 let {a:vt}netrw_selkeep = &l:sel
1702 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001703 if !g:netrw_use_noswf
1704 let {a:vt}netrw_swfkeep = &l:swf
1705 endif
1706 let {a:vt}netrw_tskeep = &l:ts
1707 let {a:vt}netrw_twkeep = &l:tw " textwidth
1708 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1709 let {a:vt}netrw_wrapkeep = &l:wrap
1710 let {a:vt}netrw_writekeep = &l:write
1711
1712 " save a few selected netrw-related variables
1713" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1714 if g:netrw_keepdir
1715 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001716" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001717 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001718 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001719 sil! let {a:vt}netrw_starkeep = @*
1720 sil! let {a:vt}netrw_pluskeep = @+
1721 endif
1722 sil! let {a:vt}netrw_slashkeep= @/
1723
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001724" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001725" 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>"))
1726" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1727endfun
1728
1729" ---------------------------------------------------------------------
1730" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1731" Use s:NetrwSaveOptions() to save user settings
1732" Use s:NetrwOptionsRestore() to restore user settings
1733fun! s:NetrwOptionsSafe(islocal)
1734" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1735" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1736" 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>"))
1737 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1738 call s:NetrwSetSafeSetting("&l:ai",0)
1739 call s:NetrwSetSafeSetting("&l:aw",0)
1740 call s:NetrwSetSafeSetting("&l:bl",0)
1741 call s:NetrwSetSafeSetting("&l:bomb",0)
1742 if a:islocal
1743 call s:NetrwSetSafeSetting("&l:bt","nofile")
1744 else
1745 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1746 endif
1747 call s:NetrwSetSafeSetting("&l:ci",0)
1748 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001749 if g:netrw_fastbrowse > a:islocal
1750 call s:NetrwSetSafeSetting("&l:bh","hide")
1751 else
1752 call s:NetrwSetSafeSetting("&l:bh","delete")
1753 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001754 call s:NetrwSetSafeSetting("&l:cino","")
1755 call s:NetrwSetSafeSetting("&l:com","")
1756 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1757 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1758 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001759 if &go =~ 'a' | set go-=a | endif
1760 if &go =~ 'A' | set go-=A | endif
1761 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001762 call s:NetrwSetSafeSetting("&l:hid",0)
1763 call s:NetrwSetSafeSetting("&l:im",0)
1764 setl isk+=@ isk+=* isk+=/
1765 call s:NetrwSetSafeSetting("&l:magic",1)
1766 if g:netrw_use_noswf
1767 call s:NetrwSetSafeSetting("swf",0)
1768 endif
1769 call s:NetrwSetSafeSetting("&l:report",10000)
1770 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1771 call s:NetrwSetSafeSetting("&l:spell",0)
1772 call s:NetrwSetSafeSetting("&l:tw",0)
1773 call s:NetrwSetSafeSetting("&l:wig","")
1774 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001775
1776 " set up cuc and cul based on g:netrw_cursor and listing style
1777 " COMBAK -- cuc cul related
1778 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001779
1780 " allow the user to override safe options
1781" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1782 if &ft == "netrw"
1783" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1784 keepalt NetrwKeepj doau FileType netrw
1785 endif
1786
1787" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1788" 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>"))
1789" call Dret("s:NetrwOptionsSafe")
1790endfun
1791
1792" ---------------------------------------------------------------------
1793" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1794fun! s:NetrwOptionsRestore(vt)
1795" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001796" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001797" 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 +01001798 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001799" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01001800 if filereadable(expand("%"))
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001801" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001802 filetype detect
1803" 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>"))
1804 else
1805 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001806 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001807" 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 +02001808" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001809 return
1810 endif
1811 unlet {a:vt}netrw_optionsave
1812
1813 if exists("+acd")
1814 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001815" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001816 let curdir = getcwd()
1817 let &l:acd = {a:vt}netrw_acdkeep
1818 unlet {a:vt}netrw_acdkeep
1819 if &l:acd
1820 call s:NetrwLcd(curdir)
1821 endif
1822 endif
1823 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001824" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001825 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1826 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1827 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1828 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1829 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001830" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001831 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1832 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1833 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1834 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1835 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001836" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001837 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1838 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1839 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1840 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1841 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001842 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001843" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1844 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1845 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001846 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001847 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1848" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1850 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1851" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1852 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1853" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1855 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001856 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001857 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1858 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1859" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1860 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1861 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1862 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1863 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1864" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001865 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001866 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1867 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1868 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001869 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001870" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001871 call s:NetrwRestoreSetting("s:yykeep","@@")
1872 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1873 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1874 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1875 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1876
Bram Moolenaara6878372014-03-22 21:02:50 +01001877 if exists("{a:vt}netrw_swfkeep")
1878 if &directory == ""
1879 " user hasn't specified a swapfile directory;
1880 " netrw will temporarily set the swapfile directory
1881 " to the current directory as returned by getcwd().
1882 let &l:directory= getcwd()
1883 sil! let &l:swf = {a:vt}netrw_swfkeep
1884 setl directory=
1885 unlet {a:vt}netrw_swfkeep
1886 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001887 if !g:netrw_use_noswf
1888 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1889 sil! let &l:swf= {a:vt}netrw_swfkeep
1890 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001891 unlet {a:vt}netrw_swfkeep
1892 endif
1893 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001894 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001895 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1896 if exists("{a:vt}netrw_dirkeep")
1897 call s:NetrwLcd(dirkeep)
1898 unlet {a:vt}netrw_dirkeep
1899 endif
1900 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001901 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001902" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001903 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1904 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001905 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001906 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001907
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001908" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1909" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1910" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1911" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1912" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001913 " Moved the filetype detect here from NetrwGetFile() because remote files
1914 " were having their filetype detect-generated settings overwritten by
1915 " NetrwOptionRestore.
1916 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001917" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1918 filetype detect
1919" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001920 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001921" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001922" 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 +02001923" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001924endfun
1925
1926" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001927" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1928" but only when the options' value and the safe setting differ
1929" Doing this means that netrw will not come up as having changed a
1930" setting last when it really didn't actually change it.
1931"
1932" Called from s:NetrwOptionsSafe
1933" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1934fun! s:NetrwSetSafeSetting(setting,safesetting)
1935" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001936
Bram Moolenaar85850f32019-07-19 22:05:51 +02001937 if a:setting =~ '^&'
1938" call Decho("fyi: a:setting starts with &")
1939 exe "let settingval= ".a:setting
1940" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001941
Bram Moolenaar85850f32019-07-19 22:05:51 +02001942 if settingval != a:safesetting
1943" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1944 if type(a:safesetting) == 0
1945 exe "let ".a:setting."=".a:safesetting
1946 elseif type(a:safesetting) == 1
1947 exe "let ".a:setting."= '".a:safesetting."'"
1948 else
1949 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1950 endif
1951 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001952 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001953
Bram Moolenaar85850f32019-07-19 22:05:51 +02001954" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001955endfun
1956
1957" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001958" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1959" but only if the setting value differs from the associated keepvar.
1960" Doing this means that netrw will not come up as having changed a
1961" setting last when it really didn't actually change it.
1962"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001963" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001964" keepvars are set up by s:NetrwOptionsSave
1965fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001966""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001967
Bram Moolenaar85850f32019-07-19 22:05:51 +02001968 " typically called from s:NetrwOptionsRestore
1969 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1970 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001971 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001972 if exists(a:keepvar)
1973 exe "let keepvarval= ".a:keepvar
1974 exe "let setting= ".a:setting
1975
1976"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1977"" call Decho("fyi: keepvarval=".keepvarval)
1978"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1979
1980 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001981"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001982 if type(a:setting) == 0
1983 exe "let ".a:setting."= ".keepvarval
1984 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001985 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001986 else
1987 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1988 endif
1989 endif
1990
1991 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001992 endif
1993
Bram Moolenaar85850f32019-07-19 22:05:51 +02001994"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001995endfun
1996
1997" ---------------------------------------------------------------------
1998" NetrwStatusLine: {{{2
1999fun! NetrwStatusLine()
2000
2001" vvv NetrwStatusLine() debugging vvv
2002" let g:stlmsg=""
2003" if !exists("w:netrw_explore_bufnr")
2004" let g:stlmsg="!X<explore_bufnr>"
2005" elseif w:netrw_explore_bufnr != bufnr("%")
2006" let g:stlmsg="explore_bufnr!=".bufnr("%")
2007" endif
2008" if !exists("w:netrw_explore_line")
2009" let g:stlmsg=" !X<explore_line>"
2010" elseif w:netrw_explore_line != line(".")
2011" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2012" endif
2013" if !exists("w:netrw_explore_list")
2014" let g:stlmsg=" !X<explore_list>"
2015" endif
2016" ^^^ NetrwStatusLine() debugging ^^^
2017
2018 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")
2019 " restore user's status line
2020 let &stl = s:netrw_users_stl
2021 let &laststatus = s:netrw_users_ls
2022 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2023 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2024 return ""
2025 else
2026 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2027 endif
2028endfun
2029
Bram Moolenaar85850f32019-07-19 22:05:51 +02002030" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002031" Netrw Transfer Functions: {{{1
2032" ===============================
2033
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002035" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002036" mode: =0 read remote file and insert before current line
2037" =1 read remote file and insert after current line
2038" =2 replace with remote file
2039" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002040fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002041" 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 +00002042
Bram Moolenaar5c736222010-01-06 20:54:52 +01002043 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002044 call s:NetrwOptionsSave("w:")
2045 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002046 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002047 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2048 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2049 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002050" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051
Bram Moolenaar5c736222010-01-06 20:54:52 +01002052 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002053 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002054 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002056 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057 elseif a:mode == 2 " replace with remote file
2058 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002059 elseif a:mode == 3 " skip read of file (leave as temporary)
2060 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002061 else
2062 exe a:mode
2063 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002065 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002066" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002067
Bram Moolenaar5c736222010-01-06 20:54:52 +01002068 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002069 let tmpfile= s:GetTempfile("")
2070 if tmpfile == ""
2071" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002072 return
2073 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002074
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 " attempt to repeat with previous host-file-etc
2078 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002079" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 let choice = b:netrw_lastfile
2081 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002082
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002083 else
2084 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002085" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002086
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002087 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002088 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002089 echomsg 'NetRead Usage:'
2090 echomsg ':Nread machine:path uses rcp'
2091 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2092 echomsg ':Nread "machine id password path" uses ftp'
2093 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2094 echomsg ':Nread fetch://machine/path uses fetch'
2095 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2096 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002097 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002098 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002099 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2100 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2101 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2102 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002103 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002104 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002105
Bram Moolenaar9964e462007-05-05 17:54:07 +00002106 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002107 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002108" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002109 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002111 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 else
2113 " case "... ... ..."
2114 let choice = strpart(choice,1,strlen(choice)-1)
2115 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002116
Bram Moolenaar9964e462007-05-05 17:54:07 +00002117 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002118 let wholechoice = wholechoice . " " . choice
2119 let ichoice = ichoice + 1
2120 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002121 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002122 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002123 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002124" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002125 return
2126 endif
2127 let choice= a:{ichoice}
2128 endwhile
2129 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2130 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 endif
2132 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002133
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002134" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002135 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002136
Bram Moolenaar5c736222010-01-06 20:54:52 +01002137 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002138 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002139 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002140" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002141 return
2142 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002143 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002144
Bram Moolenaar8d043172014-01-23 14:24:41 +01002145 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002146" 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 +02002147 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002148" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002149 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002150" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002151 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002152 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002153
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002155 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002156 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002157 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2158 echo "(netrw) Processing your read request..."
2159 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002160
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002162 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002164" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002165 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002167 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 " ER: the tmpfile is full path: rcp sees C:\... as host C
2169 if s:netrw_has_nt_rcp == 1
2170 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2171 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2172 else
2173 " Any way needed it machine contains a '.'
2174 let uid_machine = g:netrw_machine .'.'. $USERNAME
2175 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2178 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2179 else
2180 let uid_machine = g:netrw_machine
2181 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002182 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002183 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 +00002184 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002186
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002188 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002190" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002191 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002193 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002194 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002195 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002197 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002198 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002200 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002201 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204 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 +00002205 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002207 endif
2208 " 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 +00002209 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002210 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002211 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002212 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002213 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002214 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002215 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002216 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002217 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2218 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002219 q!
2220 endif
2221 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002222 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002224
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002226 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2228 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002229" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002230 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002231 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002232 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002233 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002235 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002236" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002238 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002239" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002240 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002241
Bram Moolenaar97d62492012-11-15 21:28:22 +01002242 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002243 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002244 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002249" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002250 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002251 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002252" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002254 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002255
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002257 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002260 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002261 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002262" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002263 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002264 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002265" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002266
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002267 " perform ftp:
2268 " -i : turns off interactive prompting from ftp
2269 " -n unix : DON'T use <.netrc>, even though it exists
2270 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002271 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002272 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2274 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002275" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002276 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002277 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002278 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002280 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002281 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002283
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002285 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002287" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002288 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002289 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002290 else
2291 let useport= ""
2292 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002293 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2294 " This is workaround to avoid mis-handle windows local-path:
2295 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2296 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2297 else
2298 let tmpfile_get = tmpfile
2299 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002300 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 +00002301 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002303
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002305 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002306 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002307" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002308 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002309 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002310 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002311 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002312" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002313 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002314 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002315
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002316 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2317 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002318" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002319 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320 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 +00002321 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002322 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 +00002323 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002324 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002325
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002327 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002329 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2330 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002331" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2332" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2333 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 +00002334 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002335" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002336 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002337 endif
2338 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002339" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002340 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002341
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002342 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002343 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002344 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002345" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaar5c736222010-01-06 20:54:52 +01002347 if !executable(g:netrw_dav_cmd)
2348 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2349" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2350 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002351 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002353 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 +01002354 else
2355 " Construct execution string (four lines) which will be passed through filter
2356 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2357 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002358 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002360 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002361 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002364 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002366 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2368 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002369
Bram Moolenaar5c736222010-01-06 20:54:52 +01002370 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002371 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002372 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002373 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002374 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002375 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002376 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002377
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002380 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002381" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002382 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 +00002383 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002384 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002385
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002387 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002389 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002390" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002392 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002393 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002394 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002395" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002396 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002397 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002398 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399 let netrw_option= "http"
2400 else
2401 let netrw_option= "ftp"
2402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002403" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002404
Bram Moolenaar446cb832008-06-24 21:56:24 +00002405 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002406 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 +00002407 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_fetch_cmd." ".s:ShellEscape(tmpfile,1)." ".s:ShellEscape(netrw_option."://".g:netrw_machine."/".b:netrw_fname,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002409 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002410
Bram Moolenaar446cb832008-06-24 21:56:24 +00002411 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002413" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002414 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002415
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002417 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002418 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002419" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2420 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 +00002421 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002422 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002423
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002424 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002425 " NetRead: (file) NetRead Method #10 {{{3
2426 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002427" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2428 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002429 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2430 let b:netrw_lastfile = choice
2431
2432 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002433 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002434 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002435 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 endif
2437 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002438
Bram Moolenaar5c736222010-01-06 20:54:52 +01002439 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002440 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002441" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002443 unlet b:netrw_fname
2444 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002445 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 +01002446" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002447 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002448 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002449 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002450
Bram Moolenaar9964e462007-05-05 17:54:07 +00002451" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002452endfun
2453
2454" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002455" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002456fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002457" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002458
Bram Moolenaar5c736222010-01-06 20:54:52 +01002459 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002460 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002461 call s:NetrwOptionsSave("w:")
2462 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002463
Bram Moolenaar5c736222010-01-06 20:54:52 +01002464 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002465 let tmpfile= s:GetTempfile("")
2466 if tmpfile == ""
2467" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002468 return
2469 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002470
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002471 if a:0 == 0
2472 let ichoice = 0
2473 else
2474 let ichoice = 1
2475 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002476
Bram Moolenaar9964e462007-05-05 17:54:07 +00002477 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002478" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002479 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002480 " For binary writes, always write entire file.
2481 " (line numbers don't really make sense for that).
2482 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002483" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002484 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 elseif g:netrw_cygwin
2486 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002487 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002488" 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 +01002489 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002490 else
2491 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002492" 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 +01002493 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002494 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002495
Bram Moolenaar9964e462007-05-05 17:54:07 +00002496 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002497 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002498 " on the temporary file's name. Deletion of the temporary file during
2499 " cleanup then causes an error message.
2500 0file!
2501 endif
2502
Bram Moolenaar5c736222010-01-06 20:54:52 +01002503 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002505
Bram Moolenaar9964e462007-05-05 17:54:07 +00002506 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002507 " attempt to repeat with previous host-file-etc
2508 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002509" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 let choice = b:netrw_lastfile
2511 let ichoice= ichoice + 1
2512 else
2513 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002514
Bram Moolenaar8d043172014-01-23 14:24:41 +01002515 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002516 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002517 echomsg 'NetWrite Usage:"'
2518 echomsg ':Nwrite machine:path uses rcp'
2519 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2520 echomsg ':Nwrite "machine id password path" uses ftp'
2521 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2522 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2523 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2524 echomsg ':Nwrite rcp://machine/path uses rcp'
2525 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2526 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2527 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002528 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002529 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002530
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002531 elseif match(choice,"^\"") != -1
2532 if match(choice,"\"$") != -1
2533 " case "..."
2534 let choice=strpart(choice,1,strlen(choice)-2)
2535 else
2536 " case "... ... ..."
2537 let choice = strpart(choice,1,strlen(choice)-1)
2538 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002539
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002540 while match(choice,"\"$") == -1
2541 let wholechoice= wholechoice . " " . choice
2542 let ichoice = ichoice + 1
2543 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002544 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002545 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002546 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002547" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002548 return
2549 endif
2550 let choice= a:{ichoice}
2551 endwhile
2552 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2553 endif
2554 endif
2555 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002556 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002557" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002558
Bram Moolenaar9964e462007-05-05 17:54:07 +00002559 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002560 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002561 if !exists("b:netrw_method") || b:netrw_method < 0
2562" call Dfunc("netrw#NetWrite : unsupported method")
2563 return
2564 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002565
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002566 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002567 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002568 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002569 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2570 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002571" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002572 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002573
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002574 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002575 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002576 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002577" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002578 if s:netrw_has_nt_rcp == 1
2579 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2580 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2581 else
2582 let uid_machine = g:netrw_machine .'.'. $USERNAME
2583 endif
2584 else
2585 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2586 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2587 else
2588 let uid_machine = g:netrw_machine
2589 endif
2590 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002591 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 +00002592 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002593
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002594 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002595 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002596 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002597" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002598 let netrw_fname = b:netrw_fname
2599
2600 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2601 let bhkeep = &l:bh
2602 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002603 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002605
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002607 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002608 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002610 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002611 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002613 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002615" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617 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 +00002618 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002619" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2620 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 endif
2622 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2623 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002624 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002625 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002626 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002627 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002629
2630 " remove enew buffer (quietly)
2631 let filtbuf= bufnr("%")
2632 exe curbuf."b!"
2633 let &l:bh = bhkeep
2634 exe filtbuf."bw!"
2635
Bram Moolenaar071d4272004-06-13 20:20:40 +00002636 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002637
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002638 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002640 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002642" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643 let netrw_fname = b:netrw_fname
2644 let bhkeep = &l:bh
2645
2646 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2647 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002648 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002649 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002650 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002651
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002653 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002656 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002657" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002658 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 if exists("g:netrw_uid") && g:netrw_uid != ""
2660 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002663 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002667 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002668 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002670 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002671 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002672 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002674 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002675 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002677 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002678 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002679" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002680 " save choice/id/password for future use
2681 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002682
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002683 " perform ftp:
2684 " -i : turns off interactive prompting from ftp
2685 " -n unix : DON'T use <.netrc>, even though it exists
2686 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002687 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002688 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002689 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2690 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002691 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002692 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002693 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002694 let mod=1
2695 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002696
2697 " remove enew buffer (quietly)
2698 let filtbuf= bufnr("%")
2699 exe curbuf."b!"
2700 let &l:bh= bhkeep
2701 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002702
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002703 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002704 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002705 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002707 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002708 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 else
2710 let useport= ""
2711 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002712 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 +00002713 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002714
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002715 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002716 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002717 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002718" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002719 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2720 if executable(curl)
2721 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002722 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 +01002723 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002724 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002725 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002726
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002727 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002728 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002729 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002730" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002731
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002732 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2734 let bhkeep = &l:bh
2735
2736 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2737 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002738 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002739 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002740
Bram Moolenaarff034192013-04-24 18:51:19 +02002741 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002742 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002743 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002744 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002745 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002746 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002747 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002749 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002751
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002752 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002753 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002754 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002755
2756 " remove enew buffer (quietly)
2757 let filtbuf= bufnr("%")
2758 exe curbuf."b!"
2759 let &l:bh = bhkeep
2760 exe filtbuf."bw!"
2761
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002762 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002763
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002764 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002765 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002766 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002767" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002768 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 +00002769 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002770
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002771 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002772 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002773 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002774" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002775 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2777 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2778 else
2779 let uid_machine = g:netrw_machine
2780 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002781
2782 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2783 let bhkeep = &l:bh
2784 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002785 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002787
Bram Moolenaarff034192013-04-24 18:51:19 +02002788 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002790" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002791 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002792 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002793 let filtbuf= bufnr("%")
2794 exe curbuf."b!"
2795 let &l:bh = bhkeep
2796 exe filtbuf."bw!"
2797 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002798
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002799 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002800 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002801 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002802 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002803 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002804 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002805 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002806
Bram Moolenaar5c736222010-01-06 20:54:52 +01002807 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002808" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002809 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002811 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002813 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002814
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002815 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002816 " restore modifiability; usually equivalent to set nomod
2817 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002818" 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 +02002819 elseif !exists("leavemod")
2820 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002822 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002825
Bram Moolenaar9964e462007-05-05 17:54:07 +00002826" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002827endfun
2828
2829" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002830" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002831" uses NetRead to get a copy of the file into a temporarily file,
2832" then sources that file,
2833" then removes that file.
2834fun! netrw#NetSource(...)
2835" call Dfunc("netrw#NetSource() a:0=".a:0)
2836 if a:0 > 0 && a:1 == '?'
2837 " give help
2838 echomsg 'NetSource Usage:'
2839 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2840 echomsg ':Nsource fetch://machine/path uses fetch'
2841 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002842 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002843 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2844 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2845 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2846 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2847 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002848 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002850 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002851 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002854" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002855 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002856" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002857 if delete(s:netrw_tmpfile)
2858 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2859 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002860 unlet s:netrw_tmpfile
2861 else
2862 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2863 endif
2864 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002865 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002866 endif
2867" call Dret("netrw#NetSource")
2868endfun
2869
Bram Moolenaar8d043172014-01-23 14:24:41 +01002870" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002871" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2872" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002873fun! netrw#SetTreetop(iscmd,...)
2874" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2875" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002876
Bram Moolenaar85850f32019-07-19 22:05:51 +02002877 " iscmd==0: netrw#SetTreetop called using gn mapping
2878 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2879" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002880 " clear out the current tree
2881 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002882" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002883 let inittreetop= w:netrw_treetop
2884 unlet w:netrw_treetop
2885 endif
2886 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002888 unlet w:netrw_treedict
2889 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002890" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002891
Bram Moolenaar85850f32019-07-19 22:05:51 +02002892 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002893 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002895 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896 if isdirectory(s:NetrwFile(a:1))
2897" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002898 let treedir = a:1
2899 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002900 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002901 let treedir = b:netrw_curdir."/".a:1
2902 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002903" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002904 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905 " normally the cursor is left in the message window.
2906 " However, here this results in the directory being listed in the message window, which is not wanted.
2907 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002908 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002909 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002910 let treedir = "."
2911 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002912 endif
2913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002915
2916 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002917 let islocal= expand("%") !~ '^\a\{3,}://'
2918" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002919
2920 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002921 if islocal
2922 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2923 else
2924 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2925 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002926
Bram Moolenaara6878372014-03-22 21:02:50 +01002927" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002928endfun
2929
Bram Moolenaar9964e462007-05-05 17:54:07 +00002930" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002931" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932" readcmd == %r : replace buffer with newly read file
2933" == 0r : read file at top of buffer
2934" == r : read file after current line
2935" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002936fun! s:NetrwGetFile(readcmd, tfile, method)
2937" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002938
2939 " readcmd=='t': simply do nothing
2940 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002941" 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 +01002942" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002943 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002944 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002945
Bram Moolenaar9964e462007-05-05 17:54:07 +00002946 " get name of remote filename (ie. url and all)
2947 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002948" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002949
Bram Moolenaar9964e462007-05-05 17:54:07 +00002950 if exists("*NetReadFixup")
2951 " for the use of NetReadFixup (not otherwise used internally)
2952 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002953 endif
2954
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 if a:readcmd[0] == '%'
2956 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002957" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958
2959 " rename the current buffer to the temp file (ie. tfile)
2960 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002961 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002962 else
2963 let tfile= a:tfile
2964 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002965 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002966
2967 " edit temporary file (ie. read the temporary file in)
2968 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002970 call zip#Browse(tfile)
2971 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002974 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002977 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002980 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 call tar#Browse(tfile)
2983 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002984" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002985 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002986 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002988 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002989 endif
2990
2991 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002992 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002993
Bram Moolenaar71badf92023-04-22 22:40:14 +01002994 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002995 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002996 " Note that isk must not include a "/" for scripts.vim
2997 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002998" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2999" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003000" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003001" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3002 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003003 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003004 filetype detect
3005" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3006 let &isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003007" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003008 let line1 = 1
3009 let line2 = line("$")
3010
Bram Moolenaar8d043172014-01-23 14:24:41 +01003011 elseif !&ma
3012 " 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 +01003013 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003014" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003015 return
3016
Bram Moolenaar9964e462007-05-05 17:54:07 +00003017 elseif s:FileReadable(a:tfile)
3018 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003020 let curline = line(".")
3021 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003022" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003023 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003024 let line1= curline + 1
3025 let line2= line("$") - lastline + 1
3026
3027 else
3028 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003029" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3030" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003031 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003032" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003033 return
3034 endif
3035
3036 " User-provided (ie. optional) fix-it-up command
3037 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003039 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003040" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003041" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003042 endif
3043
Bram Moolenaaradc21822011-04-01 18:03:16 +02003044 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003045 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003046 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003047 endif
3048
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003049" 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 +00003050
3051 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003052" redraw!
3053
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003054" 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 +00003055" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003056endfun
3057
Bram Moolenaar9964e462007-05-05 17:54:07 +00003058" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003059" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003060" Input:
3061" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3062" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003063" b:netrw_method= 1: rcp
3064" 2: ftp + <.netrc>
3065" 3: ftp + machine, id, password, and [path]filename
3066" 4: scp
3067" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003068" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003069" 7: rsync
3070" 8: fetch
3071" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003072" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003073" g:netrw_machine= hostname
3074" b:netrw_fname = filename
3075" g:netrw_port = optional port number (for ftp)
3076" g:netrw_choice = copy of input url (choice)
3077fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003078" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003079
Bram Moolenaar251e1912011-06-19 05:09:16 +02003080 " sanity check: choice should have at least three slashes in it
3081 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3082 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3083 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003084" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003085 return
3086 endif
3087
Bram Moolenaar5c736222010-01-06 20:54:52 +01003088 " record current g:netrw_machine, if any
3089 " curmachine used if protocol == ftp and no .netrc
3090 if exists("g:netrw_machine")
3091 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003092" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003093 else
3094 let curmachine= "N O T A HOST"
3095 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003096 if exists("g:netrw_port")
3097 let netrw_port= g:netrw_port
3098 endif
3099
3100 " insure that netrw_ftp_cmd starts off every method determination
3101 " with the current g:netrw_ftp_cmd
3102 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003103
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 " initialization
3105 let b:netrw_method = 0
3106 let g:netrw_machine = ""
3107 let b:netrw_fname = ""
3108 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003109 let g:netrw_choice = a:choice
3110
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003112 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003113 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3114 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003115 " rcpurm : rcp://[user@]host/filename Use rcp
3116 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003118 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003119 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 " rsyncurm : rsync://host[:port]/path Use rsync
3121 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3122 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003123 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3125 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003126 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3127 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003129 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003130 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003131 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003132 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003133 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003135 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003136
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003137" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003139 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003140 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003141" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003142 let b:netrw_method = 1
3143 let userid = substitute(a:choice,rcpurm,'\1',"")
3144 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3145 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003146 if userid != ""
3147 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003149
Bram Moolenaaradc21822011-04-01 18:03:16 +02003150 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003152" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003153 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003154 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3155 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3156 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003157
Bram Moolenaar15146672011-10-20 22:22:38 +02003158 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003159 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003160" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 let b:netrw_method = 5
3162 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3163 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003164 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003165
Bram Moolenaaradc21822011-04-01 18:03:16 +02003166 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003167 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003168" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003169 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003170 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003171 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3172 else
3173 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3174 endif
3175 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003176
Bram Moolenaaradc21822011-04-01 18:03:16 +02003177 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003179" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 let b:netrw_method = 7
3181 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3182 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003183
Bram Moolenaaradc21822011-04-01 18:03:16 +02003184 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003186" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003187 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003188 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3189 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3190 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003191" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003192 if userid != ""
3193 let g:netrw_uid= userid
3194 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003195
Bram Moolenaaradc21822011-04-01 18:03:16 +02003196 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003197 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003198 call NetUserPass("ftp:".g:netrw_machine)
3199 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003200 " if there's a change in hostname, require password re-entry
3201 unlet s:netrw_passwd
3202 endif
3203 if exists("netrw_port")
3204 unlet netrw_port
3205 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003206 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003207
Bram Moolenaar446cb832008-06-24 21:56:24 +00003208 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003209 let b:netrw_method = 3
3210 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003211 let host= substitute(g:netrw_machine,'\..*$','','')
3212 if exists("s:netrw_hup[host]")
3213 call NetUserPass("ftp:".host)
3214
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003215 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003216" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3217" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003218 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003219 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003220" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003221 endif
3222 let b:netrw_method= 2
3223 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003224" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003225 let b:netrw_method= 2
3226 else
3227 if !exists("g:netrw_uid") || g:netrw_uid == ""
3228 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003229 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003231 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003232 endif
3233 let b:netrw_method= 3
3234 endif
3235 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003236
Bram Moolenaaradc21822011-04-01 18:03:16 +02003237 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003238 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003239" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003240 let b:netrw_method = 8
3241 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3242 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3243 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3244 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003245
Bram Moolenaaradc21822011-04-01 18:03:16 +02003246 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003247 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003248" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003250 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3251 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003252 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003254 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003255
Bram Moolenaaradc21822011-04-01 18:03:16 +02003256 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003257 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003258" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003259 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003260 let b:netrw_method = 3
3261 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3262 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003263
Bram Moolenaar9964e462007-05-05 17:54:07 +00003264 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003265 let b:netrw_method = 2
3266 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3267 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3268 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003269
Bram Moolenaaradc21822011-04-01 18:03:16 +02003270 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003271 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003272" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003273 let b:netrw_method = 9
3274 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3275 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003276
Bram Moolenaaradc21822011-04-01 18:03:16 +02003277 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003278 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003279" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003280 let b:netrw_method = 1
3281 let userid = substitute(a:choice,rcphf,'\2',"")
3282 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3283 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003284" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3285" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3286" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3287" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003288 if userid != ""
3289 let g:netrw_uid= userid
3290 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003291
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003292 " Method#10: file://user@hostname/...path-to-file {{{3
3293 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003294" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003295 let b:netrw_method = 10
3296 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003297" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003298
Bram Moolenaaradc21822011-04-01 18:03:16 +02003299 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003300 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003301 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003302 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003303 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003304 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003306 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003307
Bram Moolenaar81695252004-12-29 20:58:21 +00003308 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003309 " remove any leading [:#] from port number
3310 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3311 elseif exists("netrw_port")
3312 " retain port number as implicit for subsequent ftp operations
3313 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003314 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003315
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003316" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3317" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3318" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3319" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003320" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003322" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003323" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003324" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003325" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003327" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329
3330" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003331" NetReadFixup: this sort of function is typically written by the user {{{2
3332" to handle extra junk that their system's ftp dumps
3333" into the transfer. This function is provided as an
3334" example and as a fix for a Windows 95 problem: in my
3335" experience, win95's ftp always dumped four blank lines
3336" at the end of the transfer.
3337if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3338 fun! NetReadFixup(method, line1, line2)
3339" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003340
3341 " sanity checks -- attempt to convert inputs to integers
3342 let method = a:method + 0
3343 let line1 = a:line1 + 0
3344 let line2 = a:line2 + 0
3345 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3346" call Dret("NetReadFixup")
3347 return
3348 endif
3349
Bram Moolenaar9964e462007-05-05 17:54:07 +00003350 if method == 3 " ftp (no <.netrc>)
3351 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003352 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003353 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003354 call histdel("/",-1)
3355 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003356 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003357
Bram Moolenaar9964e462007-05-05 17:54:07 +00003358" call Dret("NetReadFixup")
3359 endfun
3360endif
3361
3362" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003363" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003364" Usage: :call NetUserPass() -- will prompt for userid and password
3365" :call NetUserPass("uid") -- will prompt for password
3366" :call NetUserPass("uid","password") -- sets global userid and password
3367" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3368" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369fun! NetUserPass(...)
3370
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003371" call Dfunc("NetUserPass() a:0=".a:0)
3372
3373 if !exists('s:netrw_hup')
3374 let s:netrw_hup= {}
3375 endif
3376
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003378 " case: no input arguments
3379
3380 " change host and username if not previously entered; get new password
3381 if !exists("g:netrw_machine")
3382 let g:netrw_machine= input('Enter hostname: ')
3383 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003385 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003386 let g:netrw_uid= input('Enter username: ')
3387 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003388 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003389 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003390
3391 " set up hup database
3392 let host = substitute(g:netrw_machine,'\..*$','','')
3393 if !exists('s:netrw_hup[host]')
3394 let s:netrw_hup[host]= {}
3395 endif
3396 let s:netrw_hup[host].uid = g:netrw_uid
3397 let s:netrw_hup[host].passwd = s:netrw_passwd
3398
3399 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003400 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003401
3402 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003403 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003404 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003405" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003406 let host = substitute(a:1,'^ftp:','','')
3407 let host = substitute(host,'\..*','','')
3408 if exists("s:netrw_hup[host]")
3409 let g:netrw_uid = s:netrw_hup[host].uid
3410 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003411" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3412" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003413 else
3414 let g:netrw_uid = input("Enter UserId: ")
3415 let s:netrw_passwd = inputsecret("Enter Password: ")
3416 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003417
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003418 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003419 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003420" 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 +02003421 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003422 if g:netrw_machine =~ '[0-9.]\+'
3423 let host= g:netrw_machine
3424 else
3425 let host= substitute(g:netrw_machine,'\..*$','','')
3426 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003427 else
3428 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003429 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003430 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003431" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003432 if exists("g:netrw_passwd")
3433 " ask for password if one not previously entered
3434 let s:netrw_passwd= g:netrw_passwd
3435 else
3436 let s:netrw_passwd = inputsecret("Enter Password: ")
3437 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003438 endif
3439
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003440" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003441 if exists("host")
3442 if !exists('s:netrw_hup[host]')
3443 let s:netrw_hup[host]= {}
3444 endif
3445 let s:netrw_hup[host].uid = g:netrw_uid
3446 let s:netrw_hup[host].passwd = s:netrw_passwd
3447 endif
3448
3449 elseif a:0 == 2
3450 let g:netrw_uid = a:1
3451 let s:netrw_passwd = a:2
3452
3453 elseif a:0 == 3
3454 " enter hostname, user-id, and password into the hup dictionary
3455 let host = substitute(a:1,'^\a\+:','','')
3456 let host = substitute(host,'\..*$','','')
3457 if !exists('s:netrw_hup[host]')
3458 let s:netrw_hup[host]= {}
3459 endif
3460 let s:netrw_hup[host].uid = a:2
3461 let s:netrw_hup[host].passwd = a:3
3462 let g:netrw_uid = s:netrw_hup[host].uid
3463 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003464" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3465" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003467
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003468" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470
Bram Moolenaar85850f32019-07-19 22:05:51 +02003471" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003472" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003473" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003474
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003475" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003476" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3477fun! s:ExplorePatHls(pattern)
3478" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3479 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003480" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003481 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003482" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003483 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3484" call Dret("s:ExplorePatHls repat<".repat.">")
3485 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003486endfun
3487
3488" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003489" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003490" 0: (user: <mb>) bookmark current directory
3491" 1: (user: <gb>) change to the bookmarked directory
3492" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003493" 3: (browsing) records current directory history
3494" 4: (user: <u>) go up (previous) directory, using history
3495" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003496" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003497fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003498" 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 +02003499 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3500" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3501 return
3502 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003503
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003504 let ykeep = @@
3505 let curbufnr = bufnr("%")
3506
Bram Moolenaar9964e462007-05-05 17:54:07 +00003507 if a:chg == 0
3508 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003509" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003510 if exists("s:netrwmarkfilelist_{curbufnr}")
3511 call s:NetrwBookmark(0)
3512 echo "bookmarked marked files"
3513 else
3514 call s:MakeBookmark(a:curdir)
3515 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003516 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003517
KSR-Yasudaf4498252023-10-06 03:34:17 +09003518 try
3519 call s:NetrwBookHistSave()
3520 catch
3521 endtry
3522
Bram Moolenaar9964e462007-05-05 17:54:07 +00003523 elseif a:chg == 1
3524 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003525" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003526 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003527" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003528 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003529 else
3530 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3531 endif
3532
3533 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003534" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003535 let didwork= 0
3536 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003537" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003538 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003539" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003540 let cnt= 1
3541 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003542" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003543 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003544 let didwork = 1
3545 let cnt = cnt + 1
3546 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003547 endif
3548
3549 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550 " Note: history is saved only when PerformListing is done;
3551 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3552 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003553 let first = 1
3554 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003555 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556 while ( first || cnt != g:netrw_dirhistcnt )
3557" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003558 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003559" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003560 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003561 let didwork= 1
3562 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003563 let histcnt = histcnt + 1
3564 let first = 0
3565 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003566 if cnt < 0
3567 let cnt= cnt + g:netrw_dirhistmax
3568 endif
3569 endwhile
3570 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003571 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003572 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003573 if didwork
3574 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3575 endif
3576
3577 elseif a:chg == 3
3578 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003579" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003580 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 +02003581 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003582 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3583 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003584 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003585" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003586 endif
3587
3588 elseif a:chg == 4
3589 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003590" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003591 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003592 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3593 if g:netrw_dirhistcnt < 0
3594 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003595 endif
3596 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003597 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003598 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003599 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3600" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003601 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003602 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003603" call Decho("setl ma noro",'~'.expand("<slnum>"))
3604 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003605 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003606" call Decho("setl nomod",'~'.expand("<slnum>"))
3607" 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 +00003608 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003609" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3610 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003611 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003612 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003613 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003614 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003615 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003616 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003617 echo "Sorry, no predecessor directory exists yet"
3618 endif
3619
3620 elseif a:chg == 5
3621 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003622" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003623 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003624 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3625 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3626" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003627 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003628" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003629 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630 sil! NetrwKeepj %d _
3631" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3632" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003633 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003634" 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 +02003635 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003636" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3637 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003638 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003639 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3640 if g:netrw_dirhistcnt < 0
3641 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003642 endif
3643 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003644 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003645 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003646 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003647 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003648 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003649
3650 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003651" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003652 if exists("s:netrwmarkfilelist_{curbufnr}")
3653 call s:NetrwBookmark(1)
3654 echo "removed marked files from bookmarks"
3655 else
3656 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003657 let iremove = v:count
3658 let dremove = g:netrw_bookmarklist[iremove - 1]
3659" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003660 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003661" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3662 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3663 echo "removed ".dremove." from g:netrw_bookmarklist"
3664" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003666" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003667
3668 try
3669 call s:NetrwBookHistSave()
3670 catch
3671 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003672 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003673 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003674 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003675 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003676" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003677endfun
3678
3679" ---------------------------------------------------------------------
3680" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003681" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003682" Sister function: s:NetrwBookHistSave()
3683fun! s:NetrwBookHistRead()
3684" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003685 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003686" 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 +02003687 return
3688 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003689 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003690
3691 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003692 if !exists("s:netrw_initbookhist")
3693 let home = s:NetrwHome()
3694 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003695 if filereadable(s:NetrwFile(savefile))
3696" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003697 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699
3700 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003701 if g:netrw_dirhistmax > 0
3702 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003703 if filereadable(s:NetrwFile(savefile))
3704" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003705 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003706 endif
3707 let s:netrw_initbookhist= 1
3708 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003709 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003710 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003711
Bram Moolenaar97d62492012-11-15 21:28:22 +01003712 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003713" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3714" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003715" call Dret("s:NetrwBookHistRead")
3716endfun
3717
3718" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003719" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003720" Sister function: s:NetrwBookHistRead()
3721" I used to do this via viminfo but that appears to
3722" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003723" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3724" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003725" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003726fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003727" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003728 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003729" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003730 return
3731 endif
3732
Bram Moolenaar5c736222010-01-06 20:54:52 +01003733 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003734" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003735 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003736
3737 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003738 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003739" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003740 if g:netrw_use_noswf
3741 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3742 else
3743 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3744 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003745 setl nocin noai noci magic nospell nohid wig= noaw
3746 setl ma noro write
3747 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003748 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749
Bram Moolenaar85850f32019-07-19 22:05:51 +02003750 " rename enew'd file: .netrwhist -- no attempt to merge
3751 " record dirhistmax and current dirhistcnt
3752 " save history
3753" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003754 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003755 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003756 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3757 if g:netrw_dirhistmax > 0
3758 let lastline = line("$")
3759 let cnt = g:netrw_dirhistcnt
3760 let first = 1
3761 while ( first || cnt != g:netrw_dirhistcnt )
3762 let lastline= lastline + 1
3763 if exists("g:netrw_dirhist_{cnt}")
3764 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3765" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3766 endif
3767 let first = 0
3768 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3769 if cnt < 0
3770 let cnt= cnt + g:netrw_dirhistmax
3771 endif
3772 endwhile
3773 exe "sil! w! ".savefile
3774" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3775 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003776
Bram Moolenaar85850f32019-07-19 22:05:51 +02003777 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003778 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003779 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003780" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003781 " merge and write .netrwbook
3782 let savefile= s:NetrwHome()."/.netrwbook"
3783
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003784 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003785 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003786 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003787 for bdm in booklist
3788 if index(g:netrw_bookmarklist,bdm) == -1
3789 call add(g:netrw_bookmarklist,bdm)
3790 endif
3791 endfor
3792 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003793 endif
3794
3795 " construct and save .netrwbook
3796 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003797 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003798" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003799 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003800
3801 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 let bgone= bufnr("%")
3803 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003804 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003805
3806" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003807endfun
3808
3809" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003810" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3811" list of the contents of a local or remote directory. It is assumed that the
3812" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3813" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003814" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003815fun! s:NetrwBrowse(islocal,dirname)
3816 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003817" 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 +02003818" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3819" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3820" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003821
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003822 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3823 " This is useful when one edits a local file, then :e ., then :Rex
3824 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3825 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003826" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003827 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003828
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 " s:NetrwBrowse : initialize history {{{3
3830 if !exists("s:netrw_initbookhist")
3831 NetrwKeepj call s:NetrwBookHistRead()
3832 endif
3833
3834 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003835 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003836 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003837" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003838 else
3839 let dirname= a:dirname
3840 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003841
Bram Moolenaar85850f32019-07-19 22:05:51 +02003842 " repoint t:netrw_lexbufnr if appropriate
3843 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3844" call Decho("set repointlexbufnr to true!")
3845 let repointlexbufnr= 1
3846 endif
3847
3848 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003849 if exists("s:netrw_skipbrowse")
3850 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003851" 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 +01003852" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853 return
3854 endif
3855 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003857" call Dret("s:NetrwBrowse : missing shellescape()")
3858 return
3859 endif
3860 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003862" call Dret("s:NetrwBrowse : missing fnameescape()")
3863 return
3864 endif
3865
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003867 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003868
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003870 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3871 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3872" call Decho("clearing marked files",'~'.expand("<slnum>"))
3873 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3874 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003875 endif
3876
3877 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003878 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003879" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3880" 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 +02003881 if s:NetrwLcd(dirname)
3882" call Dret("s:NetrwBrowse : lcd failure")
3883 return
3884 endif
3885 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003886" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003887
Bram Moolenaar5c736222010-01-06 20:54:52 +01003888 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003889 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003890" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003891 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003892" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003893 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003894 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003895 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003896" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003897
3898 " remove any filetype indicator from end of dirname, except for the
3899 " "this is a directory" indicator (/).
3900 " There shouldn't be one of those here, anyway.
3901 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003902" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003903 call s:RemotePathAnalysis(dirname)
3904
3905 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3906 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003907 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003908 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003909" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003910 let b:netrw_curdir = dirname
3911 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003912 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003913 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3914 sil call netrw#NetRead(2,url)
3915 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003916" call Decho("url<".url.">",'~'.expand("<slnum>"))
3917" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3918" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003919 if s:path =~ '.bz2'
3920 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3921 elseif s:path =~ '.gz'
3922 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3923 elseif s:path =~ '.gz'
3924 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3925 else
3926 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3927 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003928 endif
3929
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003930 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003931 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003932 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003933" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003934 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935" 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 +00003936
Bram Moolenaar446cb832008-06-24 21:56:24 +00003937" call Dret("s:NetrwBrowse : file<".s:fname.">")
3938 return
3939 endif
3940
Bram Moolenaaradc21822011-04-01 18:03:16 +02003941 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003942 call s:UseBufWinVars()
3943
3944 " set up some variables {{{3
3945 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003946 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947 let s:last_sort_by = g:netrw_sort_by
3948
3949 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003950 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003951
Bram Moolenaar97d62492012-11-15 21:28:22 +01003952 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003953" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003954 let svpos = winsaveview()
3955" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003956 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003957
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003959 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3960 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3961" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3962" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3963 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3964 else
3965" " call Decho("2match none",'~'.expand("<slnum>"))
3966 2match none
3967 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003968 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003969 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003970 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003971" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003972 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" 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 +01003974" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003975 return
3976 endif
3977
3978 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003980 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981 if b:netrw_curdir =~ '[/\\]$'
3982 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3983 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003984 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3985 let b:netrw_curdir= b:netrw_curdir."/"
3986 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003987 if b:netrw_curdir == ''
3988 if has("amiga")
3989 " On the Amiga, the empty string connotes the current directory
3990 let b:netrw_curdir= getcwd()
3991 else
3992 " under unix, when the root directory is encountered, the result
3993 " from the preceding substitute is an empty string.
3994 let b:netrw_curdir= '/'
3995 endif
3996 endif
3997 if !a:islocal && b:netrw_curdir !~ '/$'
3998 let b:netrw_curdir= b:netrw_curdir.'/'
3999 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001
4002 " ------------
4003 " (local only) {{{3
4004 " ------------
4005 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007
4008 " Set up ShellCmdPost handling. Append current buffer to browselist
4009 call s:LocalFastBrowser()
4010
4011 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
4012 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004013" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
4014" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004015 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004016 if s:NetrwLcd(b:netrw_curdir)
4017" call Dret("s:NetrwBrowse : lcd failure")
4018 return
4019 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004020 endif
4021 endif
4022
4023 " --------------------------------
4024 " remote handling: {{{3
4025 " --------------------------------
4026 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004027" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004028
Bram Moolenaar97d62492012-11-15 21:28:22 +01004029 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004030" 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 +02004031 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004032 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004034 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4035 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4036 if dirname !~ '/$'
4037 let dirname= dirname.'/'
4038 endif
4039 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004040" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004041 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004042 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004044 endif
4045
4046 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4047 if dirname !~ dirpat
4048 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004049 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004050 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004051 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004052" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004053 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054" 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 +00004055" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4056 return
4057 endif
4058 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004060 endif " (additional remote handling)
4061
Bram Moolenaar85850f32019-07-19 22:05:51 +02004062 " -------------------------------
4063 " Perform Directory Listing: {{{3
4064 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004065 NetrwKeepj call s:NetrwMaps(a:islocal)
4066 NetrwKeepj call s:NetrwCommands(a:islocal)
4067 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004068
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004069 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004070 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004071" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4072
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004073 " If there is a rexposn: restore position with rexposn
4074 " Otherwise : set rexposn
4075 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004076" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4077 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4078 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4079 NetrwKeepj exe w:netrw_bannercnt
4080 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004081 else
4082 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4083 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004084 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004085 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004086" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004087 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004088 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004089
Bram Moolenaar85850f32019-07-19 22:05:51 +02004090 " repoint t:netrw_lexbufnr if appropriate
4091 if exists("repointlexbufnr")
4092 let t:netrw_lexbufnr= bufnr("%")
4093" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4094 endif
4095
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004096 " restore position
4097 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004098" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4099 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004100 endif
4101
Bram Moolenaara6878372014-03-22 21:02:50 +01004102 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004103 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4104 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4106" 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 +02004107" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004108 return
4109endfun
4110
4111" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004112" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4113" may not apply correctly; ie. netrw's idea of the current directory may
4114" differ from vim's. This function insures that netrw's idea of the current
4115" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004116" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004118" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4119" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4120" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4121" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4122" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004123
4124 " clean up any leading treedepthstring
4125 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4126 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004127" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004128 else
4129 let fname= a:fname
4130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131
4132 if g:netrw_keepdir
4133 " vim's idea of the current directory possibly may differ from netrw's
4134 if !exists("b:netrw_curdir")
4135 let b:netrw_curdir= getcwd()
4136 endif
4137
4138 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004139 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004140 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004141 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004142" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004143 else
4144 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004145 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004146" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004147 endif
4148
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004149 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004150 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004152" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004153 else
4154 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004155 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004156" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157 endif
4158 else
4159 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004161" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4162" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4163" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164 endif
4165
Bram Moolenaar85850f32019-07-19 22:05:51 +02004166" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004167 return ret
4168endfun
4169
4170" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004171" s:NetrwFileInfo: supports qf (query for file information) {{{2
4172fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004173" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004174 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004175 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004176 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004177 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004178 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004179 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004180 let lsopt= "-lsadh --si"
4181 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004182" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004183 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004184
4185 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004186 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004187" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004188
Bram Moolenaara6878372014-03-22 21:02:50 +01004189 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004190 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004191" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004192
4193 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004194 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004195" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004196
Bram Moolenaar446cb832008-06-24 21:56:24 +00004197 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004198" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004199 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004200" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004201 endif
4202 else
4203 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004204" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4205 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206 let fname= substitute(a:fname,".$","","")
4207 else
4208 let fname= a:fname
4209 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004210 let t = getftime(s:NetrwFile(fname))
4211 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004212 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004213 let sz= s:NetrwHumanReadable(sz)
4214 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004215 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4216" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004217 endif
4218 else
4219 echo "sorry, \"qf\" not supported yet for remote files"
4220 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004221 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004222" call Dret("s:NetrwFileInfo")
4223endfun
4224
4225" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004226" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4227fun! s:NetrwFullPath(filename)
4228" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4229 let filename= a:filename
4230 if filename !~ '^/'
4231 let filename= resolve(getcwd().'/'.filename)
4232 endif
4233 if filename != "/" && filename =~ '/$'
4234 let filename= substitute(filename,'/$','','')
4235 endif
4236" " call Dret("s:NetrwFullPath <".filename.">")
4237 return filename
4238endfun
4239
4240" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004241" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004242" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004243" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004244" 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 +00004245fun! s:NetrwGetBuffer(islocal,dirname)
4246" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004247" 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 +02004248" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4249" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004250 let dirname= a:dirname
4251
4252 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004253" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004254 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004256 let s:netrwbuf= {}
4257 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4259" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4260
4261 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4262 let bufnum = -1
4263
4264 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4265 if has_key(s:netrwbuf,"NetrwTreeListing")
4266 let bufnum= s:netrwbuf["NetrwTreeListing"]
4267 else
4268 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4269 endif
4270" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4271 if !bufexists(bufnum)
4272 call remove(s:netrwbuf,"NetrwTreeListing"])
4273 let bufnum= -1
4274 endif
4275 elseif bufnr("NetrwTreeListing") != -1
4276 let bufnum= bufnr("NetrwTreeListing")
4277" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4278 else
4279" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4280 let bufnum= -1
4281 endif
4282
4283 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004284 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004285" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004286 if !bufexists(bufnum)
4287 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4288 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004289 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004290
Bram Moolenaar446cb832008-06-24 21:56:24 +00004291 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004292" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004293 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004294 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004295" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4296
Bram Moolenaar71badf92023-04-22 22:40:14 +01004297 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004298 " IF the buffer already has the desired name
4299 " AND it is empty
4300 let curbuf = bufname("%")
4301 if curbuf == '.'
4302 let curbuf = getcwd()
4303 endif
4304" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004305" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004306" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4307" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4308" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4309" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4310 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004311" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4312 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004313 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004314" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004315 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004316 " 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 +00004317
4318 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004319 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004320" 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 +00004321 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004322" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323 " name the buffer
4324 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4325 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004326" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004327 let w:netrw_treebufnr = bufnr("%")
4328 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004329 if g:netrw_use_noswf
4330 setl nobl bt=nofile noswf
4331 else
4332 setl nobl bt=nofile
4333 endif
4334 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4335 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4336 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4337 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004338" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004339 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004340 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004341 " enter the new buffer into the s:netrwbuf dictionary
4342 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4343" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4344" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004345 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004346" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004347
4348 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004350 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004351 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004352 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004353
4354 if &ft == "netrw"
4355" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4356 exe "sil! NetrwKeepj noswapfile b ".bufnum
4357" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004358 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004359" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4360 call s:NetrwEditBuf(bufnum)
4361" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004362 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004363" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004364 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004365 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004367
4368 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004370
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004371 if line("$") <= 1 && getline(1) == ""
4372 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004373 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004374" 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<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4377 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004378
Bram Moolenaar97d62492012-11-15 21:28:22 +01004379 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004381 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004382 sil NetrwKeepj %d _
4383" 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>"))
4384" 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 +01004385" 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 +00004386 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004387
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004389" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4390" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004391 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004392 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004393 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004394" 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>"))
4395" 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 +01004396" 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 +00004397 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004398
Bram Moolenaar446cb832008-06-24 21:56:24 +00004399 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004400" 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>"))
4401" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4402" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004403 return 1
4404 endif
4405 endif
4406
4407 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4408 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4409 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4410 " med 1 D H
4411 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004412" 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 +00004413 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004414 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004415 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004416
4417 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004418" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4419" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4420 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004422" 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>"))
4423" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4424" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425 return 0
4426endfun
4427
4428" ---------------------------------------------------------------------
4429" s:NetrwGetcwd: get the current directory. {{{2
4430" Change backslashes to forward slashes, if any.
4431" If doesc is true, escape certain troublesome characters
4432fun! s:NetrwGetcwd(doesc)
4433" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4434 let curdir= substitute(getcwd(),'\\','/','ge')
4435 if curdir !~ '[\/]$'
4436 let curdir= curdir.'/'
4437 endif
4438 if a:doesc
4439 let curdir= fnameescape(curdir)
4440 endif
4441" call Dret("NetrwGetcwd <".curdir.">")
4442 return curdir
4443endfun
4444
4445" ---------------------------------------------------------------------
4446" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4447fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004448" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4449" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4450 let keepsol= &l:sol
4451 setl nosol
4452
Bram Moolenaar446cb832008-06-24 21:56:24 +00004453 call s:UseBufWinVars()
4454
4455 " insure that w:netrw_liststyle is set up
4456 if !exists("w:netrw_liststyle")
4457 if exists("g:netrw_liststyle")
4458 let w:netrw_liststyle= g:netrw_liststyle
4459 else
4460 let w:netrw_liststyle= s:THINLIST
4461 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004462" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004463 endif
4464
4465 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4466 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004467" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004468 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469 let dirname= "./"
4470 let curline= getline('.')
4471
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004472 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004473 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004474 let s:netrw_skipbrowse= 1
4475 echo 'Pressing "s" also works'
4476
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004477 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478 let s:netrw_skipbrowse= 1
4479 echo 'Press "S" to edit sorting sequence'
4480
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004481 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004482 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004485 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004486 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487 let s:netrw_skipbrowse= 1
4488 echo 'Pressing "a" also works'
4489
4490 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004491 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 endif
4493
4494 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004495" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004496 NetrwKeepj norm! 0
4497 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004498
4499 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004500" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004502 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4503
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004504 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004505" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004506 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004507 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508
4509 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004510" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 let dirname= getline('.')
4512
4513 if !exists("b:netrw_cpf")
4514 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004515 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 +01004516 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004517" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 endif
4519
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004520" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004521 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004522" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4523" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004524 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004525 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526 else
4527 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004528 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529 endif
4530 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004531 let eofname= filestart + b:netrw_cpf + 1
4532 if eofname <= col("$")
4533 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004534 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004535 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004536 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004537 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004538 let dirname = @a
4539 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004540" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004542" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 endif
4544
4545 " symlinks are indicated by a trailing "@". Remove it before further processing.
4546 let dirname= substitute(dirname,"@$","","")
4547
4548 " executables are indicated by a trailing "*". Remove it before further processing.
4549 let dirname= substitute(dirname,"\*$","","")
4550
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004551 let &l:sol= keepsol
4552
Bram Moolenaar446cb832008-06-24 21:56:24 +00004553" call Dret("s:NetrwGetWord <".dirname.">")
4554 return dirname
4555endfun
4556
4557" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004558" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4559" g:netrw_bufsettings will be used after the listing is produced.
4560" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561fun! s:NetrwListSettings(islocal)
4562" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004563" 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 +00004564 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004565" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4566 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4567 setl bt=nofile nobl ma nonu nowrap noro nornu
4568 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004570 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004571 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004572" call Dredir("ls!","s:NetrwListSettings")
4573" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004574 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004575 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004577 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004579 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004581" 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 +00004582" call Dret("s:NetrwListSettings")
4583endfun
4584
4585" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004586" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004587" islocal=0: remote browsing
4588" =1: local browsing
4589fun! s:NetrwListStyle(islocal)
4590" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004591
Bram Moolenaar97d62492012-11-15 21:28:22 +01004592 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004593 let fname = s:NetrwGetWord()
4594 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004595 let svpos = winsaveview()
4596" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004598" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4599" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4600" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004601
Bram Moolenaar85850f32019-07-19 22:05:51 +02004602 " repoint t:netrw_lexbufnr if appropriate
4603 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4604" call Decho("set repointlexbufnr to true!")
4605 let repointlexbufnr= 1
4606 endif
4607
Bram Moolenaar446cb832008-06-24 21:56:24 +00004608 if w:netrw_liststyle == s:THINLIST
4609 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004611 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4612
4613 elseif w:netrw_liststyle == s:LONGLIST
4614 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004616 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4617
4618 elseif w:netrw_liststyle == s:WIDELIST
4619 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004620" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004621 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4622
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004623 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004624" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004625 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4626
4627 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004628 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004629 let g:netrw_liststyle = s:THINLIST
4630 let w:netrw_liststyle = g:netrw_liststyle
4631 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4632 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004633 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004634" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004635
4636 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004637" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4638 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004639 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004640" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004641 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004642" 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 +00004643
4644 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004645" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004646 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004647 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004648
Bram Moolenaar85850f32019-07-19 22:05:51 +02004649 " repoint t:netrw_lexbufnr if appropriate
4650 if exists("repointlexbufnr")
4651 let t:netrw_lexbufnr= bufnr("%")
4652" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4653 endif
4654
Bram Moolenaar13600302014-05-22 18:26:40 +02004655 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004656" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4657 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004658 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004659
4660" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4661endfun
4662
4663" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004664" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4665fun! s:NetrwBannerCtrl(islocal)
4666" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4667
Bram Moolenaar97d62492012-11-15 21:28:22 +01004668 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004669 " toggle the banner (enable/suppress)
4670 let g:netrw_banner= !g:netrw_banner
4671
4672 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004673 let svpos= winsaveview()
4674" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004675 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4676
4677 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004678 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4679 let fname= s:NetrwGetWord()
4680 sil NetrwKeepj $
4681 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4682" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4683 if result <= 0 && exists("w:netrw_bannercnt")
4684 exe "NetrwKeepj ".w:netrw_bannercnt
4685 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004686 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004687 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004688" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4689endfun
4690
4691" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004692" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4693"
4694" No bang: enters files/directories into Netrw's bookmark system
4695" No argument and in netrw buffer:
4696" if there are marked files: bookmark marked files
4697" otherwise : bookmark file/directory under cursor
4698" No argument and not in netrw buffer: bookmarks current open file
4699" Has arguments: globs them individually and bookmarks them
4700"
4701" With bang: deletes files/directories from Netrw's bookmark system
4702fun! s:NetrwBookmark(del,...)
4703" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4704 if a:0 == 0
4705 if &ft == "netrw"
4706 let curbufnr = bufnr("%")
4707
4708 if exists("s:netrwmarkfilelist_{curbufnr}")
4709 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004710" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004711 let svpos = winsaveview()
4712" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004713 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004714 for fname in s:netrwmarkfilelist_{curbufnr}
4715 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4716 endfor
4717 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4718 call s:NetrwUnmarkList(curbufnr,curdir)
4719 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004720" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4721 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004722 else
4723 let fname= s:NetrwGetWord()
4724 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4725 endif
4726
4727 else
4728 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004729" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004730 let fname= expand("%")
4731 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4732 endif
4733
4734 else
4735 " bookmark specified files
4736 " attempts to infer if working remote or local
4737 " by deciding if the current file begins with an url
4738 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004739 let islocal= expand("%") !~ '^\a\{3,}://'
4740" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004741 let i = 1
4742 while i <= a:0
4743 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004744 if v:version > 704 || (v:version == 704 && has("patch656"))
4745 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004746 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004747 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004748 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004749 else
4750 let mbfiles= [a:{i}]
4751 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004752" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004753 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004754" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004755 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4756 endfor
4757 let i= i + 1
4758 endwhile
4759 endif
4760
4761 " update the menu
4762 call s:NetrwBookmarkMenu()
4763
4764" call Dret("s:NetrwBookmark")
4765endfun
4766
4767" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004768" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4769" .2.[cnt] for bookmarks, and
4770" .3.[cnt] for history
4771" (see s:NetrwMenu())
4772fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004773 if !exists("s:netrw_menucnt")
4774 return
4775 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004776" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004777
4778 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004780 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004781" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004782 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4783 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004784 endif
4785 if !exists("s:netrw_initbookhist")
4786 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004787 endif
4788
4789 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004790 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004791 let cnt= 1
4792 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004793" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004794 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004795
4796 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004797 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004798
4799 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004800 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 +01004801 let cnt= cnt + 1
4802 endfor
4803
4804 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004805
4806 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004807 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004808 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004809 let first = 1
4810 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004811 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004812 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004813 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004814 if exists("g:netrw_dirhist_{cnt}")
4815 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004816" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004817 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4818 endif
4819 let first = 0
4820 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4821 if cnt < 0
4822 let cnt= cnt + g:netrw_dirhistmax
4823 endif
4824 endwhile
4825 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004826
Bram Moolenaar9964e462007-05-05 17:54:07 +00004827 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004828" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004829endfun
4830
4831" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004832" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4833" directory and a new directory name. Also, if the
4834" "new directory name" is actually a file,
4835" NetrwBrowseChgDir() edits the file.
4836fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004837" 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 +01004838" 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 +00004839
Bram Moolenaar97d62492012-11-15 21:28:22 +01004840 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004841 if !exists("b:netrw_curdir")
4842 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4843 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004844 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4846" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004847" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004848" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004849 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004850 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004851" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004852
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004853 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004854" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004855 call s:SavePosn(s:netrw_posn)
4856 NetrwKeepj call s:NetrwOptionsSave("s:")
4857 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004858 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004859 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004860 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004861 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004862 endif
4863 let newdir = a:newdir
4864 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004865 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004866" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004867" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004868" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004869
4870 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004871" 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 +01004872 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004873" 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 +01004874 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004875 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004876" 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 +01004877 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004878" 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 +02004879 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004880 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004881 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004882 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004883" 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 +01004884 endif
4885 endif
4886" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004887" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004888 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004889
Bram Moolenaar446cb832008-06-24 21:56:24 +00004890 " set up o/s-dependent directory recognition pattern
4891 if has("amiga")
4892 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004893 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 let dirpat= '[\/]$'
4895 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004896" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004897
4898 if dirname !~ dirpat
4899 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004900 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004902" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 endif
4904
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004905" 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 +01004906 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004907 " ------------------------------
4908 " NetrwBrowseChgDir: edit a file {{{3
4909 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004910" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004911
Bram Moolenaar97d62492012-11-15 21:28:22 +01004912 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004913 let s:rexposn_{bufnr("%")}= winsaveview()
4914" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004915" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4916" 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 +01004917
Bram Moolenaar446cb832008-06-24 21:56:24 +00004918 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004919" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4920" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004921" let newdir = s:NetrwTreePath(s:netrw_treetop)
4922" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004923 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004924 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4925" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4926 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004927 if dirname =~ '/$'
4928 let dirname= dirname.newdir
4929 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004930 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004931 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004932" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4933" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004934 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004935" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004937 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004938 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004939 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004940" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004941 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004942 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004943" 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 +02004944 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004945 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004946 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004947" " 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 +01004948 if type(g:netrw_browse_split) == 3
4949 " open file in server
4950 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004951" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004952 call s:NetrwServerEdit(a:islocal,dirname)
4953" call Dret("s:NetrwBrowseChgDir")
4954 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004955
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004956 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004957 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004958" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004959 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4960 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004961 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004962 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004963 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004964 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004965
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004967 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004968" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004969 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4970 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004971 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004972 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004973 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004974 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 == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004977 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004978" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004979 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004980 if !exists("b:netrw_curdir")
4981 let b:netrw_curdir= getcwd()
4982 endif
4983 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004984
Bram Moolenaar446cb832008-06-24 21:56:24 +00004985 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004986 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004987" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004988 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004989 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004990" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004991 return
4992 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004993 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004994
Bram Moolenaar9964e462007-05-05 17:54:07 +00004995 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004996 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004997" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004998 call s:NetrwMenu(0)
4999 " optional change to window
5000 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005001" 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 +02005002 if winnr("$")+1 == g:netrw_chgwin
5003 " if g:netrw_chgwin is set to one more than the last window, then
5004 " vertically split the last window to make that window available.
5005 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005006 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02005007 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005008 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02005009 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005010 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00005011 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005012 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00005013 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005014
Bram Moolenaar9964e462007-05-05 17:54:07 +00005015 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005016
Bram Moolenaar446cb832008-06-24 21:56:24 +00005017 " the point where netrw actually edits the (local) file
5018 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005019 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005020 if !&mod
5021 " if e the new file would fail due to &mod, then don't change any of the flags
5022 let dolockout= 1
5023 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005024 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005026 " some like c-^ to return to the last edited file
5027 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005028 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5029 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005030 call s:NetrwEditFile("e","",dirname)
5031" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005032 " COMBAK -- cuc cul related
5033 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005034 if &hidden || &bufhidden == "hide"
5035 " file came from vim's hidden storage. Don't "restore" options with it.
5036 let dorestore= 0
5037 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005038 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005039" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005040 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005041
5042 " handle g:Netrw_funcref -- call external-to-netrw functions
5043 " This code will handle g:Netrw_funcref as an individual function reference
5044 " or as a list of function references. It will ignore anything that's not
5045 " a function reference. See :help Funcref for information about function references.
5046 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005047" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005048 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005049" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005050 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005051 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005052" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005053 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005054 if type(Fncref) == 2
5055 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005056 endif
5057 endfor
5058 endif
5059 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005060 endif
5061
5062 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005063 " ----------------------------------------------------
5064 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5065 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005066" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005067 let dirname = newdir
5068 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005069 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005070 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005071
5072 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005073 " ---------------------------------------------
5074 " NetrwBrowseChgDir: refresh the directory list {{{3
5075 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005076" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005077 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005078 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005079
5080 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005081 " --------------------------------------
5082 " NetrwBrowseChgDir: go up one directory {{{3
5083 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005084" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005085
5086 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5087 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005088" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5089" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005090 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005091 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005092 endif
5093
5094 if has("amiga")
5095 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005096" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005097 if a:islocal
5098 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5099 let dirname= substitute(dirname,'/$','','')
5100 else
5101 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5102 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005103" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005104
Bram Moolenaar8d043172014-01-23 14:24:41 +01005105 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5106 " windows
5107 if a:islocal
5108 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5109 if dirname == ""
5110 let dirname= '/'
5111 endif
5112 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005114 endif
5115 if dirname =~ '^\a:$'
5116 let dirname= dirname.'/'
5117 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005118" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005119
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 else
5121 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005122" 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 +00005123 if a:islocal
5124 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5125 if dirname == ""
5126 let dirname= '/'
5127 endif
5128 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005129 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005131" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005133 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005134 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005135
5136 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005137 " --------------------------------------
5138 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5139 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005140" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005141 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5142" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005143 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005145" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5146 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005147 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005148 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005149" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005150 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005151 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005152" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153
5154 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005155" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005157" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158 let haskey= 1
5159 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005160" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 endif
5162
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005164" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005165 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005166 if has_key(w:netrw_treedict,treedir."/")
5167 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005168" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169 let haskey = 1
5170 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005171" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172 endif
5173 endif
5174
5175 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005176" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005177 if !haskey && treedir =~ '/$'
5178 let treedir= substitute(treedir,'/$','','')
5179 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005180" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005181 let haskey = 1
5182 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005183" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005184 endif
5185 endif
5186
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005187" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005188 if haskey
5189 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005190" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005191 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5193" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005194 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005195 else
5196 " go down one directory
5197 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005198" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5199" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005200 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005201 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005203 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005204
5205 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005206 " ----------------------------------------
5207 " NetrwBrowseChgDir: Go down one directory {{{3
5208 " ----------------------------------------
5209 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005210" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005211 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005212 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005213 endif
5214
Bram Moolenaar97d62492012-11-15 21:28:22 +01005215 " --------------------------------------
5216 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5217 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005218 if dorestore
5219 " dorestore is zero'd when a local file was hidden or bufhidden;
5220 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005221" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005222 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005223" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005224" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005225 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005226 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005227" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005228 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005229" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5230" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005231 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005232" 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 +02005233 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005234" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5235" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005236 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005237" call Decho("restore: ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005238 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005239 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005240 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005241 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005242
Bram Moolenaar446cb832008-06-24 21:56:24 +00005243" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5244 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005245endfun
5246
5247" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005248" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5249" for thin, long, and wide: cursor placed just after banner
5250" for tree, keeps cursor on current filename
5251fun! s:NetrwBrowseUpDir(islocal)
5252" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005253 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5254 " this test needed because occasionally this function seems to be incorrectly called
5255 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005256 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005257 " directories.
5258" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5259 return
5260 endif
5261
Bram Moolenaara6878372014-03-22 21:02:50 +01005262 norm! 0
5263 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005264" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005265 let curline= getline(".")
5266 let swwline= winline() - 1
5267 if exists("w:netrw_treetop")
5268 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005269 elseif exists("b:netrw_curdir")
5270 let w:netrw_treetop= b:netrw_curdir
5271 else
5272 let w:netrw_treetop= getcwd()
5273 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005274 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275 let curfile = getline(".")
5276 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005277 if a:islocal
5278 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5279 else
5280 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5281 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005282" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5283" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5284 if w:netrw_treetop == '/'
5285 keepj call search('^\M'.curfile,"w")
5286 elseif curfile == '../'
5287 keepj call search('^\M'.curfile,"wb")
5288 else
5289" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5290 while 1
5291 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5292 let treepath= s:NetrwTreePath(w:netrw_treetop)
5293" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5294 if treepath == curpath
5295 break
5296 endif
5297 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005298 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005299
Bram Moolenaara6878372014-03-22 21:02:50 +01005300 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005301" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005302 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005303 if exists("b:netrw_curdir")
5304 let curdir= b:netrw_curdir
5305 else
5306 let curdir= expand(getcwd())
5307 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005308 if a:islocal
5309 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5310 else
5311 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5312 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005313 call s:RestorePosn(s:netrw_posn)
5314 let curdir= substitute(curdir,'^.*[\/]','','')
5315 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005316 endif
5317" call Dret("s:NetrwBrowseUpDir")
5318endfun
5319
5320" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005321" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005322" given filename; typically this means given their extension.
5323" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005324fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005325 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005326" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005327
Bram Moolenaar91359012019-11-30 17:57:03 +01005328 if a:remote == 0 && isdirectory(a:fname)
5329 " if its really just a local directory, then do a "gf" instead
5330" 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 +01005331" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5332 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005333" call Dret("netrw#BrowseX")
5334 return
5335 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5336 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5337" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5338" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5339" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5340" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5341 norm! gf
5342" call Dret("netrw#BrowseX")
5343 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005344 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005345" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005346
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005347 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5348 let remote = a:remote
5349 else
5350 let remote = 0
5351 endif
5352
Bram Moolenaar97d62492012-11-15 21:28:22 +01005353 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005354 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005355" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005356
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005357 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5358 let awkeep = &aw
5359 set noaw
5360
Bram Moolenaar5c736222010-01-06 20:54:52 +01005361 " special core dump handler
5362 if a:fname =~ '/core\(\.\d\+\)\=$'
5363 if exists("g:Netrw_corehandler")
5364 if type(g:Netrw_corehandler) == 2
5365 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005366" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005367 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005368 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005369 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005370" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005371 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005372 if type(Fncref) == 2
5373 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005374 endif
5375 endfor
5376 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005377" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005378 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005379 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005380 let &aw= awkeep
5381" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005382 return
5383 endif
5384 endif
5385
Bram Moolenaar446cb832008-06-24 21:56:24 +00005386 " set up the filename
5387 " (lower case the extension, make a local copy of a remote file)
5388 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5389 if has("win32") || has("win95") || has("win64") || has("win16")
5390 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005391 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005392 if exten =~ "[\\/]"
5393 let exten= ""
5394 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005395" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005396
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005397 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005398 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005399" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005400 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005401 call netrw#NetRead(3,a:fname)
5402 " attempt to rename tempfile
5403 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005404 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005405" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5406" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005407 if s:netrw_tmpfile != newname && newname != ""
5408 if rename(s:netrw_tmpfile,newname) == 0
5409 " renaming succeeded
5410" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5411 let fname= newname
5412 else
5413 " renaming failed
5414" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5415 let fname= s:netrw_tmpfile
5416 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005417 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005418 let fname= s:netrw_tmpfile
5419 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005420 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005421" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005422 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005423 " special ~ handler for local
5424 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005425" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5426 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005427 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005428 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005429" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5430" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005431
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005432 " set up redirection (avoids browser messages)
5433 " by default, g:netrw_suppress_gx_mesg is true
5434 if g:netrw_suppress_gx_mesg
5435 if &srr =~ "%s"
5436 if (has("win32") || has("win95") || has("win64") || has("win16"))
5437 let redir= substitute(&srr,"%s","nul","")
5438 else
5439 let redir= substitute(&srr,"%s","/dev/null","")
5440 endif
5441 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5442 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005443 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005444 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005446 else
5447 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005448 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005449" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005450
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005451 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005453" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005454 if g:netrw_browsex_viewer =~ '\s'
5455 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5456 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5457 let oviewer = ''
5458 let cnt = 1
5459 while !executable(viewer) && viewer != oviewer
5460 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5461 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5462 let cnt = cnt + 1
5463 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005464" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005465 endwhile
5466 else
5467 let viewer = g:netrw_browsex_viewer
5468 let viewopt = ""
5469 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005470" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005471 endif
5472
5473 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005474" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005475 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005476" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005477 let ret= netrwFileHandlers#Invoke(exten,fname)
5478
5479 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005480" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005481 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005482 let ret= v:shell_error
5483
5484 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005485" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005486 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005487 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005488 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005489 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005490 else
5491 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5492 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005493 let ret= v:shell_error
5494
Bram Moolenaar97d62492012-11-15 21:28:22 +01005495 elseif has("win32unix")
5496 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005497" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005498 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005499" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005500 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005501 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005502" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005503 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005504 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005505" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005506 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005507 else
5508 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5509 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005510 let ret= v:shell_error
5511
Bram Moolenaar85850f32019-07-19 22:05:51 +02005512 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005513" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5514 if a:fname =~ '^https\=://'
5515 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5516 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005517" call Decho("fname<".fname.">")
5518" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005519 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5520
5521 else
5522 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5523 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005524 let ret= v:shell_error
5525
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005526 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5527" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5528 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5529 let ret= v:shell_error
5530
5531 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5532" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5533 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5534 let ret= v:shell_error
5535
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005536 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005537" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005538 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005539 let ret= v:shell_error
5540
5541 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005542" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005543 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544 let ret= v:shell_error
5545
5546 else
5547 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005548" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 let ret= netrwFileHandlers#Invoke(exten,fname)
5550 endif
5551
5552 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5553 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005554" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005555 let ret= netrwFileHandlers#Invoke(exten,fname)
5556 endif
5557
Bram Moolenaarc236c162008-07-13 17:41:49 +00005558 " restoring redraw! after external file handlers
5559 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005560
5561 " cleanup: remove temporary file,
5562 " delete current buffer if success with handler,
5563 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005564 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005565 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005566" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005567"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005568" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005569" endif
5570
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005571 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005572 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005573 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005574 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005575 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005576 if use_ctrlo
5577 exe "sil! NetrwKeepj norm! \<c-o>"
5578 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005579 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005580" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005581 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005582 let @@ = ykeep
5583 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005584
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005585" call Dret("netrw#BrowseX")
5586endfun
5587
5588" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005589" netrw#GX: gets word under cursor for gx support {{{2
5590" See also: netrw#BrowseXVis
5591" netrw#BrowseX
5592fun! netrw#GX()
5593" call Dfunc("netrw#GX()")
5594 if &ft == "netrw"
5595 let fname= s:NetrwGetWord()
5596 else
5597 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5598 endif
5599" call Dret("netrw#GX <".fname.">")
5600 return fname
5601endfun
5602
5603" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005604" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5605fun! netrw#BrowseXVis()
5606" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005607 let akeep = @a
5608 norm! gv"ay
5609 let gxfile= @a
5610 let @a = akeep
5611 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005612" call Dret("netrw#BrowseXVis")
5613endfun
5614
5615" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005616" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5617" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5618" to become an unlisted buffer, so in that case don't bwipe it.
5619fun! s:NetrwBufRename(newname)
5620" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5621" call Dredir("ls!","s:NetrwBufRename (before rename)")
5622 let oldbufname= bufname(bufnr("%"))
5623" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5624
5625 if oldbufname != a:newname
5626" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5627 let b:junk= 1
5628" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5629 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005630" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005631 let oldbufnr= bufnr(oldbufname)
5632" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5633" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5634 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5635" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5636 exe "bwipe! ".oldbufnr
5637" else " Decho
5638" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005639" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5640" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5641" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005642 endif
5643" call Dredir("ls!","s:NetrwBufRename (after rename)")
5644" else " Decho
5645" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5646 endif
5647
5648" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5649endfun
5650
5651" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005652" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005653fun! netrw#CheckIfRemote(...)
5654" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5655 if a:0 > 0
5656 let curfile= a:1
5657 else
5658 let curfile= expand("%")
5659 endif
5660" call Decho("curfile<".curfile.">")
5661 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005662" call Dret("netrw#CheckIfRemote 1")
5663 return 1
5664 else
5665" call Dret("netrw#CheckIfRemote 0")
5666 return 0
5667 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005668endfun
5669
5670" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005671" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5672fun! s:NetrwChgPerm(islocal,curdir)
5673" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005674 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005675 call inputsave()
5676 let newperm= input("Enter new permission: ")
5677 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005678 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5679 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5680" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005681 call system(chgperm)
5682 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005683 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005684 endif
5685 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005686 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005687 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005688 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005689" call Dret("s:NetrwChgPerm")
5690endfun
5691
5692" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005693" s:CheckIfKde: checks if kdeinit is running {{{2
5694" Returns 0: kdeinit not running
5695" 1: kdeinit is running
5696fun! s:CheckIfKde()
5697" call Dfunc("s:CheckIfKde()")
5698 " seems kde systems often have gnome-open due to dependencies, even though
5699 " gnome-open's subsidiary display tools are largely absent. Kde systems
5700 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5701 if !exists("s:haskdeinit")
5702 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005703 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005704 if v:shell_error
5705 let s:haskdeinit = 0
5706 endif
5707 else
5708 let s:haskdeinit= 0
5709 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005710" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005711 endif
5712
5713" call Dret("s:CheckIfKde ".s:haskdeinit)
5714 return s:haskdeinit
5715endfun
5716
5717" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005718" s:NetrwClearExplore: clear explore variables (if any) {{{2
5719fun! s:NetrwClearExplore()
5720" call Dfunc("s:NetrwClearExplore()")
5721 2match none
5722 if exists("s:explore_match") |unlet s:explore_match |endif
5723 if exists("s:explore_indx") |unlet s:explore_indx |endif
5724 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5725 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5726 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5727 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5728 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5729 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5730 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5731" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005732" call Dret("s:NetrwClearExplore")
5733endfun
5734
5735" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005736" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5737fun! s:NetrwEditBuf(bufnum)
5738" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5739 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5740" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5741 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5742 else
5743" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005744 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005745 endif
5746" call Dret("s:NetrwEditBuf")
5747endfun
5748
5749" ---------------------------------------------------------------------
5750" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5751" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5752fun! s:NetrwEditFile(cmd,opt,fname)
5753" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5754 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5755" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5756 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5757 else
5758" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5759 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5760 endif
5761" call Dret("s:NetrwEditFile")
5762endfun
5763
5764" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005765" s:NetrwExploreListUniq: {{{2
5766fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005767" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005768
5769 " this assumes that the list is already sorted
5770 let newexplist= []
5771 for member in a:explist
5772 if !exists("uniqmember") || member != uniqmember
5773 let uniqmember = member
5774 let newexplist = newexplist + [ member ]
5775 endif
5776 endfor
5777
Bram Moolenaar15146672011-10-20 22:22:38 +02005778" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005779 return newexplist
5780endfun
5781
5782" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005783" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5784fun! s:NetrwForceChgDir(islocal,newdir)
5785" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005786 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005787 if a:newdir !~ '/$'
5788 " ok, looks like force is needed to get directory-style treatment
5789 if a:newdir =~ '@$'
5790 let newdir= substitute(a:newdir,'@$','/','')
5791 elseif a:newdir =~ '[*=|\\]$'
5792 let newdir= substitute(a:newdir,'.$','/','')
5793 else
5794 let newdir= a:newdir.'/'
5795 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005796" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005797 else
5798 " should already be getting treatment as a directory
5799 let newdir= a:newdir
5800 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005801 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005802 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005803 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005804" call Dret("s:NetrwForceChgDir")
5805endfun
5806
5807" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005808" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005809" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5810" expr : this is the expression to follow the directory. Will use s:ComposePath()
5811" pare =1: remove the current directory from the resulting glob() filelist
5812" =0: leave the current directory in the resulting glob() filelist
5813fun! s:NetrwGlob(direntry,expr,pare)
5814" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005815 if netrw#CheckIfRemote()
5816 keepalt 1sp
5817 keepalt enew
5818 let keep_liststyle = w:netrw_liststyle
5819 let w:netrw_liststyle = s:THINLIST
5820 if s:NetrwRemoteListing() == 0
5821 keepj keepalt %s@/@@
5822 let filelist= getline(1,$)
5823 q!
5824 else
5825 " remote listing error -- leave treedict unchanged
5826 let filelist= w:netrw_treedict[a:direntry]
5827 endif
5828 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005829 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5830 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5831 if a:pare
5832 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5833 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005834 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005835 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5836 if a:pare
5837 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5838 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005839 endif
5840" call Dret("s:NetrwGlob ".string(filelist))
5841 return filelist
5842endfun
5843
5844" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005845" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5846fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005847" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005848 if a:newfile =~ '[/@*=|\\]$'
5849 let newfile= substitute(a:newfile,'.$','','')
5850 else
5851 let newfile= a:newfile
5852 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005853 if a:islocal
5854 call s:NetrwBrowseChgDir(a:islocal,newfile)
5855 else
5856 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5857 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005858" call Dret("s:NetrwForceFile")
5859endfun
5860
5861" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005862" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5863" and switches the hiding mode. The actual hiding is done by
5864" s:NetrwListHide().
5865" g:netrw_hide= 0: show all
5866" 1: show not-hidden files
5867" 2: show hidden files only
5868fun! s:NetrwHide(islocal)
5869" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005870 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005871 let svpos= winsaveview()
5872" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873
5874 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005875" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5876" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877
5878 " hide the files in the markfile list
5879 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005880" 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 +00005881 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5882 " remove fname from hiding list
5883 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5884 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5885 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005886" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005887 else
5888 " append fname to hiding list
5889 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5890 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5891 else
5892 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5893 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005894" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005895 endif
5896 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005897 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898 let g:netrw_hide= 1
5899
5900 else
5901
5902 " switch between show-all/show-not-hidden/show-hidden
5903 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005904 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005906 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005907 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005908" call Dret("NetrwHide")
5909 return
5910 endif
5911 endif
5912
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005913 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005914" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5915 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005916 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005917" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005918endfun
5919
5920" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005921" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5922fun! s:NetrwHideEdit(islocal)
5923" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5924
5925 let ykeep= @@
5926 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005927 let svpos= winsaveview()
5928" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005929
5930 " get new hiding list from user
5931 call inputsave()
5932 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5933 call inputrestore()
5934 let g:netrw_list_hide= newhide
5935" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5936
5937 " refresh the listing
5938 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5939
5940 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005941" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5942 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005943 let @@= ykeep
5944
5945" call Dret("NetrwHideEdit")
5946endfun
5947
5948" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005949" s:NetrwHidden: invoked by "gh" {{{2
5950fun! s:NetrwHidden(islocal)
5951" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005952 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005954 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005955" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005956
5957 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005958 " remove .file pattern from hiding list
5959" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005960 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005961 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005962" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005963 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5964 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005965" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005966 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5967 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005968 if g:netrw_list_hide =~ '^,'
5969 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5970 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005971
5972 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005973 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005974" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5975 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005976 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005977" call Dret("s:NetrwHidden")
5978endfun
5979
5980" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005981" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5982fun! s:NetrwHome()
5983 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005984 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005985 else
5986 " go to vim plugin home
5987 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005988 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005989 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005990 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005991 let home= basehome."/.vim"
5992 break
5993 endif
5994 endfor
5995 if home == ""
5996 " just pick the first directory
5997 let home= substitute(&rtp,',.*$','','')
5998 endif
5999 if (has("win32") || has("win95") || has("win64") || has("win16"))
6000 let home= substitute(home,'/','\\','g')
6001 endif
6002 endif
6003 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006004 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006005" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006006 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006007" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006008 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01006009 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006010" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006011 call mkdir(home)
6012 endif
6013 endif
6014 let g:netrw_home= home
6015 return home
6016endfun
6017
6018" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006019" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6020fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006021 if exists("s:netrwdrag")
6022 return
6023 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006024 if &ft != "netrw"
6025 return
6026 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006027" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006028
Bram Moolenaar97d62492012-11-15 21:28:22 +01006029 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006030 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006031 while getchar(0) != 0
6032 "clear the input stream
6033 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006034 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006035 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006036 let mouse_lnum = v:mouse_lnum
6037 let wlastline = line('w$')
6038 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006039" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6040" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006041 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6042 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006043 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006044" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6045 return
6046 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006047 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006048 " 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 +01006049 " without this test when its disabled.
6050 " 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 +01006051" 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 +01006052 if v:mouse_col > virtcol('.')
6053 let @@= ykeep
6054" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6055 return
6056 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006057
Bram Moolenaar446cb832008-06-24 21:56:24 +00006058 if a:islocal
6059 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006060 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006061 endif
6062 else
6063 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006064 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006065 endif
6066 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006067 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006068" call Dret("s:NetrwLeftmouse")
6069endfun
6070
6071" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006072" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6073fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006074 if &ft != "netrw"
6075 return
6076 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006077" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6078 call s:NetrwMarkFileTgt(a:islocal)
6079" call Dret("s:NetrwCLeftmouse")
6080endfun
6081
6082" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006083" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6084" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006085" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086" a:islocal=2 : <c-r> used, remote
6087" a:islocal=3 : <c-r> used, local
6088fun! s:NetrwServerEdit(islocal,fname)
6089" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6090 let islocal = a:islocal%2 " =0: remote =1: local
6091 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006092" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006093
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006094 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006095 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006096 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006097" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006098 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006099 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006100 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6101 unlet s:netrw_browse_split_{winnr()}
6102 endif
6103 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6104" call Dret("s:NetrwServerEdit")
6105 return
6106 endif
6107
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006108" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006109 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006110" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006111
6112 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006113" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006114 let srvrname = g:netrw_browse_split[0]
6115 let tabnum = g:netrw_browse_split[1]
6116 let winnum = g:netrw_browse_split[2]
6117
6118 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006119" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006120
6121 if !ctrlr
6122 " user must have closed the server window and the user did not use <c-r>, but
6123 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006124" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006125 if exists("g:netrw_browse_split")
6126 unlet g:netrw_browse_split
6127 endif
6128 let g:netrw_browse_split= 0
6129 if exists("s:netrw_browse_split_".winnr())
6130 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6131 endif
6132 call s:NetrwBrowseChgDir(islocal,a:fname)
6133" call Dret("s:NetrwServerEdit")
6134 return
6135
6136 elseif has("win32") && executable("start")
6137 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006138" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006139 call system("start gvim --servername ".srvrname)
6140
6141 else
6142 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006143" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006144 call system("gvim --servername ".srvrname)
6145 endif
6146 endif
6147
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6150 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006151 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006152
6153 else
6154
6155 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6156
6157 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006158" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006159 if exists("g:netrw_browse_split")
6160 unlet g:netrw_browse_split
6161 endif
6162 let g:netrw_browse_split= 0
6163 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6164" call Dret("s:NetrwServerEdit")
6165 return
6166
6167 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006168" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006169 if has("win32") && executable("start")
6170 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006171" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006172 call system("start gvim --servername ".g:netrw_servername)
6173 else
6174 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006175" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006176 call system("gvim --servername ".g:netrw_servername)
6177 endif
6178 endif
6179 endif
6180
6181 while 1
6182 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006183" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6184 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006185 break
6186 catch /^Vim\%((\a\+)\)\=:E241/
6187 sleep 200m
6188 endtry
6189 endwhile
6190
6191 if exists("g:netrw_browse_split")
6192 if type(g:netrw_browse_split) != 3
6193 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6194 endif
6195 unlet g:netrw_browse_split
6196 endif
6197 let g:netrw_browse_split= [g:netrw_servername,1,1]
6198 endif
6199
6200 else
6201 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6202 endif
6203
6204" call Dret("s:NetrwServerEdit")
6205endfun
6206
6207" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006208" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6209fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006210 if &ft != "netrw"
6211 return
6212 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006213" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006214
Bram Moolenaar8d043172014-01-23 14:24:41 +01006215 let s:ngw= s:NetrwGetWord()
6216 call s:NetrwMarkFile(a:islocal,s:ngw)
6217
6218" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006219endfun
6220
6221" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006222" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6223" Used to mark multiple files.
6224fun! s:NetrwSLeftdrag(islocal)
6225" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6226 if !exists("s:netrwdrag")
6227 let s:netrwdrag = winnr()
6228 if a:islocal
6229 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006230 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006231 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006232 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006233 endif
6234 let ngw = s:NetrwGetWord()
6235 if !exists("s:ngw") || s:ngw != ngw
6236 call s:NetrwMarkFile(a:islocal,ngw)
6237 endif
6238 let s:ngw= ngw
6239" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6240endfun
6241
6242" ---------------------------------------------------------------------
6243" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6244fun! s:NetrwSLeftrelease(islocal)
6245" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6246 if exists("s:netrwdrag")
6247 nunmap <s-leftrelease>
6248 let ngw = s:NetrwGetWord()
6249 if !exists("s:ngw") || s:ngw != ngw
6250 call s:NetrwMarkFile(a:islocal,ngw)
6251 endif
6252 if exists("s:ngw")
6253 unlet s:ngw
6254 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006255 unlet s:netrwdrag
6256 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006257" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006258endfun
6259
6260" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006261" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6262" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006263fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006264" 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 +02006265" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006266 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267
6268 " 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 +02006269 " How-it-works: take the hiding command, convert it into a range.
6270 " Duplicate characters don't matter.
6271 " Remove all such characters from the '/~@#...890' string.
6272 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006273" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006275 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006276" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006277
6278 while listhide != ""
6279 if listhide =~ ','
6280 let hide = substitute(listhide,',.*$','','e')
6281 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6282 else
6283 let hide = listhide
6284 let listhide = ""
6285 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006286" 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 +01006287 if g:netrw_sort_by =~ '^[ts]'
6288 if hide =~ '^\^'
6289" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6290 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6291 elseif hide =~ '^\\(\^'
6292 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6293 endif
6294" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6295 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006296
6297 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006298" 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 +00006299 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006300" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006301 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006303" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006304 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006306" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006308
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006310 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006311" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006312 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006313" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006314 endif
6315
Bram Moolenaaradc21822011-04-01 18:03:16 +02006316 " remove any blank lines that have somehow remained.
6317 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006318 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006319
Bram Moolenaar97d62492012-11-15 21:28:22 +01006320 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006321" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006322endfun
6323
6324" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006325" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006326" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006328" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006329
Bram Moolenaar97d62492012-11-15 21:28:22 +01006330 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006331 " get name of new directory from user. A bare <CR> will skip.
6332 " if its currently a directory, also request will be skipped, but with
6333 " a message.
6334 call inputsave()
6335 let newdirname= input("Please give directory name: ")
6336 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006337" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006338
6339 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006340 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006341" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006342 return
6343 endif
6344
6345 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006346" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006347
6348 " Local mkdir:
6349 " sanity checks
6350 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006351" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6352 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006353 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006354 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006355 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006356 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006357" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006358 return
6359 endif
6360 if s:FileReadable(fullnewdir)
6361 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006362 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006363 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006364 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006365" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006366 return
6367 endif
6368
6369 " requested new local directory is neither a pre-existing file or
6370 " directory, so make it!
6371 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006372 if has("unix")
6373 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6374 else
6375 call mkdir(fullnewdir,"p")
6376 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006377 else
6378 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006379 if s:NetrwLcd(b:netrw_curdir)
6380" call Dret("s:NetrwMakeDir : lcd failure")
6381 return
6382 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006383" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006384 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006385 if v:shell_error != 0
6386 let @@= ykeep
6387 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 +01006388" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006389 return
6390 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006391 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006393 if s:NetrwLcd(netrw_origdir)
6394" call Dret("s:NetrwBrowse : lcd failure")
6395 return
6396 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006397 endif
6398 endif
6399
6400 if v:shell_error == 0
6401 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006402" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006403 let svpos= winsaveview()
6404" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006406" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6407 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006408 elseif !exists("g:netrw_quiet")
6409 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6410 endif
6411" redraw!
6412
6413 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006414 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006415" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006416 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6417 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006418 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006419 if v:shell_error == 0
6420 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006421 let svpos= winsaveview()
6422" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006423 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006424" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6425 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006426 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006427 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428 endif
6429" redraw!
6430
6431 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006432 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006433 let svpos= winsaveview()
6434" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006435" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006436 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006437" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006438 let remotepath= b:netrw_fname
6439 else
6440 let remotepath= ""
6441 endif
6442 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006443 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006444" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6445 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006446
Bram Moolenaar446cb832008-06-24 21:56:24 +00006447 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006448 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006449 let svpos= winsaveview()
6450" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006451" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006452 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006453" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006454 let remotepath= b:netrw_fname
6455 else
6456 let remotepath= ""
6457 endif
6458 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006459 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006460" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6461 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006462 endif
6463
Bram Moolenaar97d62492012-11-15 21:28:22 +01006464 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006465" call Dret("s:NetrwMakeDir")
6466endfun
6467
6468" ---------------------------------------------------------------------
6469" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6470fun! s:TreeSqueezeDir(islocal)
6471" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6472 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6473 " its a tree-listing style
6474 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006475 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006476 let depth = strchars(substitute(curdepth,' ','','g'))
6477 let srch = -1
6478" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6479" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006480" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006481" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6482 if depth >= 2
6483 NetrwKeepj norm! 0
6484 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6485 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6486" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6487" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6488 elseif depth == 1
6489 NetrwKeepj norm! 0
6490 let treedepthchr= substitute(s:treedepthstring,' ','','')
6491 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6492" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6493 endif
6494 if srch > 0
6495" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6496 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6497 exe srch
6498 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006499 endif
6500" call Dret("s:TreeSqueezeDir")
6501endfun
6502
6503" ---------------------------------------------------------------------
6504" s:NetrwMaps: {{{2
6505fun! s:NetrwMaps(islocal)
6506" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6507
Bram Moolenaar85850f32019-07-19 22:05:51 +02006508 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006509 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006510" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006511 if !hasmapto("<Plug>NetrwReturn")
6512 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006513" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006514 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6515 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006516" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006517 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6518 endif
6519 endif
6520 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006521" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006522 endif
6523
Bram Moolenaar85850f32019-07-19 22:05:51 +02006524 " generate default <Plug> maps {{{3
6525 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006526 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006527 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6528 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6529 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6530 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6531 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6532 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6533 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6534 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6535 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6536 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6537" ---------------------------------------------------------------------
6538" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6539" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6540" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6541" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6542" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6543" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6544" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6545" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6546" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6547" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6548" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6549" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6550" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6551" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6552" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6553" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6554" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6555" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6556" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6557" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6558" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6559" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6560" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6561" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6562" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6563" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6564" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6565" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6566" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6567" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6568" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6569" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6570" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6571" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6572" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6573" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6574" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6575" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6576" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6577" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6578" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6579" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6580" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6581" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6582" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6583" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6584" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6585
Bram Moolenaara6878372014-03-22 21:02:50 +01006586 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006587" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006588 " local normal-mode maps {{{3
6589 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6590 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6591 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6592 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6593 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6594 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6595 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6596 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6597 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6598 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6599 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6600" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006601 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6602 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6603 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006604 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006606 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6607 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6608 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6609 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006610 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6611 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6612 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6613 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6614 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6615 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6616 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6617 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6618 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6619 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6620 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6621 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6622 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006623 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006624 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006625 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6626 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6627 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6628 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6629 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006630 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006631 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006632 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6633 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006634 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6635 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6636 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006637 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006638 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006639 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6640 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006641 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006642 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006643 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6644 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6645 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6647 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006648
6649 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 +01006650 if !hasmapto('<Plug>NetrwHideEdit')
6651 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006652 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006653 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006654 if !hasmapto('<Plug>NetrwRefresh')
6655 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006656 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006657 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 +01006658 if s:didstarstar || !mapcheck("<s-down>","n")
6659 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006660 endif
6661 if s:didstarstar || !mapcheck("<s-up>","n")
6662 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006663 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006664 if !hasmapto('<Plug>NetrwTreeSqueeze')
6665 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006666 endif
6667 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006668 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6669 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006670 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6671 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6672 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6673 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6674 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6675 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6676 imap <buffer> <leftmouse> <Plug>ILeftmouse
6677 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006678 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006679 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006680 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006681 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006682 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006683 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006684 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6685 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006686 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006687 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6688 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6689 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6690 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6691 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6692 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6693 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006694 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6695
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006696 " support user-specified maps
6697 call netrw#UserMaps(1)
6698
Bram Moolenaar85850f32019-07-19 22:05:51 +02006699 else
6700 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006701" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006702 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006703 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6704 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6705 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6706 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6707 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6708 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6709 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6710 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6711 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6712 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6713 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6714" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006715 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6716 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6717 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6718 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6719 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6720 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6722 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006723 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006724 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6726 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6727 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6728 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6729 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6730 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6731 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6732 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6733 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6734 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6735 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006736 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006737 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006738 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6739 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6740 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6741 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6742 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006743 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6744 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6745 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6746 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006747 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6749 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006750 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006751 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 +01006752 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6753 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6754 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6755 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6756 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6757 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6758 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6759 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6760 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006761 if !hasmapto('<Plug>NetrwHideEdit')
6762 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006763 endif
6764 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6765 if !hasmapto('<Plug>NetrwRefresh')
6766 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006767 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006768 if !hasmapto('<Plug>NetrwTreeSqueeze')
6769 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006770 endif
6771 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006772
6773 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006774 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006775
6776 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6777 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006778 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6779 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6780 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6781 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6782 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6783 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6784 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6785 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6786 nmap <middlemouse> <Plug>NetrwMiddlemouse
6787 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6788 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6789 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6790 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006791 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006792 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006793 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6794 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006795 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006796 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6797 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6798 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6799 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6800 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6801 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6802 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006803 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006804
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006805 " support user-specified maps
6806 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006807 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006808
6809" call Dret("s:NetrwMaps")
6810endfun
6811
6812" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006813" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006814" If -buffer, the command is only available from within netrw buffers
6815" Otherwise, the command is available from any window, so long as netrw
6816" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006817fun! s:NetrwCommands(islocal)
6818" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6819
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006820 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6821 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006822 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 +01006823 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006824 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006825 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006826 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006827 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006828 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006829
6830" call Dret("s:NetrwCommands")
6831endfun
6832
6833" ---------------------------------------------------------------------
6834" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6835" glob()ing only works with local files
6836fun! s:NetrwMarkFiles(islocal,...)
6837" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006838 let curdir = s:NetrwGetCurdir(a:islocal)
6839 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006840 while i <= a:0
6841 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006842 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006843 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006844 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006845 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006846 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006847 else
6848 let mffiles= [a:{i}]
6849 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006850" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006851 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006852" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006853 call s:NetrwMarkFile(a:islocal,mffile)
6854 endfor
6855 let i= i + 1
6856 endwhile
6857" call Dret("s:NetrwMarkFiles")
6858endfun
6859
6860" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006861" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006862fun! s:NetrwMarkTarget(...)
6863" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6864 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006865 let curdir = s:NetrwGetCurdir(1)
6866 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006867 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006868 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6869 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006870 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006871" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006872 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006873 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6874 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006875 let svpos = winsaveview()
6876" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006877 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006878" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6879 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006880" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006881endfun
6882
6883" ---------------------------------------------------------------------
6884" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6885" mark and unmark files. If a markfile list exists,
6886" then the rename and delete functions will use it instead
6887" of whatever may happen to be under the cursor at that
6888" moment. When the mouse and gui are available,
6889" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006890"
6891" Creates two lists
6892" s:netrwmarkfilelist -- holds complete paths to all marked files
6893" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6894"
6895" Creates a marked file match string
6896" s:netrwmarfilemtch_# -- used with 2match to display marked files
6897"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006898" Creates a buffer version of islocal
6899" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006900fun! s:NetrwMarkFile(islocal,fname)
6901" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006902" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006903
6904 " sanity check
6905 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006906" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006907 return
6908 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006909 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006910
Bram Moolenaar97d62492012-11-15 21:28:22 +01006911 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006913 if a:fname =~ '^\a'
6914 let leader= '\<'
6915 else
6916 let leader= ''
6917 endif
6918 if a:fname =~ '\a$'
6919 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6920 else
6921 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6922 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006923
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006925 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006926" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6927" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6928" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006929 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930
6931 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006932 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006933" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006934 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006935 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936
6937 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006938 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006939" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6941 if s:netrwmarkfilelist_{curbufnr} == []
6942 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006943" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006944 call s:NetrwUnmarkList(curbufnr,curdir)
6945 else
6946 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006947" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006948 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006949 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 for fname in s:netrwmarkfilelist_{curbufnr}
6951 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006952 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006953 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006954 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955 endif
6956 let first= 0
6957 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006958" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006959 endif
6960 endif
6961
6962 else
6963 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006964" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006966" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006968 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6969" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006970
6971 " build initial markfile matching pattern
6972 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006973 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006974 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006975 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006976 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006977" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978 endif
6979
6980 " handle global markfilelist
6981 if exists("s:netrwmarkfilelist")
6982 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6983 if index(s:netrwmarkfilelist,dname) == -1
6984 " append new filename to global markfilelist
6985 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006986" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006987 else
6988 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006989" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6990" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006991 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006992" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006994" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006995 unlet s:netrwmarkfilelist
6996 endif
6997 endif
6998 else
6999 " initialize new global-directory markfilelist
7000 let s:netrwmarkfilelist= []
7001 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007002" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007003 endif
7004
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007005 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02007006 if has("syntax") && exists("g:syntax_on") && g:syntax_on
7007 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
7008" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
7009 if exists("g:did_drchip_netrwlist_syntax")
7010 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
7011 endif
7012 else
7013" " call Decho("2match none",'~'.expand("<slnum>"))
7014 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007015 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007016 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007017 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007018" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7019" 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 +00007020endfun
7021
7022" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007023" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7024" mA: move the argument list to marked file list (tomflist=1)
7025" Uses the global marked file list
7026fun! s:NetrwMarkFileArgList(islocal,tomflist)
7027" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7028
7029 let svpos = winsaveview()
7030" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7031 let curdir = s:NetrwGetCurdir(a:islocal)
7032 let curbufnr = bufnr("%")
7033
7034 if a:tomflist
7035 " mA: move argument list to marked file list
7036 while argc()
7037 let fname= argv(0)
7038" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7039 exe "argdel ".fnameescape(fname)
7040 call s:NetrwMarkFile(a:islocal,fname)
7041 endwhile
7042
7043 else
7044 " ma: move marked file list to argument list
7045 if exists("s:netrwmarkfilelist")
7046
7047 " for every filename in the marked list
7048 for fname in s:netrwmarkfilelist
7049" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7050 exe "argadd ".fnameescape(fname)
7051 endfor " for every file in the marked list
7052
7053 " unmark list and refresh
7054 call s:NetrwUnmarkList(curbufnr,curdir)
7055 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7056" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7057 NetrwKeepj call winrestview(svpos)
7058 endif
7059 endif
7060
7061" call Dret("s:NetrwMarkFileArgList")
7062endfun
7063
7064" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007065" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7066" compress/decompress files using the programs
7067" in g:netrw_compress and g:netrw_uncompress,
7068" using g:netrw_compress_suffix to know which to
7069" do. By default:
7070" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007071" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007072fun! s:NetrwMarkFileCompress(islocal)
7073" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007074 let svpos = winsaveview()
7075" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007076 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077 let curbufnr = bufnr("%")
7078
Bram Moolenaarff034192013-04-24 18:51:19 +02007079 " sanity check
7080 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007081 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007082" call Dret("s:NetrwMarkFileCompress")
7083 return
7084 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007085" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007086
Bram Moolenaar446cb832008-06-24 21:56:24 +00007087 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007088
7089 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007090 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007091 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007092" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007093 if exists("g:netrw_decompress['".sfx."']")
7094 " fname has a suffix indicating that its compressed; apply associated decompression routine
7095 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007096" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007097 let exe= netrw#WinPath(exe)
7098 if a:islocal
7099 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007100 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007101 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007102 call system(exe." ".fname)
7103 if v:shell_error
7104 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007105 endif
7106 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007107 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7108 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007109 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007110
Bram Moolenaarff034192013-04-24 18:51:19 +02007111 endif
7112 unlet sfx
7113
Bram Moolenaar446cb832008-06-24 21:56:24 +00007114 if exists("exe")
7115 unlet exe
7116 elseif a:islocal
7117 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007118 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007119 if v:shell_error
7120 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7121 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007122 else
7123 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007124 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007125 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007126 endfor " for every file in the marked list
7127
Bram Moolenaar446cb832008-06-24 21:56:24 +00007128 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007129 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007130" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7131 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007132 endif
7133" call Dret("s:NetrwMarkFileCompress")
7134endfun
7135
7136" ---------------------------------------------------------------------
7137" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7138" If no marked files, then set up directory as the
7139" target. Currently does not support copying entire
7140" directories. Uses the local-buffer marked file list.
7141" Returns 1=success (used by NetrwMarkFileMove())
7142" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007143fun! s:NetrwMarkFileCopy(islocal,...)
7144" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7145
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007146 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007147 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007148 if b:netrw_curdir !~ '/$'
7149 if !exists("b:netrw_curdir")
7150 let b:netrw_curdir= curdir
7151 endif
7152 let b:netrw_curdir= b:netrw_curdir."/"
7153 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007154
Bram Moolenaarff034192013-04-24 18:51:19 +02007155 " sanity check
7156 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007157 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007158" call Dret("s:NetrwMarkFileCopy")
7159 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007160 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007161" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007162
Bram Moolenaar446cb832008-06-24 21:56:24 +00007163 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007164 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007165" call Dret("s:NetrwMarkFileCopy 0")
7166 return 0
7167 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007168" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007169
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007170 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007171 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007172" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007173 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007174 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7175" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7176 return
7177 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007178
7179 " copy marked files while within the same directory (ie. allow renaming)
7180 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7181 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7182 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007183" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007184 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007185 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7186 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007187" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007188 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007189 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007190 let oldname = a:1
7191 else
7192 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007193" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007194 let s:recursive= 1
7195 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7196 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7197 if ret == 0
7198 break
7199 endif
7200 endfor
7201 unlet s:recursive
7202 call s:NetrwUnmarkList(curbufnr,curdir)
7203" call Dret("s:NetrwMarkFileCopy ".ret)
7204 return ret
7205 endif
7206
7207 call inputsave()
7208 let newname= input("Copy ".oldname." to : ",oldname,"file")
7209 call inputrestore()
7210 if newname == ""
7211" call Dret("s:NetrwMarkFileCopy 0")
7212 return 0
7213 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007214 let args= s:ShellEscape(oldname)
7215 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007216 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007217 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7218 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007219 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007220 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7221 let args= substitute(args,'/','\\','g')
7222 let tgt = substitute(tgt, '/','\\','g')
7223 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007224 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7225 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7226 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7227 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7228" call Decho("args <".args.">",'~'.expand("<slnum>"))
7229" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007230 if isdirectory(s:NetrwFile(args))
7231" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007232 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007233" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007234 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7235 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7236 " contents to a target. One must append the source directory name to the target to get xcopy to
7237 " do the right thing.
7238 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007239" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007240 endif
7241 else
7242 let copycmd= g:netrw_localcopycmd
7243 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007244 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007245 let copycmd = substitute(copycmd,'\s.*$','','')
7246 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007247 let copycmd = netrw#WinPath(copycmd).copycmdargs
7248 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007249 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007250 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007251" call Decho("args <".args.">",'~'.expand("<slnum>"))
7252" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7253" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7254" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007255 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007256 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007257 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007258 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 +01007259 else
7260 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7261 endif
7262" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007263 return 0
7264 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007265
7266 elseif a:islocal && !s:netrwmftgt_islocal
7267 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007268" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007269 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007270
7271 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007272 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007273" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007274 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007275
7276 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007277 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007278" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279 let curdir = getcwd()
7280 let tmpdir = s:GetTempfile("")
7281 if tmpdir !~ '/'
7282 let tmpdir= curdir."/".tmpdir
7283 endif
7284 if exists("*mkdir")
7285 call mkdir(tmpdir)
7286 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007287 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007288 if v:shell_error != 0
7289 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 +01007290" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007291 return
7292 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007293 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007294 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007295 if s:NetrwLcd(tmpdir)
7296" call Dret("s:NetrwMarkFileCopy : lcd failure")
7297 return
7298 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007299 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007300 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007301 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007302 if getcwd() == tmpdir
7303 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007304 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007305 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007306 if s:NetrwLcd(curdir)
7307" call Dret("s:NetrwMarkFileCopy : lcd failure")
7308 return
7309 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007310 if delete(tmpdir,"d")
7311 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007312 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007313 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007314 if s:NetrwLcd(curdir)
7315" call Dret("s:NetrwMarkFileCopy : lcd failure")
7316 return
7317 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007318 endif
7319 endif
7320 endif
7321
7322 " -------
7323 " cleanup
7324 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007325" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007326 " remove markings from local buffer
7327 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007328" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7329" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7330" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7331" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7332" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7333" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7334 if exists("s:recursive")
7335" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7336 else
7337" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007338 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007339 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007340 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007341 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007342 else
7343 " refresh local and targets for fast browsing
7344 if !exists("s:recursive")
7345 " remove markings from local buffer
7346" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7347 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7348 endif
7349
7350 " refresh buffers
7351 if s:netrwmftgt_islocal
7352" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7353 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7354 endif
7355 if a:islocal && s:netrwmftgt != curdir
7356" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7357 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7358 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007359 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007360
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361" call Dret("s:NetrwMarkFileCopy 1")
7362 return 1
7363endfun
7364
7365" ---------------------------------------------------------------------
7366" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7367" invoke vim's diff mode on the marked files.
7368" Either two or three files can be so handled.
7369" Uses the global marked file list.
7370fun! s:NetrwMarkFileDiff(islocal)
7371" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7372 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007373
Bram Moolenaarff034192013-04-24 18:51:19 +02007374 " sanity check
7375 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007376 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007377" call Dret("s:NetrwMarkFileDiff")
7378 return
7379 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007380 let curdir= s:NetrwGetCurdir(a:islocal)
7381" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007382
Bram Moolenaara6878372014-03-22 21:02:50 +01007383 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007384 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007385 for fname in s:netrwmarkfilelist
7386 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007388" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007389 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390 diffthis
7391 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007392 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007393" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007394 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007395 diffthis
7396 else
7397 break
7398 endif
7399 endfor
7400 call s:NetrwUnmarkList(curbufnr,curdir)
7401 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007402
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403" call Dret("s:NetrwMarkFileDiff")
7404endfun
7405
7406" ---------------------------------------------------------------------
7407" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7408" Uses global markfilelist
7409fun! s:NetrwMarkFileEdit(islocal)
7410" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7411
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007412 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007413 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007414
7415 " sanity check
7416 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007417 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007418" call Dret("s:NetrwMarkFileEdit")
7419 return
7420 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007422
Bram Moolenaar446cb832008-06-24 21:56:24 +00007423 if exists("s:netrwmarkfilelist_{curbufnr}")
7424 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007425 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007426 " unmark markedfile list
7427" call s:NetrwUnmarkList(curbufnr,curdir)
7428 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007429" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007430 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007431 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007432 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007433
Bram Moolenaar446cb832008-06-24 21:56:24 +00007434" call Dret("s:NetrwMarkFileEdit")
7435endfun
7436
7437" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007438" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007439fun! s:NetrwMarkFileQFEL(islocal,qfel)
7440" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7441 call s:NetrwUnmarkAll()
7442 let curbufnr= bufnr("%")
7443
7444 if !empty(a:qfel)
7445 for entry in a:qfel
7446 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007447" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007448 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007449" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007450 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7451 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7452 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7453 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007454" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007455 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7456 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007457" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007458 endif
7459 endfor
7460 echo "(use me to edit marked files)"
7461 else
7462 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7463 endif
7464
7465" call Dret("s:NetrwMarkFileQFEL")
7466endfun
7467
7468" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007469" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7470" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7471" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7472fun! s:NetrwMarkFileExe(islocal,enbloc)
7473" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007474 let svpos = winsaveview()
7475" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007476 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007477 let curbufnr = bufnr("%")
7478
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007479 if a:enbloc == 0
7480 " individually apply command to files, one at a time
7481 " sanity check
7482 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7483 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7484" call Dret("s:NetrwMarkFileExe")
7485 return
7486 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007487" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007488
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007489 if exists("s:netrwmarkfilelist_{curbufnr}")
7490 " get the command
7491 call inputsave()
7492 let cmd= input("Enter command: ","","file")
7493 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007494" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007495 if cmd == ""
7496" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7497 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007498 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007499
7500 " apply command to marked files, individually. Substitute: filename -> %
7501 " If no %, then append a space and the filename to the command
7502 for fname in s:netrwmarkfilelist_{curbufnr}
7503 if a:islocal
7504 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007505 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007506 endif
7507 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007508 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007509 endif
7510 if cmd =~ '%'
7511 let xcmd= substitute(cmd,'%',fname,'g')
7512 else
7513 let xcmd= cmd.' '.fname
7514 endif
7515 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007516" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007517 let ret= system(xcmd)
7518 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007519" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007520 let ret= s:RemoteSystem(xcmd)
7521 endif
7522 if v:shell_error < 0
7523 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7524 break
7525 else
7526 echo ret
7527 endif
7528 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007529
7530 " unmark marked file list
7531 call s:NetrwUnmarkList(curbufnr,curdir)
7532
7533 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007534 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007535" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7536 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007537 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007538 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007539 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007540
7541 else " apply command to global list of files, en bloc
7542
7543 call inputsave()
7544 let cmd= input("Enter command: ","","file")
7545 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007546" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007547 if cmd == ""
7548" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7549 return
7550 endif
7551 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007552 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007553 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007554 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007555 endif
7556 if a:islocal
7557 call system(cmd)
7558 if v:shell_error < 0
7559 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7560 endif
7561 else
7562 let ret= s:RemoteSystem(cmd)
7563 endif
7564 call s:NetrwUnmarkAll()
7565
7566 " refresh the listing
7567 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007568" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7569 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007570
7571 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007572
Bram Moolenaar446cb832008-06-24 21:56:24 +00007573" call Dret("s:NetrwMarkFileExe")
7574endfun
7575
7576" ---------------------------------------------------------------------
7577" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7578" as the marked file(s) (toggles suffix presence)
7579" Uses the local marked file list.
7580fun! s:NetrwMarkHideSfx(islocal)
7581" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007582 let svpos = winsaveview()
7583" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007584 let curbufnr = bufnr("%")
7585
7586 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7587 if exists("s:netrwmarkfilelist_{curbufnr}")
7588
7589 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007590" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007591 " construct suffix pattern
7592 if fname =~ '\.'
7593 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7594 else
7595 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7596 endif
7597 " determine if its in the hiding list or not
7598 let inhidelist= 0
7599 if g:netrw_list_hide != ""
7600 let itemnum = 0
7601 let hidelist= split(g:netrw_list_hide,',')
7602 for hidepat in hidelist
7603 if sfxpat == hidepat
7604 let inhidelist= 1
7605 break
7606 endif
7607 let itemnum= itemnum + 1
7608 endfor
7609 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007610" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007611 if inhidelist
7612 " remove sfxpat from list
7613 call remove(hidelist,itemnum)
7614 let g:netrw_list_hide= join(hidelist,",")
7615 elseif g:netrw_list_hide != ""
7616 " append sfxpat to non-empty list
7617 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7618 else
7619 " set hiding list to sfxpat
7620 let g:netrw_list_hide= sfxpat
7621 endif
7622 endfor
7623
7624 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007625 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007626" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7627 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007628 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007629 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007630 endif
7631
7632" call Dret("s:NetrwMarkHideSfx")
7633endfun
7634
7635" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007636" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007637" Uses the local marked-file list.
7638fun! s:NetrwMarkFileVimCmd(islocal)
7639" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007640 let svpos = winsaveview()
7641" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007642 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007643 let curbufnr = bufnr("%")
7644
Bram Moolenaarff034192013-04-24 18:51:19 +02007645 " sanity check
7646 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007647 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007648" call Dret("s:NetrwMarkFileVimCmd")
7649 return
7650 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007651" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007652
Bram Moolenaar15146672011-10-20 22:22:38 +02007653 if exists("s:netrwmarkfilelist_{curbufnr}")
7654 " get the command
7655 call inputsave()
7656 let cmd= input("Enter vim command: ","","file")
7657 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007658" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007659 if cmd == ""
7660" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7661 return
7662 endif
7663
7664 " apply command to marked files. Substitute: filename -> %
7665 " If no %, then append a space and the filename to the command
7666 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007667" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007668 if a:islocal
7669 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007670 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007671" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007672 exe cmd
7673 exe "sil! keepalt wq!"
7674 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007675" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007676 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007677 endif
7678 endfor
7679
7680 " unmark marked file list
7681 call s:NetrwUnmarkList(curbufnr,curdir)
7682
7683 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007684 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007685" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7686 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007687 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007688 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007689 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007690
Bram Moolenaar15146672011-10-20 22:22:38 +02007691" call Dret("s:NetrwMarkFileVimCmd")
7692endfun
7693
7694" ---------------------------------------------------------------------
7695" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7696" as the marked file(s) (toggles suffix presence)
7697" Uses the local marked file list.
7698fun! s:NetrwMarkHideSfx(islocal)
7699" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007700 let svpos = winsaveview()
7701" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007702 let curbufnr = bufnr("%")
7703
7704 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7705 if exists("s:netrwmarkfilelist_{curbufnr}")
7706
7707 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007708" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007709 " construct suffix pattern
7710 if fname =~ '\.'
7711 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7712 else
7713 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7714 endif
7715 " determine if its in the hiding list or not
7716 let inhidelist= 0
7717 if g:netrw_list_hide != ""
7718 let itemnum = 0
7719 let hidelist= split(g:netrw_list_hide,',')
7720 for hidepat in hidelist
7721 if sfxpat == hidepat
7722 let inhidelist= 1
7723 break
7724 endif
7725 let itemnum= itemnum + 1
7726 endfor
7727 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007728" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007729 if inhidelist
7730 " remove sfxpat from list
7731 call remove(hidelist,itemnum)
7732 let g:netrw_list_hide= join(hidelist,",")
7733 elseif g:netrw_list_hide != ""
7734 " append sfxpat to non-empty list
7735 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7736 else
7737 " set hiding list to sfxpat
7738 let g:netrw_list_hide= sfxpat
7739 endif
7740 endfor
7741
7742 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007743 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007744" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7745 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007746 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007747 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007748 endif
7749
7750" call Dret("s:NetrwMarkHideSfx")
7751endfun
7752
7753" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007754" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7755" Uses the global markfilelist
7756fun! s:NetrwMarkFileGrep(islocal)
7757" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007758 let svpos = winsaveview()
7759" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007760 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007761 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762
7763 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007764" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007765 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007766" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007767 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007768 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007769" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007770 let netrwmarkfilelist= "*"
7771 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007772
Bram Moolenaarff034192013-04-24 18:51:19 +02007773 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007774" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 call inputsave()
7776 let pat= input("Enter pattern: ","")
7777 call inputrestore()
7778 let patbang = ""
7779 if pat =~ '^!'
7780 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007781 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007782 endif
7783 if pat =~ '^\i'
7784 let pat = escape(pat,'/')
7785 let pat = '/'.pat.'/'
7786 else
7787 let nonisi = pat[0]
7788 endif
7789
7790 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007792 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007793 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007794 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007795 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007796" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7797 return
7798 endtry
7799 echo "(use :cn, :cp to navigate, :Rex to return)"
7800
7801 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007802" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7803 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007804
7805 if exists("nonisi")
7806 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007807" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007808 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007809 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007810 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007811 endif
7812
7813" call Dret("s:NetrwMarkFileGrep")
7814endfun
7815
7816" ---------------------------------------------------------------------
7817" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7818" uses the global marked file list
7819" s:netrwmfloc= 0: target directory is remote
7820" = 1: target directory is local
7821fun! s:NetrwMarkFileMove(islocal)
7822" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007823 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007824 let curbufnr = bufnr("%")
7825
7826 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007827 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007828 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007829" call Dret("s:NetrwMarkFileMove")
7830 return
7831 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007832" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007833
Bram Moolenaar446cb832008-06-24 21:56:24 +00007834 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007835 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007836" call Dret("s:NetrwMarkFileCopy 0")
7837 return 0
7838 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007840
7841 if a:islocal && s:netrwmftgt_islocal
7842 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("move from local to local",'~'.expand("<slnum>"))
7844" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007845 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007846 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7847" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7848 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007849 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007850 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007851" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007852 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007853 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007854" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007855 if g:netrw_localmovecmd =~ '\s'
7856 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7857 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7858 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007859" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007860 else
7861 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007862" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007863 endif
7864 else
7865 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007866" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007867 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007868 for fname in s:netrwmarkfilelist_{bufnr("%")}
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 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7874 let fname= substitute(fname,'/','\\','g')
Bram Moolenaar71badf92023-04-22 22:40:14 +01007875 if g:netrw_keepdir
7876 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7877 let fname= b:netrw_curdir."\\".fname
7878 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007879 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007880" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007881 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007882 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007883 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007884 call netrw#ErrorMsg(s:ERROR,"move failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",100)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007885 else
7886 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7887 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007888 break
7889 endif
7890 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007891
7892 elseif a:islocal && !s:netrwmftgt_islocal
7893 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("move from local to remote",'~'.expand("<slnum>"))
7895" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007896 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007897 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007898" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007899 for fname in mflist
7900 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7901 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7902 endfor
7903 unlet mflist
7904
7905 elseif !a:islocal && s:netrwmftgt_islocal
7906 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007907" call Decho("move from remote to local",'~'.expand("<slnum>"))
7908" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007910 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007911" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007912 for fname in mflist
7913 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7914 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7915 endfor
7916 unlet mflist
7917
7918 elseif !a:islocal && !s:netrwmftgt_islocal
7919 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007920" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7921" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007922 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007923 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007924" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007925 for fname in mflist
7926 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7927 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7928 endfor
7929 unlet mflist
7930 endif
7931
7932 " -------
7933 " cleanup
7934 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007935" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007936
7937 " remove markings from local buffer
7938 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7939
7940 " refresh buffers
7941 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007942" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007943 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007944 endif
7945 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007946" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007947 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007949 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007950" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007951 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007952 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007953
Bram Moolenaar446cb832008-06-24 21:56:24 +00007954" call Dret("s:NetrwMarkFileMove")
7955endfun
7956
7957" ---------------------------------------------------------------------
7958" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7959" using the hardcopy command. Local marked-file list only.
7960fun! s:NetrwMarkFilePrint(islocal)
7961" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7962 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007963
7964 " sanity check
7965 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007966 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007967" call Dret("s:NetrwMarkFilePrint")
7968 return
7969 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007970" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7971 let curdir= s:NetrwGetCurdir(a:islocal)
7972
Bram Moolenaar446cb832008-06-24 21:56:24 +00007973 if exists("s:netrwmarkfilelist_{curbufnr}")
7974 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007975 call s:NetrwUnmarkList(curbufnr,curdir)
7976 for fname in netrwmarkfilelist
7977 if a:islocal
7978 if g:netrw_keepdir
7979 let fname= s:ComposePath(curdir,fname)
7980 endif
7981 else
7982 let fname= curdir.fname
7983 endif
7984 1split
7985 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007986" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007987 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007988" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007989 hardcopy
7990 q
7991 endfor
7992 2match none
7993 endif
7994" call Dret("s:NetrwMarkFilePrint")
7995endfun
7996
7997" ---------------------------------------------------------------------
7998" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7999" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02008000" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00008001fun! s:NetrwMarkFileRegexp(islocal)
8002" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
8003
8004 " get the regular expression
8005 call inputsave()
8006 let regexp= input("Enter regexp: ","","file")
8007 call inputrestore()
8008
8009 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008010 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008011" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008012 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008013" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008014 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008015 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008016 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008017 else
8018 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008019 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008020 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008021" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022
8023 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008024 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008025 if fname =~ '^'.fnameescape(curdir)
8026" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8027 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8028 else
8029" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8030 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8031 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008032 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033
8034 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008035" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008036
8037 " convert displayed listing into a filelist
8038 let eikeep = &ei
8039 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008040 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008041 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008042" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008043 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008044 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008045 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008046 sil NetrwKeepj norm! "ap
8047 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008049 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008050 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008053 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008055 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008056 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008058 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8059 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008060 call histdel("/",-1)
8061 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062 endif
8063 " convert regexp into the more usual glob-style format
8064 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008065" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008066 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008067 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008068 let filelist= getline(1,line("$"))
8069 q!
8070 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008071 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008072 endfor
8073 unlet filelist
8074 let @a = areg
8075 let &ei = eikeep
8076 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008077 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008078
8079" call Dret("s:NetrwMarkFileRegexp")
8080endfun
8081
8082" ---------------------------------------------------------------------
8083" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8084" Uses the local marked file list.
8085fun! s:NetrwMarkFileSource(islocal)
8086" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8087 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008088
8089 " sanity check
8090 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008091 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008092" call Dret("s:NetrwMarkFileSource")
8093 return
8094 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008095" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8096 let curdir= s:NetrwGetCurdir(a:islocal)
8097
Bram Moolenaar446cb832008-06-24 21:56:24 +00008098 if exists("s:netrwmarkfilelist_{curbufnr}")
8099 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008100 call s:NetrwUnmarkList(curbufnr,curdir)
8101 for fname in netrwmarkfilelist
8102 if a:islocal
8103 if g:netrw_keepdir
8104 let fname= s:ComposePath(curdir,fname)
8105 endif
8106 else
8107 let fname= curdir.fname
8108 endif
8109 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008110" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008111 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 endfor
8113 2match none
8114 endif
8115" call Dret("s:NetrwMarkFileSource")
8116endfun
8117
8118" ---------------------------------------------------------------------
8119" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8120" Uses the global markfilelist
8121fun! s:NetrwMarkFileTag(islocal)
8122" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008123 let svpos = winsaveview()
8124" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008125 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008126 let curbufnr = bufnr("%")
8127
Bram Moolenaarff034192013-04-24 18:51:19 +02008128 " sanity check
8129 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008130 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008131" call Dret("s:NetrwMarkFileTag")
8132 return
8133 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008134" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008135
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008137" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8138 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 call s:NetrwUnmarkAll()
8140
8141 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008142
8143" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8144 call system(g:netrw_ctags." ".netrwmarkfilelist)
8145 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8147 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008148
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008150 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008151 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008152 let curdir= b:netrw_curdir
8153 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008154 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008155 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008156" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008157 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008158 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 wq!
8160 endif
8161 2match none
8162 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008163" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8164 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008165 endif
8166
8167" call Dret("s:NetrwMarkFileTag")
8168endfun
8169
8170" ---------------------------------------------------------------------
8171" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008172" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008173" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008174" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008175" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008176fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008177" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8178 let svpos = winsaveview()
8179" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181 let hadtgt = exists("s:netrwmftgt")
8182 if !exists("w:netrw_bannercnt")
8183 let w:netrw_bannercnt= b:netrw_bannercnt
8184 endif
8185
8186 " set up target
8187 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008189 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8190 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008192 unlet s:netrwmftgt s:netrwmftgt_islocal
8193 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008194 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008195 endif
8196 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008197" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8198 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008199" call Dret("s:NetrwMarkFileTgt : removed target")
8200 return
8201 else
8202 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008204 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008205
8206 else
8207 " get word under cursor.
8208 " * If directory, use it for the target.
8209 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008210" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211 let curword= s:NetrwGetWord()
8212 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008214 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008215" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008216 elseif !a:islocal && tgtdir =~ '/$'
8217 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008218" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219 else
8220 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222 endif
8223 endif
8224 if a:islocal
8225 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8226 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008227" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008228 endif
8229 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008230 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008231 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8232 endif
8233 let s:netrwmftgt_islocal= a:islocal
8234
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008235 " need to do refresh so that the banner will be updated
8236 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008237 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008238" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008239 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008240 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008242 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008243 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8244 else
8245 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8246 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008247" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8248 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008249 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008250 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008251 endif
8252
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008253" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8254" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008255" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8256endfun
8257
8258" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008259" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8260fun! s:NetrwGetCurdir(islocal)
8261" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8262
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008263 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008264 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8265" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8266 elseif !exists("b:netrw_curdir")
8267 let b:netrw_curdir= getcwd()
8268" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8269 endif
8270
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008271" call Decho("b:netrw_curdir<".b:netrw_curdir."> ".((b:netrw_curdir !~ '\<\a\{3,}://')? "does not match" : "matches")." url pattern",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008272 if b:netrw_curdir !~ '\<\a\{3,}://'
8273 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008274" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008275 if g:netrw_keepdir == 0
8276 call s:NetrwLcd(curdir)
8277 endif
8278 endif
8279
8280" call Dret("s:NetrwGetCurdir <".curdir.">")
8281 return b:netrw_curdir
8282endfun
8283
8284" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008285" s:NetrwOpenFile: query user for a filename and open it {{{2
8286fun! s:NetrwOpenFile(islocal)
8287" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008288 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008289 call inputsave()
8290 let fname= input("Enter filename: ")
8291 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008292" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8293
8294 " determine if Lexplore is in use
8295 if exists("t:netrw_lexbufnr")
8296 " check if t:netrw_lexbufnr refers to a netrw window
8297" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8298 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8299 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8300" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8301 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8302 exe "NetrwKeepj e ".fnameescape(fname)
8303 let @@= ykeep
8304" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8305 endif
8306 endif
8307
8308 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008309 if fname !~ '[/\\]'
8310 if exists("b:netrw_curdir")
8311 if exists("g:netrw_quiet")
8312 let netrw_quiet_keep = g:netrw_quiet
8313 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008314 let g:netrw_quiet = 1
8315 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008316 let s:rexposn_{bufnr("%")}= winsaveview()
8317" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008318 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008319 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008320 else
8321 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8322 endif
8323 if exists("netrw_quiet_keep")
8324 let g:netrw_quiet= netrw_quiet_keep
8325 else
8326 unlet g:netrw_quiet
8327 endif
8328 endif
8329 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008330 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008331 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008332 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008333" call Dret("s:NetrwOpenFile")
8334endfun
8335
8336" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008337" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8338" For the mapping to this function be made via
8339" netrwPlugin, you'll need to have had
8340" g:netrw_usetab set to non-zero.
8341fun! netrw#Shrink()
8342" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8343 let curwin = winnr()
8344 let wiwkeep = &wiw
8345 set wiw=1
8346
8347 if &ft == "netrw"
8348 if winwidth(0) > g:netrw_wiw
8349 let t:netrw_winwidth= winwidth(0)
8350 exe "vert resize ".g:netrw_wiw
8351 wincmd l
8352 if winnr() == curwin
8353 wincmd h
8354 endif
8355" call Decho("vert resize 0",'~'.expand("<slnum>"))
8356 else
8357 exe "vert resize ".t:netrw_winwidth
8358" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8359 endif
8360
8361 elseif exists("t:netrw_lexbufnr")
8362 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8363 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8364 let t:netrw_winwidth= winwidth(0)
8365 exe "vert resize ".g:netrw_wiw
8366 wincmd l
8367 if winnr() == curwin
8368 wincmd h
8369 endif
8370" call Decho("vert resize 0",'~'.expand("<slnum>"))
8371 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8372 exe "vert resize ".t:netrw_winwidth
8373" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8374 else
8375 call netrw#Lexplore(0,0)
8376 endif
8377
8378 else
8379 call netrw#Lexplore(0,0)
8380 endif
8381 let wiw= wiwkeep
8382
8383" call Dret("netrw#Shrink")
8384endfun
8385
8386" ---------------------------------------------------------------------
8387" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8388fun! s:NetSortSequence(islocal)
8389" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8390
8391 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008392 let svpos= winsaveview()
8393" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008394 call inputsave()
8395 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8396 call inputrestore()
8397
8398 " refresh the listing
8399 let g:netrw_sort_sequence= newsortseq
8400 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008401" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8402 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008403 let @@= ykeep
8404
8405" call Dret("NetSortSequence")
8406endfun
8407
8408" ---------------------------------------------------------------------
8409" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8410" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008411" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008412fun! s:NetrwUnmarkList(curbufnr,curdir)
8413" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8414
8415 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008416 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008417 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8418 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8419 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8420 call remove(s:netrwmarkfilelist,idx) " remove from global list
8421 endfor
8422 if s:netrwmarkfilelist == []
8423 unlet s:netrwmarkfilelist
8424 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008425
Bram Moolenaar446cb832008-06-24 21:56:24 +00008426 " getting rid of the local marked-file lists is easy
8427 unlet s:netrwmarkfilelist_{a:curbufnr}
8428 endif
8429 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8430 unlet s:netrwmarkfilemtch_{a:curbufnr}
8431 endif
8432 2match none
8433" call Dret("s:NetrwUnmarkList")
8434endfun
8435
8436" ---------------------------------------------------------------------
8437" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8438fun! s:NetrwUnmarkAll()
8439" call Dfunc("s:NetrwUnmarkAll()")
8440 if exists("s:netrwmarkfilelist")
8441 unlet s:netrwmarkfilelist
8442 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008443 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008444 2match none
8445" call Dret("s:NetrwUnmarkAll")
8446endfun
8447
8448" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008449" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450fun! s:NetrwUnmarkAll2()
8451" call Dfunc("s:NetrwUnmarkAll2()")
8452 redir => netrwmarkfilelist_let
8453 let
8454 redir END
8455 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008456 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008457 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8458 for flist in netrwmarkfilelist_list
8459 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8460 unlet s:netrwmarkfilelist_{curbufnr}
8461 unlet s:netrwmarkfilemtch_{curbufnr}
8462 endfor
8463" call Dret("s:NetrwUnmarkAll2")
8464endfun
8465
8466" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008467" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8468"
8469" Marked files are in two types of lists:
8470" s:netrwmarkfilelist -- holds complete paths to all marked files
8471" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8472"
8473" Marked files suitable for use with 2match are in:
8474" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008475fun! s:NetrwUnMarkFile(islocal)
8476" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008477 let svpos = winsaveview()
8478" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008479 let curbufnr = bufnr("%")
8480
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008481 " unmark marked file list
8482 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8483 if exists("s:netrwmarkfilelist")
8484" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008485 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486 endif
8487
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008488 let ibuf= 1
8489 while ibuf < bufnr("$")
8490 if exists("s:netrwmarkfilelist_".ibuf)
8491 unlet s:netrwmarkfilelist_{ibuf}
8492 unlet s:netrwmarkfilemtch_{ibuf}
8493 endif
8494 let ibuf = ibuf + 1
8495 endwhile
8496 2match none
8497
Bram Moolenaar446cb832008-06-24 21:56:24 +00008498" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008499"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8500call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501" call Dret("s:NetrwUnMarkFile")
8502endfun
8503
8504" ---------------------------------------------------------------------
8505" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8506fun! s:NetrwMenu(domenu)
8507
8508 if !exists("g:NetrwMenuPriority")
8509 let g:NetrwMenuPriority= 80
8510 endif
8511
Bram Moolenaaradc21822011-04-01 18:03:16 +02008512 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008513" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8514
8515 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008516" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008517 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008518 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8522 if g:netrw_dirhistmax > 0
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8527 else
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8529 endif
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.11.4 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Window<tab>o o'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008545 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Tab<tab>t t'
Bram Moolenaarff034192013-04-24 18:51:19 +02008546 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8559 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8560 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8561 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8562 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8563 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8564 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8565 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8566 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8567 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8568 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8569 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8570 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8571 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8572 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8573 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8574 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8575 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.1 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Show\ All<tab>a :let g:netrw_hide=0<cr><c-L>'
8576 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.3 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Normal<tab>a :let g:netrw_hide=1<cr><c-L>'
8577 exe 'sil! menu '.g:NetrwMenuPriority.'.16.2.2 '.g:NetrwTopLvlMenu.'Style.Normal-Hide-Show.Hidden\ Only<tab>a :let g:netrw_hide=2<cr><c-L>'
8578 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8579 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.1 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Name<tab>s :let g:netrw_sort_by="name"<cr><c-L>'
8580 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.2 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Time<tab>s :let g:netrw_sort_by="time"<cr><c-L>'
8581 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Size<tab>s :let g:netrw_sort_by="size"<cr><c-L>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008582 exe 'sil! menu '.g:NetrwMenuPriority.'.16.4.3 '.g:NetrwTopLvlMenu.'Style.Sorting\ Method.Exten<tab>s :let g:netrw_sort_by="exten"<cr><c-L>'
Bram Moolenaarff034192013-04-24 18:51:19 +02008583 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8584 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008586 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8587 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588
8589 elseif !a:domenu
8590 let s:netrwcnt = 0
8591 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008592 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593 exe curwin."wincmd w"
8594
8595 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008596" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008597 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008598" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008599 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008600 endif
8601 endif
8602" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008603 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008604 endif
8605
8606endfun
8607
8608" ---------------------------------------------------------------------
8609" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8610" Used by the O maps (as <SID>NetrwObtain())
8611fun! s:NetrwObtain(islocal)
8612" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8613
Bram Moolenaar97d62492012-11-15 21:28:22 +01008614 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008616 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008617 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008618 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8619 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008620 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008621 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008622 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623
8624" call Dret("NetrwObtain")
8625endfun
8626
8627" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8629" If there's only one window, then the window will first be split.
8630" Returns:
8631" choice = 0 : didn't have to choose
8632" choice = 1 : saved modified file in window first
8633" choice = 2 : didn't save modified file, opened window
8634" choice = 3 : cancel open
8635fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008636" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008637
Bram Moolenaar97d62492012-11-15 21:28:22 +01008638 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008640 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008641" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008642
8643 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008644 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008646" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8647" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8648 let curword = s:NetrwGetWord()
8649 let choice = 0
8650 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8651" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008652 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008653" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008654 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008655" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008657" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008658
Bram Moolenaar8d043172014-01-23 14:24:41 +01008659 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 if lastwinnr == 1
8661 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008663 " g:netrw_preview=0: preview window shown in a horizontally split window
8664 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008666 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008667 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008668" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008669 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008671 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008672 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008673" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008674 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008675 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008676 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008677" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008678
8679 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008680" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008681 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008682" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008684" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008685 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008686" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008687 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008688" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008689" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008690" call Decho("COMBAK#12: mod=".&mod)
8691
8692 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8693 " whoops -- user trying to open file in the Lexplore window.
8694 " Use Lexplore's opening-file window instead.
8695" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8696" exe g:netrw_chgwin."wincmd w"
8697 wincmd p
8698 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8699 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008700
8701 " prevwinnr: the window number of the "prev" window
8702 " prevbufnr: the buffer number of the buffer in the "prev" window
8703 " bnrcnt : the qty of windows open on the "prev" buffer
8704 let prevwinnr = winnr()
8705 let prevbufnr = bufnr("%")
8706 let prevbufname = bufname("%")
8707 let prevmod = &mod
8708 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008709" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008710 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008711" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008712" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008713
8714 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 " and it doesn't appear in any other extant window, then ask the
8716 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008717 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008719 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008720" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008721 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008722" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008723
8724 if bnrcnt == 1 && &hidden == 0
8725 " only one copy of the modified buffer in a window, and
8726 " hidden not set, so overwriting will lose the modified file. Ask first...
8727 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008728" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008729 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008730" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008731
8732 if choice == 1
8733 " Yes -- write file & then browse
8734 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008735 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008736 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008737 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008738 exe origwin."wincmd w"
8739 let &ei = eikeep
8740 let @@ = ykeep
8741" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008742 return choice
8743 endif
8744
8745 elseif choice == 2
8746 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008747" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008748 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749
8750 else
8751 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008752" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008753 exe origwin."wincmd w"
8754 let &ei= eikeep
8755 let @@ = ykeep
8756" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008757 return choice
8758 endif
8759 endif
8760 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008761 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008763" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008764
8765 " restore b:netrw_curdir (window split/enew may have lost it)
8766 let b:netrw_curdir= curdir
8767 if a:islocal < 2
8768 if a:islocal
8769 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8770 else
8771 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8772 endif
8773 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008774 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008775" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776 return choice
8777endfun
8778
8779" ---------------------------------------------------------------------
8780" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8781" Always assumed to be local -> remote
8782" call s:NetrwUpload(filename, target)
8783" call s:NetrwUpload(filename, target, fromdirectory)
8784fun! s:NetrwUpload(fname,tgt,...)
8785" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8786
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008787 if a:tgt =~ '^\a\{3,}://'
8788 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008789 else
8790 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008792" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008793
8794 if a:0 > 0
8795 let fromdir= a:1
8796 else
8797 let fromdir= getcwd()
8798 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800
8801 if type(a:fname) == 1
8802 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008803" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008804 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8806 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8807" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 if a:tgt =~ '/$'
8809 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008811 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008813" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008814 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008816 endif
8817 q!
8818
8819 elseif type(a:fname) == 3
8820 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008821" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008822 let curdir= getcwd()
8823 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008824 if s:NetrwLcd(fromdir)
8825" call Dret("s:NetrwUpload : lcd failure")
8826 return
8827 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008828 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008829 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008830 if exists("g:netrw_port") && g:netrw_port != ""
8831 let useport= " ".g:netrw_scpport." ".g:netrw_port
8832 else
8833 let useport= ""
8834 endif
8835 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8836 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008838 if s:NetrwLcd(curdir)
8839" call Dret("s:NetrwUpload : lcd failure")
8840 return
8841 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842
8843 elseif a:tgt =~ '^ftp:'
8844 call s:NetrwMethod(a:tgt)
8845
8846 if b:netrw_method == 2
8847 " handle uploading a list of files via ftp+.netrc
8848 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008849 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008850" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008851
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008852 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008853" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854
8855 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008856 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008857" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 endif
8859
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008860 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008861" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008862
Bram Moolenaaradc21822011-04-01 18:03:16 +02008863 if tgtdir == ""
8864 let tgtdir= '/'
8865 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008866 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008867" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868
8869 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008870 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8871" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008872 endfor
8873
8874 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008875 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008876 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008877" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8878 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008879 endif
8880 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008881 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008882 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008883 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8884 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8885 else
8886 bw!|q
8887 endif
8888
8889 elseif b:netrw_method == 3
8890 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8891 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008893 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008894 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008895
8896 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008897 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008898" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endif
8903
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008904 if exists("g:netrw_uid") && g:netrw_uid != ""
8905 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008906 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008907" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008908 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008909 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008911" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008912 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008913 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008914" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008915 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008916 endif
8917
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008918 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008919" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008920
8921 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008922 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008923" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008924 endif
8925
8926 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008927 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008928" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929 endif
8930
8931 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008932 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008933" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008934 endfor
8935
8936 " perform ftp:
8937 " -i : turns off interactive prompting from ftp
8938 " -n unix : DON'T use <.netrc>, even though it exists
8939 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008940 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008941 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008942 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008943 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008944 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008945 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8946 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008947 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008948 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8949 let &debug = debugkeep
8950 let mod = 1
8951 else
8952 bw!|q
8953 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008954 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008955" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008956 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008957 endif
8958 else
8959 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8960 endif
8961 endif
8962
8963" call Dret("s:NetrwUpload")
8964endfun
8965
8966" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008967" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008968fun! s:NetrwPreview(path) range
8969" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008970" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8971" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008972 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008973 NetrwKeepj call s:NetrwOptionsSave("s:")
8974 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8975 NetrwKeepj call s:NetrwOptionsSafe(1)
8976 else
8977 NetrwKeepj call s:NetrwOptionsSafe(0)
8978 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008979 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008980" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008981 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008982" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8983 if g:netrw_preview
8984 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008985 let pvhkeep = &pvh
8986 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8987 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008988" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8989 else
8990 " horizontal split
8991 let pvhkeep = &pvh
8992 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8993 let &pvh = winheight(0) - winsz
8994" call Decho("!g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008995 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008996 " g:netrw_preview g:netrw_alto
8997 " 1 : vert 1: top -- preview window is vertically split off and on the left
8998 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8999 " 0 : 1: top -- preview window is horizontally split off and on the top
9000 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
9001 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009002 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
Bram Moolenaar85850f32019-07-19 22:05:51 +02009003 " the BufEnter event set up in netrwPlugin.vim
9004" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
9005 let eikeep = &ei
9006 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009007 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009008 let &ei= eikeep
9009" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02009010 if exists("pvhkeep")
9011 let &pvh= pvhkeep
9012 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009013 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009014 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009015 endif
9016 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009017 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, to preview your vim needs the quickfix feature compiled in",39)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009018 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009019 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009020 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009021" call Dret("NetrwPreview")
9022endfun
9023
9024" ---------------------------------------------------------------------
9025" s:NetrwRefresh: {{{2
9026fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009027" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") g:netrw_hide=".g:netrw_hide." g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009028 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009029 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009030" call Decho("setl ma noro",'~'.expand("<slnum>"))
9031" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009032 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009033 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9034 if !exists("w:netrw_treetop")
9035 if exists("b:netrw_curdir")
9036 let w:netrw_treetop= b:netrw_curdir
9037 else
9038 let w:netrw_treetop= getcwd()
9039 endif
9040 endif
9041 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9042 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009043
9044 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009045 let screenposn = winsaveview()
9046" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009047
9048" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9049" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9050 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009052 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009054 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009056
9057 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009058" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9059 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009060
9061 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009062 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9063 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9064" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9065 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9066 else
9067" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9068 2match none
9069 endif
9070 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071
Bram Moolenaar97d62492012-11-15 21:28:22 +01009072" restore
9073 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009074" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075endfun
9076
9077" ---------------------------------------------------------------------
9078" s:NetrwRefreshDir: refreshes a directory by name {{{2
9079" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009080" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009082" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083 if g:netrw_fastbrowse == 0
9084 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009085" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009086 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009087" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009088
9089 if tgtwin > 0
9090 " tgtwin is being displayed, so refresh it
9091 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009092" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009093 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009094 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009095 exe curwin."wincmd w"
9096
9097 elseif bufnr(a:dirname) > 0
9098 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009099" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9100 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101 endif
9102
9103 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009104" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009105 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009106 endif
9107" call Dret("s:NetrwRefreshDir")
9108endfun
9109
9110" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009111" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9112" window number to do its editing in.
9113" Supports [count]C where the count, if present, is used to specify
9114" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009115fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009116" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009117 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009118" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009119 if a:1 == "" " :NetrwC win#
9120 let g:netrw_chgwin= winnr()
9121 else " :NetrwC
9122 let g:netrw_chgwin= a:1
9123 endif
9124 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009125 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009126 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009127 let g:netrw_chgwin= winnr()
9128 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009129 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009130" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009131endfun
9132
9133" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009134" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9135" What this function does is to compute a priority for the patterns
9136" in the g:netrw_sort_sequence. It applies a substitute to any
9137" "files" that satisfy each pattern, putting the priority / in
9138" front. An "*" pattern handles the default priority.
9139fun! s:NetrwSetSort()
9140" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009141 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009142 if w:netrw_liststyle == s:LONGLIST
9143 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9144 else
9145 let seqlist = g:netrw_sort_sequence
9146 endif
9147 " sanity check -- insure that * appears somewhere
9148 if seqlist == ""
9149 let seqlist= '*'
9150 elseif seqlist !~ '\*'
9151 let seqlist= seqlist.',*'
9152 endif
9153 let priority = 1
9154 while seqlist != ""
9155 if seqlist =~ ','
9156 let seq = substitute(seqlist,',.*$','','e')
9157 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9158 else
9159 let seq = seqlist
9160 let seqlist = ""
9161 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009162 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009163 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009165 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009167 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009168 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009169" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170
9171 " sanity check
9172 if w:netrw_bannercnt > line("$")
9173 " apparently no files were left after a Hiding pattern was used
9174" call Dret("SetSort : no files left after hiding")
9175 return
9176 endif
9177 if seq == '*'
9178 let starpriority= spriority
9179 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009180 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009181 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009182 " sometimes multiple sorting patterns will match the same file or directory.
9183 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009184 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9185 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009186 endif
9187 let priority = priority + 1
9188 endwhile
9189 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009190 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9191 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009192 endif
9193
9194 " Following line associated with priority -- items that satisfy a priority
9195 " pattern get prefixed by ###/ which permits easy sorting by priority.
9196 " Sometimes files can satisfy multiple priority patterns -- only the latest
9197 " priority pattern needs to be retained. So, at this point, these excess
9198 " priority prefixes need to be removed, but not directories that happen to
9199 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009200 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9201 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009202 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203
9204" call Dret("SetSort")
9205endfun
9206
Bram Moolenaarff034192013-04-24 18:51:19 +02009207" ---------------------------------------------------------------------
9208" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9209" Implements [count]Tb (bookhist<b>)
9210" [count]Th (bookhist<h>)
9211" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009212fun! s:NetrwSetTgt(islocal,bookhist,choice)
9213" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009214
9215 if a:bookhist == 'b'
9216 " supports choosing a bookmark as a target using a qb-generated list
9217 let choice= a:choice - 1
9218 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009219 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009220 else
9221 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9222 endif
9223
9224 elseif a:bookhist == 'h'
9225 " supports choosing a history stack entry as a target using a qb-generated list
9226 let choice= (a:choice % g:netrw_dirhistmax) + 1
9227 if exists("g:netrw_dirhist_".choice)
9228 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009229 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009230 else
9231 echomsg "Sorry, history#".a:choice." not available!"
9232 endif
9233 endif
9234
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009235 " refresh the display
9236 if !exists("b:netrw_curdir")
9237 let b:netrw_curdir= getcwd()
9238 endif
9239 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9240
Bram Moolenaarff034192013-04-24 18:51:19 +02009241" call Dret("s:NetrwSetTgt")
9242endfun
9243
Bram Moolenaar446cb832008-06-24 21:56:24 +00009244" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009245" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246fun! s:NetrwSortStyle(islocal)
9247" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009248 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009249 let svpos= winsaveview()
9250" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009252 let g:netrw_sort_by= (g:netrw_sort_by =~# '^n')? 'time' : (g:netrw_sort_by =~# '^t')? 'size' : (g:netrw_sort_by =~# '^siz')? 'exten' : 'name'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009253 NetrwKeepj norm! 0
9254 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009255" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9256 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257
9258" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9259endfun
9260
9261" ---------------------------------------------------------------------
9262" s:NetrwSplit: mode {{{2
9263" =0 : net and o
9264" =1 : net and t
9265" =2 : net and v
9266" =3 : local and o
9267" =4 : local and t
9268" =5 : local and v
9269fun! s:NetrwSplit(mode)
9270" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9271
Bram Moolenaar97d62492012-11-15 21:28:22 +01009272 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009273 call s:SaveWinVars()
9274
9275 if a:mode == 0
9276 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009277 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009278 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009279" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009280 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009281 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009282 NetrwKeepj call s:RestoreWinVars()
9283 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 unlet s:didsplit
9285
9286 elseif a:mode == 1
9287 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009288 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009289" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009290 tabnew
9291 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009292 NetrwKeepj call s:RestoreWinVars()
9293 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009294 unlet s:didsplit
9295
9296 elseif a:mode == 2
9297 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009298 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009299 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009301 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009302 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009303 NetrwKeepj call s:RestoreWinVars()
9304 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009305 unlet s:didsplit
9306
9307 elseif a:mode == 3
9308 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009309 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009310 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009311" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009312 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009313 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009314 NetrwKeepj call s:RestoreWinVars()
9315 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009316 unlet s:didsplit
9317
9318 elseif a:mode == 4
9319 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009320 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009321 let eikeep = &ei
9322 let netrw_winnr = winnr()
9323 let netrw_line = line(".")
9324 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009325 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009326 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009327 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009328 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9329 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009330 let &ei = eikeep
9331 let netrw_curdir = s:NetrwTreeDir(0)
9332" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009334 let b:netrw_curdir = netrw_curdir
9335 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009336 NetrwKeepj call s:RestoreWinVars()
9337 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009338 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009339 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009340 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9341 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009342 let &ei= eikeep
9343 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009344 unlet s:didsplit
9345
9346 elseif a:mode == 5
9347 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009348 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009349 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009350" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009351 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009352 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009353 NetrwKeepj call s:RestoreWinVars()
9354 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009355 unlet s:didsplit
9356
9357 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009358 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009359 endif
9360
Bram Moolenaar97d62492012-11-15 21:28:22 +01009361 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009362" call Dret("s:NetrwSplit")
9363endfun
9364
9365" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009366" s:NetrwTgtMenu: {{{2
9367fun! s:NetrwTgtMenu()
9368 if !exists("s:netrw_menucnt")
9369 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009370 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009371" call Dfunc("s:NetrwTgtMenu()")
9372
9373 " the following test assures that gvim is running, has menus available, and has menus enabled.
9374 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9375 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009376" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009377 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9378 endif
9379 if !exists("s:netrw_initbookhist")
9380 call s:NetrwBookHistRead()
9381 endif
9382
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009383 " try to cull duplicate entries
9384 let tgtdict={}
9385
Bram Moolenaarff034192013-04-24 18:51:19 +02009386 " target bookmarked places
9387 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009388" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009389 let cnt= 1
9390 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009391 if has_key(tgtdict,bmd)
9392 let cnt= cnt + 1
9393 continue
9394 endif
9395 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009396 let ebmd= escape(bmd,g:netrw_menu_escape)
9397 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009399 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.1.".cnt." ".g:NetrwTopLvlMenu.'Targets.'.ebmd." :call netrw#MakeTgt('".bmd."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009400 let cnt= cnt + 1
9401 endfor
9402 endif
9403
9404 " target directory browsing history
9405 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009406" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009407 let histcnt = 1
9408 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009409 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009410 if exists("g:netrw_dirhist_{histcnt}")
9411 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009412 if has_key(tgtdict,histentry)
9413 let histcnt = histcnt + 1
9414 continue
9415 endif
9416 let tgtdict[histentry] = histcnt
9417 let ehistentry = escape(histentry,g:netrw_menu_escape)
9418" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009419 exe 'sil! menu <silent> '.g:NetrwMenuPriority.".19.2.".priority." ".g:NetrwTopLvlMenu.'Targets.'.ehistentry." :call netrw#MakeTgt('".histentry."')\<cr>"
Bram Moolenaarff034192013-04-24 18:51:19 +02009420 endif
9421 let histcnt = histcnt + 1
9422 endwhile
9423 endif
9424 endif
9425" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009426endfun
9427
9428" ---------------------------------------------------------------------
9429" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9430" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009431fun! s:NetrwTreeDir(islocal)
9432" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009433" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009434" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9435" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9436" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009437" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009438
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009439 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009440 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009441" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009442 let treedir= s:treedir
9443 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009444 unlet s:prevwinopen
9445" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009446 return treedir
9447 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009448 if exists("s:prevwinopen")
9449 unlet s:prevwinopen
9450 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009451" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452
Bram Moolenaar8d043172014-01-23 14:24:41 +01009453 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9454 let b:netrw_curdir= getcwd()
9455 endif
9456 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009457" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009458" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009460 let s:treecurpos= winsaveview()
9461" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009462" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009463
9464 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009465" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9466" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009467" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009468
9469 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009470 let curline= substitute(getline('.'),"\t -->.*$",'','')
9471 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009472" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009473 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9475 elseif curline =~ '@$'
9476" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9477 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9478" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009479 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009480" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009481 let treedir= ""
9482 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009483" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484
9485 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009486" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9487" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009488" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009489 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009490" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009491 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009492" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9493 sil! NetrwKeepj %d _
9494" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009495 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009496" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009497" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009498 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009499" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009500
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009502 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9503" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009504" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009505
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009506 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9507" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9508" let newdir = w:netrw_treetop.'/'.potentialdir
9509" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9510" let treedir = s:NetrwTreePath(newdir)
9511" let w:netrw_treetop = newdir
9512" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9513" else
9514" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009515 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009517 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009518" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009519
9520 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009521 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009522" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009523" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009524
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009525" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009526 return treedir
9527endfun
9528
9529" ---------------------------------------------------------------------
9530" s:NetrwTreeDisplay: recursive tree display {{{2
9531fun! s:NetrwTreeDisplay(dir,depth)
9532" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9533
9534 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009535 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536
9537 " install ../ and shortdir
9538 if a:depth == ""
9539 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009540" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009541 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009542 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009543 if a:dir == w:netrw_treetop
9544 let shortdir= a:dir
9545 else
9546 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9547 endif
9548 call setline(line("$")+1,a:depth.shortdir)
9549 else
9550 let shortdir= substitute(a:dir,'^.*/','','e')
9551 call setline(line("$")+1,a:depth.shortdir.'/')
9552 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009553" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009554 " append a / to dir if its missing one
9555 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009556
9557 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009558 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009559" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009560
Bram Moolenaar85850f32019-07-19 22:05:51 +02009561 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9562 if g:netrw_hide == 1
9563 " hide given patterns
9564 let listhide= split(g:netrw_list_hide,',')
9565" call Decho("listhide=".string(listhide))
9566 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009567 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009568 endfor
9569
9570 elseif g:netrw_hide == 2
9571 " show given patterns (only)
9572 let listhide= split(g:netrw_list_hide,',')
9573" call Decho("listhide=".string(listhide))
9574 let entries=[]
9575 for entry in w:netrw_treedict[dir]
9576 for pat in listhide
9577 if entry =~ pat
9578 call add(entries,entry)
9579 break
9580 endif
9581 endfor
9582 endfor
9583 let w:netrw_treedict[dir]= entries
9584 endif
9585 if depth != ""
9586 " always remove "." and ".." entries when there's depth
9587 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9588 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9589 endif
9590
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009591" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009592 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009593 if dir =~ '/$'
9594 let direntry= substitute(dir.entry,'[@/]$','','e')
9595 else
9596 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9597 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009598" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009599 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009600" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009601 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009602 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009603" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9604 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9605 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9606" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009607 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009608 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009609" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009610 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009611 endif
9612 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009613" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009614
Bram Moolenaar446cb832008-06-24 21:56:24 +00009615" call Dret("NetrwTreeDisplay")
9616endfun
9617
9618" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009619" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9620fun! s:NetrwRefreshTreeDict(dir)
9621" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009622 if !exists("w:netrw_treedict")
9623" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9624 return
9625 endif
9626
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009627 for entry in w:netrw_treedict[a:dir]
9628 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9629" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9630
9631 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9632" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9633 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009634 let liststar = s:NetrwGlob(direntry,'*',1)
9635 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009636 let w:netrw_treedict[direntry] = liststar + listdotstar
9637" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9638
9639 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9640" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9641 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009642 let liststar = s:NetrwGlob(direntry.'/','*',1)
9643 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009644 let w:netrw_treedict[direntry]= liststar + listdotstar
9645" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9646
9647 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9648" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9649 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009650 let liststar = s:NetrwGlob(direntry.'/','*',1)
9651 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009652" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9653
9654 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009655" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009656 endif
9657 endfor
9658" call Dret("s:NetrwRefreshTreeDict")
9659endfun
9660
9661" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009663" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009665 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009666" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9668" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"),'~'.expand("<slnum>"))
9669" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009670
9671 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009672 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009673" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009675 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009676" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009677 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009678" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009680 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009681" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009683 if exists("w:netrw_treetop")
9684 let s:netrw_treetop= w:netrw_treetop
9685 else
9686 let w:netrw_treetop= getcwd()
9687 let s:netrw_treetop= w:netrw_treetop
9688 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009689
Bram Moolenaar446cb832008-06-24 21:56:24 +00009690 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009691 " insure that we have a treedict, albeit empty
9692" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693 let w:netrw_treedict= {}
9694 endif
9695
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009696 " update the dictionary for the current directory
9697" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009698" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009699 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009700 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009701" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009702 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009703
9704 " if past banner, record word
9705 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9706 let fname= expand("<cword>")
9707 else
9708 let fname= ""
9709 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009710" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9711" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009712
9713 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009714" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009715 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009716" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009717
9718 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9719 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009720" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009721 1d
9722 endwhile
9723
Bram Moolenaar13600302014-05-22 18:26:40 +02009724 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009725
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009726" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009727 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009728 endif
9729endfun
9730
9731" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009732" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009733" Normally, treetop is w:netrw_treetop, but a
9734" user of the function ( netrw#SetTreetop() )
9735" wipes that out prior to calling this function
9736fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009737" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9738 if line(".") < w:netrw_bannercnt + 2
9739 let treedir= a:treetop
9740 if treedir !~ '/$'
9741 let treedir= treedir.'/'
9742 endif
9743" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9744 return treedir
9745 endif
9746
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009747 let svpos = winsaveview()
9748" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009749 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009750" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009751 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009752" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9753 let curline= getline('.')
9754" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9755 if curline =~ '/$'
9756" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9757 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9758" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9759 elseif curline =~ '@\s\+-->'
9760" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9761 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9762 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9763" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009764 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009765" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009766 let treedir= ""
9767 endif
9768 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009769" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9770" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009771 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9772 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9773 let treedir= dirname.treedir
9774 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009775" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009776 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009777" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009778 if a:treetop =~ '/$'
9779 let treedir= a:treetop.treedir
9780 else
9781 let treedir= a:treetop.'/'.treedir
9782 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009783" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009784 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009785" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009786" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9787 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009788" call Dret("s:NetrwTreePath <".treedir.">")
9789 return treedir
9790endfun
9791
9792" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009793" s:NetrwWideListing: {{{2
9794fun! s:NetrwWideListing()
9795
9796 if w:netrw_liststyle == s:WIDELIST
9797" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9798 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009799 " cpf: characters per filename
9800 " fpl: filenames per line
9801 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009802 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009803 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009804" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805 let b:netrw_cpf= 0
9806 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009807 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009808 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9809 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009810 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009811 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812" call Dret("NetrwWideListing")
9813 return
9814 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009815 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009816 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009817" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009818
9819 " determine qty files per line (fpl)
9820 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9821 if w:netrw_fpl <= 0
9822 let w:netrw_fpl= 1
9823 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009825
9826 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009827 " fpc: files per column of wide listing
9828 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009829 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9831 let newcolstart = w:netrw_bannercnt + fpc
9832 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009833" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009834 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009835" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009836 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009837 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 while line("$") >= newcolstart
9840 if newcolend > line("$") | let newcolend= line("$") | endif
9841 let newcolqty= newcolend - newcolstart
9842 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009843 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009844 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009845 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009846 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009847 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009849 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009850 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009851 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009852 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009853" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009854 if @* != keepregstar | sil! let @* = keepregstar | endif
9855 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009856 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009857 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9858 NetrwKeepj call histdel("/",-1)
9859 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9860 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009861" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009862 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009863 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009864" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009865" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009866 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009867 else
9868 if hasmapto("w","n")
9869 sil! nunmap <buffer> w
9870 endif
9871 if hasmapto("b","n")
9872 sil! nunmap <buffer> b
9873 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009874 endif
9875
9876endfun
9877
9878" ---------------------------------------------------------------------
9879" s:PerformListing: {{{2
9880fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009881" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9882" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009883" call Decho("settings: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (enter)"." ei<".&ei.">",'~'.expand("<slnum>"))
9884 sil! NetrwKeepj %d _
9885" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886
Bram Moolenaar15146672011-10-20 22:22:38 +02009887 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009888" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009889 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009890
Bram Moolenaar85850f32019-07-19 22:05:51 +02009891 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009892 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009894
9895" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009896" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897" endif " Decho
9898
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009899" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9901 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9903 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009904 endif
9905
9906 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009907 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009908
9909 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009910 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009911" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009912 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009913 if exists("g:netrw_pchk")
9914 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9915 " failure detections.
9916 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009917 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009918 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9919 endif
9920 if exists("g:netrw_pchk")
9921 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9922 else
9923 let curdir= b:netrw_curdir
9924 endif
9925 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9926 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9927 else
9928 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009929 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009930 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009931 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009932 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009934 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009935 let w:netrw_bannercnt= 1
9936 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9938" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939
Bram Moolenaar85850f32019-07-19 22:05:51 +02009940 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009942 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009943 let sortby= sortby." reversed"
9944 endif
9945
9946 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009947 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009949 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009950" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009951 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009952 NetrwKeepj put ='\" Sorted by '.sortby
9953 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009954 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9955 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009956" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009957 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009958 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009959 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9960 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009961 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009962" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009965
Bram Moolenaar85850f32019-07-19 22:05:51 +02009966 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009967 if g:netrw_banner
9968 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009969" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009972 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009973 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009974 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009975 endif
9976 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009978" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009979 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009980 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982
9983 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009984 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009985" call Decho("--handle hiding/showing in banner (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009986 if g:netrw_list_hide != "" && g:netrw_hide
9987 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009988 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009989 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009990 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009991 endif
9992 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009993 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009994 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009995
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009997 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009999 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010000" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010001 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +010010002 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +010010003" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010004" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010005 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010006
10007 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010008 if g:netrw_banner
10009 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010010 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" call Decho("--w:netrw_bannercnt=".w:netrw_bannercnt." (should index line just after banner) line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010012" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010014 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010015
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010017" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010019 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010020 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010021 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010022 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010023" call Decho("w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010024" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10025 return
10026 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010027 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010028
10029 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010030 if !exists("w:netrw_bannercnt")
10031 let w:netrw_bannercnt= 0
10032 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10034" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10035" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010036
Bram Moolenaar5c736222010-01-06 20:54:52 +010010037 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010038" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" call Decho("g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010040 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010041 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010042 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010043 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010044" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010046 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010047 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010048" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010049 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050
Bram Moolenaar5c736222010-01-06 20:54:52 +010010051 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010052" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010053 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010054 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010055 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010056 else
10057 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010058 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010059 endif
10060 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010061
Bram Moolenaar446cb832008-06-24 21:56:24 +000010062 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010063" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010064 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10065 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010066
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010067 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010068 " exten: sort by extension
10069 " The histdel(...,-1) calls remove the last search from the search history
10070" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10072 NetrwKeepj call histdel("/",-1)
10073 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10074 NetrwKeepj call histdel("/",-1)
10075 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10076 NetrwKeepj call histdel("/",-1)
10077 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10078" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010079 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010080 " normal direction sorting
10081 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10082 else
10083 " reverse direction sorting
10084 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10085 endif
10086 endif
10087 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10088 NetrwKeepj call histdel("/",-1)
10089
Bram Moolenaar446cb832008-06-24 21:56:24 +000010090 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010091 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010093 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010094" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010095 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010096 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010097" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010098 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010099 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010100" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010101 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10102 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010103 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010104 endif
10105
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010106 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010107" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010108 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010109 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010110 call histdel("/",-1)
10111 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010112 endif
10113 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010114" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010115
10116 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010117" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10118" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010119 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010121 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#3)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010123
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010124 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010125 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010126" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010127 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010128 endif
10129
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010132" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10133 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010134 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10136 else
10137" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10138" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10139" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10140" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010141 endif
10142
10143 " record previous current directory
10144 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010146
10147 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10149" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#4)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010150 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010151" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#5)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010152 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#6)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010154
10155 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010157 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010158" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010159 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010160" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010161 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10162 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010163" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010164" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010165
Bram Moolenaar8d043172014-01-23 14:24:41 +010010166 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10168" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#8)",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010169" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10170 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010171 unlet s:treecurpos
10172 endif
10173
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010174" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (return)",'~'.expand("<slnum>"))
10175" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010176" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10177endfun
10178
10179" ---------------------------------------------------------------------
10180" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010181fun! s:SetupNetrwStatusLine(statline)
10182" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10183
10184 if !exists("s:netrw_setup_statline")
10185 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010187
10188 if !exists("s:netrw_users_stl")
10189 let s:netrw_users_stl= &stl
10190 endif
10191 if !exists("s:netrw_users_ls")
10192 let s:netrw_users_ls= &laststatus
10193 endif
10194
10195 " set up User9 highlighting as needed
10196 let keepa= @a
10197 redir @a
10198 try
10199 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010200 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010201 if &bg == "dark"
10202 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10203 else
10204 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10205 endif
10206 endtry
10207 redir END
10208 let @a= keepa
10209 endif
10210
10211 " set up status line (may use User9 highlighting)
10212 " insure that windows have a statusline
10213 " make sure statusline is displayed
10214 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010215 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010216" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010217 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010218
10219" call Dret("SetupNetrwStatusLine : stl=".&stl)
10220endfun
10221
Bram Moolenaar85850f32019-07-19 22:05:51 +020010222" =========================================
10223" Remote Directory Browsing Support: {{{1
10224" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010225
10226" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010227" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10228" This function assumes that a long listing will be received. Size, time,
10229" and reverse sorts will be requested of the server but not otherwise
10230" enforced here.
10231fun! s:NetrwRemoteFtpCmd(path,listcmd)
10232" call Dfunc("NetrwRemoteFtpCmd(path<".a:path."> listcmd<".a:listcmd.">) w:netrw_method=".(exists("w:netrw_method")? w:netrw_method : (exists("b:netrw_method")? b:netrw_method : "???")))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010233" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010234 " sanity check: {{{3
10235 if !exists("w:netrw_method")
10236 if exists("b:netrw_method")
10237 let w:netrw_method= b:netrw_method
10238 else
10239 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10240" call Dret("NetrwRemoteFtpCmd")
10241 return
10242 endif
10243 endif
10244
10245 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10246 let ffkeep= &ff
10247 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010248" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010249
10250 " clear off any older non-banner lines " {{{3
10251 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010252" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10253 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010254
10255 ".........................................
10256 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10257 " ftp + <.netrc>: Method #2
10258 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010259 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010260 endif
10261 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010262 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010265 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010266" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010267 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010268" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1),'~'.expand("<slnum>"))
10269 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)." ".s:ShellEscape(g:netrw_port,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010270 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010271" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10272 exe s:netrw_silentxfer." NetrwKeepj ".w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010273 endif
10274
10275 ".........................................
10276 elseif w:netrw_method == 3 " {{{3
10277 " ftp + machine,id,passwd,filename: Method #3
10278 setl ff=unix
10279 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010280 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010281 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010282 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010283 endif
10284
10285 " handle userid and password
10286 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010287" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010288 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10289 call NetUserPass("ftp:".host)
10290 endif
10291 if exists("g:netrw_uid") && g:netrw_uid != ""
10292 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010293 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010294 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010295 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010296 endif
10297 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010298 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010299 endif
10300 endif
10301
10302 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 endif
10305 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010306 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010307" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010309 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010310
10311 " perform ftp:
10312 " -i : turns off interactive prompting from ftp
10313 " -n unix : DON'T use <.netrc>, even though it exists
10314 " -n win32: quit being obnoxious about password
10315 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010316" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010317 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010318" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010319" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10320" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010321 endif
10322
10323 ".........................................
10324 elseif w:netrw_method == 9 " {{{3
10325 " sftp username@machine: Method #9
10326 " s:netrw_sftp_cmd
10327 setl ff=unix
10328
10329 " restore settings
10330 let &ff= ffkeep
10331" call Dret("NetrwRemoteFtpCmd")
10332 return
10333
10334 ".........................................
10335 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010336 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010337 endif
10338
10339 " cleanup for Windows " {{{3
10340 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010341 sil! NetrwKeepj %s/\r$//e
10342 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 endif
10344 if a:listcmd == "dir"
10345 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010346 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10347 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10348 NetrwKeepj call histdel("/",-1)
10349 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010350 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010351 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10352 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010353 endif
10354 endif
10355
10356 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10357 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010358 exe 'NetrwKeepj '.w:netrw_bannercnt
10359 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010360 endif
10361 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010362 exe 'NetrwKeepj '.w:netrw_bannercnt
10363 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010364 endif
10365
10366 " restore settings " {{{3
10367 let &ff= ffkeep
10368" call Dret("NetrwRemoteFtpCmd")
10369endfun
10370
10371" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010372" s:NetrwRemoteListing: {{{2
10373fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010374" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010375
Bram Moolenaara6878372014-03-22 21:02:50 +010010376 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10377 let w:netrw_bannercnt= s:bannercnt
10378 endif
10379 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10380 let w:netrw_bannercnt= s:bannercnt
10381 endif
10382
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010384
Bram Moolenaar446cb832008-06-24 21:56:24 +000010385 " sanity check:
10386 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010387" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010389" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 if !exists("g:netrw_quiet")
10391 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10392 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010393 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010394" call Dret("s:NetrwRemoteListing -1")
10395 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010396 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397
Bram Moolenaar8d043172014-01-23 14:24:41 +010010398 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010401 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010402 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your g:netrw_list_cmd is empty; perhaps ".g:netrw_ssh_cmd." is not executable on your system",47)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010403 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010404 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ".g:netrw_list_cmd,19)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010405 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010406 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010407
Bram Moolenaar85850f32019-07-19 22:05:51 +020010408 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010409" call Dret("s:NetrwRemoteListing -1")
10410 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010413
Bram Moolenaar446cb832008-06-24 21:56:24 +000010414 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010415" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 let w:netrw_method= b:netrw_method
10417 endif
10418
Bram Moolenaar13600302014-05-22 18:26:40 +020010419 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010420 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010421" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010422 let s:method = "ftp"
10423 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010424 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010425 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010426 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427 let listcmd= g:netrw_ftp_sizelist_cmd
10428 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010429" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010430 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010431" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010432
Bram Moolenaara6878372014-03-22 21:02:50 +010010433 " report on missing file or directory messages
10434 if search('[Nn]o such file or directory\|Failed to change directory')
10435 let mesg= getline(".")
10436 if exists("w:netrw_bannercnt")
10437 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010438 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010439 setl noma
10440 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010441 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010442 call netrw#ErrorMsg(s:WARNING,mesg,96)
10443" call Dret("s:NetrwRemoteListing : -1")
10444 return -1
10445 endif
10446
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010447 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:WIDELIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010449" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010450 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451
10452 " cleanup
10453 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010454 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10455 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010457 sil! NetrwKeepj %s/\r$//e
10458 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010460 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010462 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010463 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010466" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010467 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010469 exe "sil! NetrwKeepj ".line1
10470 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010472" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010473 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010474" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010475 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10476 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010478" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010479 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10480 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10481 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10482 NetrwKeepj call histdel("/",-1)
10483 NetrwKeepj call histdel("/",-1)
10484 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 endif
10486 endif
10487
Bram Moolenaar13600302014-05-22 18:26:40 +020010488 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010490" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010491 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010492" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010494" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10495 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010496 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010497 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10498 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10499 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10500 NetrwKeepj call histdel("/",-1)
10501 NetrwKeepj call histdel("/",-1)
10502 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010503 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010504 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10505 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010506 endif
10507 else
10508 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010509" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010510 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010512" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10513 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10514" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515 endif
10516 endif
10517
10518 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010519 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010520" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010521 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10522 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 endif
10524 endif
10525
10526 if w:netrw_liststyle == s:LONGLIST
10527 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010528" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529
10530 if s:method == "ftp"
10531 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010532 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010533 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010534 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010535 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010536 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010537 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010538 sil! NetrwKeepj 1
10539 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540 let line2= line(".")
10541 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010543 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 endif
10545 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010546 exe "sil! NetrwKeepj ".line1
10547 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010548 endif
10549
10550 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010551" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010552 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+\)\(\w.*\)$/\2\t\1/'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010554" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010555 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010556 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010557 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10558 NetrwKeepj call histdel("/",-1)
10559 NetrwKeepj call histdel("/",-1)
10560 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 endif
10562 endif
10563
10564" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010565" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010567
10568" call Dret("s:NetrwRemoteListing 0")
10569 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010570endfun
10571
Bram Moolenaar446cb832008-06-24 21:56:24 +000010572" ---------------------------------------------------------------------
10573" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10574fun! s:NetrwRemoteRm(usrhost,path) range
10575" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010576" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010577 let svpos= winsaveview()
10578" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579
10580 let all= 0
10581 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10582 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010583" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584 for fname in s:netrwmarkfilelist_{bufnr("%")}
10585 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010586 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010588 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 let all= 1
10590 endif
10591 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010592 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593
10594 else
10595 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010596" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010597
10598 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010599 let keepsol = &l:sol
10600 setl nosol
10601 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010602
10603 " remove multiple files and directories
10604 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010605 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010606 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010607 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010609 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010610 let all= 1
10611 endif
10612 let ctr= ctr + 1
10613 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010614 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615 endif
10616
10617 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010618" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010619 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010620" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10621 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622
10623" call Dret("s:NetrwRemoteRm")
10624endfun
10625
10626" ---------------------------------------------------------------------
10627" s:NetrwRemoteRmFile: {{{2
10628fun! s:NetrwRemoteRmFile(path,rmfile,all)
10629" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10630
10631 let all= a:all
10632 let ok = ""
10633
10634 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10635 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010636" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 if !all
10638 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010639" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010640 call inputsave()
10641 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10642 call inputrestore()
10643 echohl NONE
10644 if ok == ""
10645 let ok="no"
10646 endif
10647 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010648 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010649 let all= 1
10650 endif
10651 endif
10652
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010653 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010654" call Decho("case all=".all." or ok<".ok.">".(exists("w:netrw_method")? ': netrw_method='.w:netrw_method : ""),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010655 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010657 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010658 if path =~ '^\a\{3,}://'
10659 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010661 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10663 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010666" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010668 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010669 let ok="q"
10670 else
10671 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10673" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10674" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010680" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010681 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010682 if v:shell_error != 0
10683 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010684 call netrw#ErrorMsg(s:ERROR,"remove failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",102)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010685 else
10686 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10687 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010688 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010689 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010690 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010691" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010692 endif
10693 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010694 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010695" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010696 endif
10697
10698 else
10699 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010700" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701 if !all
10702 call inputsave()
10703 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10704 call inputrestore()
10705 if ok == ""
10706 let ok="no"
10707 endif
10708 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010709 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010710 let all= 1
10711 endif
10712 endif
10713
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010714 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010716 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010717 else
10718 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010719 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10720" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010721 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010722" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010723
10724 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010725" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10726 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10727" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010728 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010729" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730
10731 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010732 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010733 endif
10734 endif
10735 endif
10736
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010737 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010738" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010739 endif
10740 endif
10741
10742" call Dret("s:NetrwRemoteRmFile ".ok)
10743 return ok
10744endfun
10745
10746" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010747" s:NetrwRemoteRename: rename a remote file or directory {{{2
10748fun! s:NetrwRemoteRename(usrhost,path) range
10749" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10750
10751 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010752 let svpos = winsaveview()
10753" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010754 let ctr = a:firstline
10755 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10756
10757 " rename files given by the markfilelist
10758 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10759 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010760" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010761 if exists("subfrom")
10762 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010763" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010764 else
10765 call inputsave()
10766 let newname= input("Moving ".oldname." to : ",oldname)
10767 call inputrestore()
10768 if newname =~ '^s/'
10769 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10770 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10771 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010773 endif
10774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010775
Bram Moolenaar446cb832008-06-24 21:56:24 +000010776 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010777 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010778 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010779 let oldname= s:ShellEscape(a:path.oldname)
10780 let newname= s:ShellEscape(a:path.newname)
10781" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010782 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010783 endif
10784
10785 endfor
10786 call s:NetrwUnMarkFile(1)
10787
10788 else
10789
10790 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010791 let keepsol= &l:sol
10792 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010793 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010794 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010795
10796 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010797" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010798
10799 call inputsave()
10800 let newname= input("Moving ".oldname." to : ",oldname)
10801 call inputrestore()
10802
10803 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10804 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10805 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010806 let oldname= s:ShellEscape(a:path.oldname)
10807 let newname= s:ShellEscape(a:path.newname)
10808" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010809 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010810 endif
10811
10812 let ctr= ctr + 1
10813 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010814 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010815 endif
10816
10817 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010818 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010819" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10820 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010821
10822" call Dret("NetrwRemoteRename")
10823endfun
10824
Bram Moolenaar85850f32019-07-19 22:05:51 +020010825" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010826" Local Directory Browsing Support: {{{1
10827" ==========================================
10828
10829" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010830" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010831" Should accept: file://localhost/etc/fstab
10832" file:///etc/fstab
10833" file:///c:/WINDOWS/clock.avi
10834" file:///c|/WINDOWS/clock.avi
10835" file://localhost/c:/WINDOWS/clock.avi
10836" file://localhost/c|/WINDOWS/clock.avi
10837" file://c:/foo.txt
10838" file:///c:/foo.txt
10839" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
Bram Moolenaar85850f32019-07-19 22:05:51 +020010840fun! netrw#FileUrlEdit(fname)
10841" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010842 let fname = a:fname
10843 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010844" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010845 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010847 endif
10848 if (has("win32") || has("win95") || has("win64") || has("win16"))
10849 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010850" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010851 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853 endif
10854 endif
10855 let fname2396 = netrw#RFC2396(fname)
10856 let fname2396e= fnameescape(fname2396)
10857 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10858 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010859" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010860 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010861" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010862 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10863 endif
10864 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010865
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010866" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10867" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010868 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010869 exe 'NetrwKeepj keepalt edit '.plainfname
10870 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10871
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010872" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010873" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010874 exe "sil doau BufReadPost ".fname2396e
10875endfun
10876
10877" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010878" netrw#LocalBrowseCheck: {{{2
10879fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010880 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010881 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10882 "
10883 " unfortunate interaction -- split window debugging can't be used here, must use
10884 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10885 " another call to LocalBrowseCheck() when attempts to write
10886 " to the DBG buffer are made.
10887 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010888 " The &ft == "netrw" test was installed because the BufEnter event
10889 " would hit when re-entering netrw windows, creating unexpected
10890 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010891" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010892" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +010010894 " getting E930: Cannot use :redir inside execute
10895"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10897" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010898
Bram Moolenaar97d62492012-11-15 21:28:22 +010010899 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900 if isdirectory(s:NetrwFile(a:dirname))
10901" call Decho("is-directory ft<".&ft."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : " doesn't exist")."> dirname<".a:dirname.">"." line($)=".line("$")." ft<".&ft."> g:netrw_fastbrowse=".g:netrw_fastbrowse,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010902
Bram Moolenaar97d62492012-11-15 21:28:22 +010010903 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010904" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10905" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010906 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010907
Bram Moolenaar446cb832008-06-24 21:56:24 +000010908 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010910 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010911
Bram Moolenaar5c736222010-01-06 20:54:52 +010010912 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010914 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010915 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010916 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010917" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010918" call Dret("netrw#LocalBrowseCheck")
10919 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010920 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010921
Bram Moolenaar85850f32019-07-19 22:05:51 +020010922 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10924 " AND IF the listing style is not a tree listing
10925 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010926" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010927 let ibuf = 1
10928 let buflast = bufnr("$")
10929 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010930 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10931 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010932 endif
10933 let ibuf= ibuf + 1
10934 endwhile
10935 endif
10936 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010937" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
10938" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010939 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010940" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010941endfun
10942
10943" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010944" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010945" performed any shell command. The idea is to cause all local-browsing
10946" buffers to be refreshed after a user has executed some shell command,
10947" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010948fun! s:LocalBrowseRefresh()
10949" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010950" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10951" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010952
Bram Moolenaar446cb832008-06-24 21:56:24 +000010953 " determine which buffers currently reside in a tab
10954 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010955" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010956 return
10957 endif
10958 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010959" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010960 return
10961 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010962 if exists("s:netrw_events") && s:netrw_events == 1
10963 " s:LocalFastBrowser gets called (indirectly) from a
10964 let s:netrw_events= 2
10965" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10966 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010967 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010968 let itab = 1
10969 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010970 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971 while itab <= tabpagenr("$")
10972 let buftablist = buftablist + tabpagebuflist()
10973 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010974 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010975 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10977" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10979 " | refresh any netrw window
10980 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010981 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010982 let ibl = 0
10983 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010984" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010985 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10986 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010987 " (ibuf not shown in a current window AND
10988 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010989" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10990 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010991 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010992" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010993 continue
10994 elseif index(tabpagebuflist(),ibuf) != -1
10995 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010996" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010997 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010998 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010999 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11000 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11001 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011004 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11005 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11006 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011007 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011008 endif
11009 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011010" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011011 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011012" call Decho("restore window: win_gotoid(".curwinid.")")
11013 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011014 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011015
Bram Moolenaara6878372014-03-22 21:02:50 +010011016" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011017endfun
11018
11019" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011020" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11021"
11022" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011024" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11025" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011026" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011027"
11028" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11029" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011030" (re-using a buffer may not be as accurate)
11031"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011032" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011033" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11034" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11035" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11036" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011037fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011038" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11039" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11040" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11041" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011042
11043 " initialize browselist, a list of buffer numbers that the local browser has used
11044 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011045" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011046 let s:netrw_browselist= []
11047 endif
11048
11049 " append current buffer to fastbrowse list
11050 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011051" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011052 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011053" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011054 endif
11055
11056 " enable autocmd events to handle refreshing/removing local browser buffers
11057 " If local browse buffer is currently showing: refresh it
11058 " If local browse buffer is currently hidden : wipe it
11059 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11060 " =1 : medium speed, re-use directory listing for remote only
11061 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011062 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11063 let s:netrw_events= 1
11064 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011065 au!
11066 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011067" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011068 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011069 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011070" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011071 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011072 endif
11073 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011074
11075 " user must have changed fastbrowse to its fast setting, so remove
11076 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011077 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011078" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011079 unlet s:netrw_events
11080 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011081 au!
11082 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011083 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011084 endif
11085
Bram Moolenaar85850f32019-07-19 22:05:51 +020011086" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011087endfun
11088
11089" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011090" s:LocalListing: does the job of "ls" for local directories {{{2
11091fun! s:LocalListing()
11092" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011093" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11094" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11095" 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 +010011096
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011097" 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
11098" 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
11099" 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 +010011100
11101 " get the list of files contained in the current directory
11102 let dirname = b:netrw_curdir
11103 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011104 let filelist = s:NetrwGlob(dirname,"*",0)
11105 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011106" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011107
11108 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11111 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011112" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011113 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011114" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115 endif
11116
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011117" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011118" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011119" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011120
11121 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11122 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11123 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11125" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" 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 +010011128
11129 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho(" ",'~'.expand("<slnum>"))
11131" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011132
11133 if getftype(filename) == "link"
11134 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 let pfile= filename."@"
11137
11138 elseif getftype(filename) == "socket"
11139 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011141 let pfile= filename."="
11142
11143 elseif getftype(filename) == "fifo"
11144 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011145" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011146 let pfile= filename."|"
11147
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011148 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011149 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011150" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011151 let pfile= filename."/"
11152
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011154 if (has("win32") || has("win95") || has("win64") || has("win16"))
11155 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11156 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011157" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011158 let pfile= filename."*"
11159 else
11160 " normal file
11161 let pfile= filename
11162 endif
11163 elseif executable(filename)
11164 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011165" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011166 let pfile= filename."*"
11167 else
11168 " normal file
11169 let pfile= filename
11170 endif
11171
11172 else
11173 " normal file
11174 let pfile= filename
11175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011176" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011177
11178 if pfile =~ '//$'
11179 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011180" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011181 endif
11182 let pfile= strpart(pfile,dirnamelen)
11183 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011184" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11185" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011186
11187 if w:netrw_liststyle == s:LONGLIST
11188 let sz = getfsize(filename)
Bram Moolenaar71badf92023-04-22 22:40:14 +010011189 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11190 let szlen = (szlen > 0) ? szlen : 0
11191 let fsz = printf("%".szlen."S",sz)
11192
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011193 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011194 let sz= s:NetrwHumanReadable(sz)
11195 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +010011196 let longfile= printf("%-".g:netrw_maxfilenamelen."S",pfile)
11197 let pfile = longfile." ".sz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011198" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011199 endif
11200
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011201 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011202 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011203 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011204" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011206 let t = getftime(filename)
11207 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar91359012019-11-30 17:57:03 +010011208" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011209 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011210 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011211
11212 elseif g:netrw_sort_by =~ "^s"
11213 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011214" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011216 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011217 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011218 let sz= s:NetrwHumanReadable(sz)
11219 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011220 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011221" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011222 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011223 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011224
11225 else
11226 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011227" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011228" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011229 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011230 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011231" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011232 endfor
11233
11234 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011235 sil! NetrwKeepj g/^$/d
11236 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011237 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011238" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011239 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11240
11241" call Dret("s:LocalListing")
11242endfun
11243
11244" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011245" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11246fun! s:NetrwLocalExecute(cmd)
11247" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11248 let ykeep= @@
11249 " sanity check
11250 if !executable(a:cmd)
11251 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11252 let @@= ykeep
11253" call Dret("s:NetrwLocalExecute")
11254 return
11255 endif
11256
11257 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011258" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011259 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011260" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261
11262 " strip any ansi escape sequences off
11263 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11264
11265 " show user the result(s)
11266 echomsg result
11267 let @@= ykeep
11268
11269" call Dret("s:NetrwLocalExecute")
11270endfun
11271
11272" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011273" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274fun! s:NetrwLocalRename(path) range
11275" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11276
11277 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011278 let ykeep = @@
11279 let ctr = a:firstline
11280 let svpos = winsaveview()
11281 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011282" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011283
11284 " rename files given by the markfilelist
11285 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11286 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011287" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011288 if exists("subfrom")
11289 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011290" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011291 else
11292 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011293 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011294 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011295 if newname =~ ''
11296 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11297 let newname = substitute(newname,'^.*','','')
11298 elseif newname =~ ''
11299 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11300 let newname = substitute(newname,'[^/]*','','')
11301 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011302 if newname =~ '^s/'
11303 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11304 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011305" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011306 let newname = substitute(oldname,subfrom,subto,'')
11307 endif
11308 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011309 if !all && filereadable(newname)
11310 call inputsave()
11311 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11312 call inputrestore()
11313 if response == "all"
11314 let all= 1
11315 elseif response != "y" && response != "yes"
11316 " refresh the directory
11317" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11318 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11319" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11320 NetrwKeepj call winrestview(svpos)
11321 let @@= ykeep
11322" call Dret("NetrwLocalRename")
11323 return
11324 endif
11325 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011326 call rename(oldname,newname)
11327 endfor
11328 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011329
Bram Moolenaar97d62492012-11-15 21:28:22 +010011330 else
11331
11332 " attempt to rename files/directories
11333 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011334 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011335
11336 " sanity checks
11337 if line(".") < w:netrw_bannercnt
11338 let ctr= ctr + 1
11339 continue
11340 endif
11341 let curword= s:NetrwGetWord()
11342 if curword == "./" || curword == "../"
11343 let ctr= ctr + 1
11344 continue
11345 endif
11346
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011347 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011348 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011349" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011350
11351 call inputsave()
11352 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11353 call inputrestore()
11354
11355 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011356" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011357
11358 let ctr= ctr + 1
11359 endwhile
11360 endif
11361
11362 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011363" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011364 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011365" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11366 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011367 let @@= ykeep
11368
11369" call Dret("NetrwLocalRename")
11370endfun
11371
11372" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011373" s:NetrwLocalRm: {{{2
11374fun! s:NetrwLocalRm(path) range
11375" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011376" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011377
11378 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011379 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011380 let ret = 0
11381 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011382 let svpos = winsaveview()
11383" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011384
11385 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11386 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011387" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011388 for fname in s:netrwmarkfilelist_{bufnr("%")}
11389 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011390 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011391 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011392 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011393 let all= 1
11394 endif
11395 endfor
11396 call s:NetrwUnMarkFile(1)
11397
11398 else
11399 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011400" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011401
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011402 let keepsol= &l:sol
11403 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011404 let ctr = a:firstline
11405 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011406 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011407
11408 " sanity checks
11409 if line(".") < w:netrw_bannercnt
11410 let ctr= ctr + 1
11411 continue
11412 endif
11413 let curword= s:NetrwGetWord()
11414 if curword == "./" || curword == "../"
11415 let ctr= ctr + 1
11416 continue
11417 endif
11418 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011419 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011420 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011421 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422 let all= 1
11423 endif
11424 let ctr= ctr + 1
11425 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011426 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011427 endif
11428
11429 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011430" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011431 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011432 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011433" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11434 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011435 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011436 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011437
11438" call Dret("s:NetrwLocalRm")
11439endfun
11440
11441" ---------------------------------------------------------------------
11442" s:NetrwLocalRmFile: remove file fname given the path {{{2
11443" Give confirmation prompt unless all==1
11444fun! s:NetrwLocalRmFile(path,fname,all)
11445" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011446
Bram Moolenaar446cb832008-06-24 21:56:24 +000011447 let all= a:all
11448 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011449 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11451" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452
11453 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11454 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011455" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011456 if !all
11457 echohl Statement
11458 call inputsave()
11459 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11460 call inputrestore()
11461 echohl NONE
11462 if ok == ""
11463 let ok="no"
11464 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011465" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011466 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011467" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011468 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011469 let all= 1
11470 endif
11471 endif
11472
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011473 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011474 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011475" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011476 endif
11477
11478 else
11479 " attempt to remove directory
11480 if !all
11481 echohl Statement
11482 call inputsave()
11483 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11484 call inputrestore()
11485 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11486 if ok == ""
11487 let ok="no"
11488 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011489 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011490 let all= 1
11491 endif
11492 endif
11493 let rmfile= substitute(rmfile,'[\/]$','','e')
11494
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011495 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar71badf92023-04-22 22:40:14 +010011496 if delete(rmfile,"d")
11497 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011498 endif
11499 endif
11500 endif
11501
11502" call Dret("s:NetrwLocalRmFile ".ok)
11503 return ok
11504endfun
11505
Bram Moolenaar85850f32019-07-19 22:05:51 +020011506" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011507" Support Functions: {{{1
11508
Bram Moolenaar488c6512005-08-11 20:09:58 +000011509" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011510" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11511" 0: marked file list of current buffer
11512" 1: marked file target
11513fun! netrw#Access(ilist)
11514 if a:ilist == 0
11515 if exists("s:netrwmarkfilelist_".bufnr('%'))
11516 return s:netrwmarkfilelist_{bufnr('%')}
11517 else
11518 return "no-list-buf#".bufnr('%')
11519 endif
11520 elseif a:ilist == 1
11521 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011522 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011523endfun
11524
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011525" ---------------------------------------------------------------------
11526" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11527fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011528 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011529endfun
11530
Bram Moolenaara6878372014-03-22 21:02:50 +010011531" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011532" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11533" I expect this function to be used in
11534" :PChkAssert netrw#Expose("netrwmarkfilelist")
11535" for example.
11536fun! netrw#Expose(varname)
11537" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011538 if exists("s:".a:varname)
11539 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011540" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011541 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011542" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011543 if type(retval) == 3
11544 let retval = copy(retval)
11545 let i = 0
11546 while i < len(retval)
11547 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11548 let i = i + 1
11549 endwhile
11550 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011551" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011552 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011553 else
11554" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011555 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011556 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011557" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011558 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011559 endif
11560
11561" call Dret("netrw#Expose ".string(retval))
11562 return retval
11563endfun
11564
11565" ---------------------------------------------------------------------
11566" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11567fun! netrw#Modify(varname,newvalue)
11568" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11569 exe "let s:".a:varname."= ".string(a:newvalue)
11570" call Dret("netrw#Modify")
11571endfun
11572
11573" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011574" netrw#RFC2396: converts %xx into characters {{{2
11575fun! netrw#RFC2396(fname)
11576" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11577 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11578" call Dret("netrw#RFC2396 ".fname)
11579 return fname
11580endfun
11581
11582" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011583" netrw#UserMaps: supports user-specified maps {{{2
11584" see :help function()
11585"
11586" g:Netrw_UserMaps is a List with members such as:
11587" [[keymap sequence, function reference],...]
11588"
11589" The referenced function may return a string,
11590" refresh : refresh the display
11591" -other- : this string will be executed
11592" or it may return a List of strings.
11593"
11594" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011595" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011596" Related functions:
11597" netrw#Expose(varname) -- see s:varname variables
11598" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11599" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11600fun! netrw#UserMaps(islocal)
11601" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11602" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11603
11604 " set up usermaplist
11605 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11606" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11607 for umap in g:Netrw_UserMaps
11608" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11609" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11610 " if umap[0] is a string and umap[1] is a string holding a function name
11611 if type(umap[0]) == 1 && type(umap[1]) == 1
11612" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11613 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11614 else
11615 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11616 endif
11617 endfor
11618 endif
11619" call Dret("netrw#UserMaps")
11620endfun
11621
11622" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011623" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11624fun! netrw#WinPath(path)
11625" call Dfunc("netrw#WinPath(path<".a:path.">)")
11626 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11627 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011628 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011629 " remove trailing slash (Win95)
11630 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11631 " remove escaped spaces
11632 let path = substitute(path, '\ ', ' ', 'g')
11633 " convert slashes to backslashes
11634 let path = substitute(path, '/', '\', 'g')
11635 else
11636 let path= a:path
11637 endif
11638" call Dret("netrw#WinPath <".path.">")
11639 return path
11640endfun
11641
11642" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011643" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11644" cb : bl2mf=0 add marked files to buffer list
11645" cB : bl2mf=1 use bufferlist to mark files
11646" (mnemonic: cb = copy (marked files) to buffer list)
11647fun! s:NetrwBadd(islocal,bl2mf)
11648" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11649 if a:bl2mf
11650 " cB: add buffer list to marked files
11651 redir => bufl
11652 ls
11653 redir END
11654 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11655 for fname in bufl
11656 call s:NetrwMarkFile(a:islocal,fname)
11657 endfor
11658 else
11659 " cb: add marked files to buffer list
11660 for fname in s:netrwmarkfilelist_{bufnr("%")}
11661" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11662 exe "badd ".fnameescape(fname)
11663 endfor
11664 let curbufnr = bufnr("%")
11665 let curdir = s:NetrwGetCurdir(a:islocal)
11666 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11667 endif
11668" call Dret("s:NetrwBadd")
11669endfun
11670
11671" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011672" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11673fun! s:ComposePath(base,subdir)
11674" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11675
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011676 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011677" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011678 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011679 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011680 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011681 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011682 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011683 endif
11684
Bram Moolenaar85850f32019-07-19 22:05:51 +020011685 " COMBAK: test on windows with changing to root directory: :e C:/
11686 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011687" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011688 let ret= a:subdir
11689
Bram Moolenaar85850f32019-07-19 22:05:51 +020011690 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011691" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011692 if a:base =~ '[/\\]$'
11693 let ret= a:base.a:subdir
11694 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011695 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011696 endif
11697
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011698 elseif a:base =~ '^\a\{3,}://'
11699" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011700 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11701 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11702 if a:subdir == '../'
11703 if curpath =~ '[^/]/[^/]\+/$'
11704 let curpath= substitute(curpath,'[^/]\+/$','','')
11705 else
11706 let curpath=""
11707 endif
11708 let ret= urlbase.curpath
11709 else
11710 let ret= urlbase.curpath.a:subdir
11711 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011712" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11713" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11714" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011715
11716 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011717" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011718 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11719 if a:base =~ '^//'
11720 " keeping initial '//' for the benefit of network share listing support
11721 let ret= '/'.ret
11722 endif
11723 let ret= simplify(ret)
11724 endif
11725
11726" call Dret("s:ComposePath ".ret)
11727 return ret
11728endfun
11729
11730" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011731" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11732" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11733fun! s:DeleteBookmark(fname)
11734" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11735 call s:MergeBookmarks()
11736
11737 if exists("g:netrw_bookmarklist")
11738 let indx= index(g:netrw_bookmarklist,a:fname)
11739 if indx == -1
11740 let indx= 0
11741 while indx < len(g:netrw_bookmarklist)
11742 if g:netrw_bookmarklist[indx] =~ a:fname
11743 call remove(g:netrw_bookmarklist,indx)
11744 let indx= indx - 1
11745 endif
11746 let indx= indx + 1
11747 endwhile
11748 else
11749 " remove exact match
11750 call remove(g:netrw_bookmarklist,indx)
11751 endif
11752 endif
11753
11754" call Dret("s:DeleteBookmark")
11755endfun
11756
11757" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011758" s:FileReadable: o/s independent filereadable {{{2
11759fun! s:FileReadable(fname)
11760" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11761
11762 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011763 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011764 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011765 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766 endif
11767
11768" call Dret("s:FileReadable ".ret)
11769 return ret
11770endfun
11771
11772" ---------------------------------------------------------------------
11773" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11774" Places correct suffix on end of temporary filename,
11775" using the suffix provided with fname
11776fun! s:GetTempfile(fname)
11777" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11778
11779 if !exists("b:netrw_tmpfile")
11780 " get a brand new temporary filename
11781 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011782" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011783
Bram Moolenaarc236c162008-07-13 17:41:49 +000011784 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011785" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011786
Bram Moolenaar9964e462007-05-05 17:54:07 +000011787 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011788 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11789" 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 +010011790 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011791" call Dret("s:GetTempfile getcwd<".getcwd().">")
11792 return ""
11793 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011794
Bram Moolenaar9964e462007-05-05 17:54:07 +000011795 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011796 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011797" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011798
Bram Moolenaar9964e462007-05-05 17:54:07 +000011799 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011800 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011801 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011802 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011803 if !exists("+shellslash") || !&ssl
11804 let tmpfile = substitute(tmpfile,'/','\','g')
11805 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011806 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011807 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011808 endif
11809 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011810" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011811 else
11812 " re-use temporary filename
11813 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011814" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011815 endif
11816
11817 " use fname's suffix for the temporary file
11818 if a:fname != ""
11819 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011820" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011821 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011822 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011823 elseif a:fname =~ '.txz$'
11824 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011825 else
11826 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11827 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011828" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011829 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011830" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011832" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011833 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11834 endif
11835 endif
11836
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011837" 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 +000011838" call Dret("s:GetTempfile <".tmpfile.">")
11839 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011840endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011841
11842" ---------------------------------------------------------------------
11843" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011844" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011845fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011846" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011847 if s:user == ""
11848 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11849 else
11850 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11851 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011852 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011853 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011854 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011855 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011856 else
11857 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11858 endif
11859" call Dret("s:MakeSshCmd <".sshcmd.">")
11860 return sshcmd
11861endfun
11862
11863" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011864" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11865fun! s:MakeBookmark(fname)
11866" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11867
11868 if !exists("g:netrw_bookmarklist")
11869 let g:netrw_bookmarklist= []
11870 endif
11871
11872 if index(g:netrw_bookmarklist,a:fname) == -1
11873 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011874 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011875 call add(g:netrw_bookmarklist,a:fname.'/')
11876 elseif a:fname !~ '/'
11877 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11878 else
11879 call add(g:netrw_bookmarklist,a:fname)
11880 endif
11881 call sort(g:netrw_bookmarklist)
11882 endif
11883
11884" call Dret("s:MakeBookmark")
11885endfun
11886
11887" ---------------------------------------------------------------------
11888" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11889fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011890" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011891 " get bookmarks from .netrwbook file
11892 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011893 if filereadable(s:NetrwFile(savefile))
11894" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011895 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011896" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011897 NetrwKeepj call delete(savefile)
11898 endif
11899" call Dret("s:MergeBookmarks")
11900endfun
11901
11902" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011903" s:NetrwBMShow: {{{2
11904fun! s:NetrwBMShow()
11905" call Dfunc("s:NetrwBMShow()")
11906 redir => bmshowraw
11907 menu
11908 redir END
11909 let bmshowlist = split(bmshowraw,'\n')
11910 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011911 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011912 if bmshowfuncs != []
11913 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011914 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011915 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011916 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011917 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011918 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011919" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11920endfun
11921
11922" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011923" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011924fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011925 if !exists("w:netrw_liststyle")
11926 let w:netrw_liststyle= g:netrw_liststyle
11927 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011928" 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 +020011929
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011930" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11931
Bram Moolenaaradc21822011-04-01 18:03:16 +020011932 if &ft != "netrw"
11933 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11934 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011935" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011936
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011937 elseif g:netrw_cursor == 8
11938 if w:netrw_liststyle == s:WIDELIST
11939 setl cursorline
11940 setl cursorcolumn
11941 else
11942 setl cursorline
11943 endif
11944 elseif g:netrw_cursor == 7
11945 setl cursorline
11946 elseif g:netrw_cursor == 6
11947 if w:netrw_liststyle == s:WIDELIST
11948 setl cursorline
11949 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011950 elseif g:netrw_cursor == 4
11951 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011952" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011953 setl cursorline
11954 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011955
11956 elseif g:netrw_cursor == 3
11957 " thin-long-tree: cursorline, user's cursorcolumn
11958 " wide : cursorline, cursorcolumn
11959 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011960" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011961 setl cursorline
11962 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011963 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011964" 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 +020011965 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011966 endif
11967
11968 elseif g:netrw_cursor == 2
11969 " thin-long-tree: cursorline, user's cursorcolumn
11970 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011971" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011972 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011973
11974 elseif g:netrw_cursor == 1
11975 " thin-long-tree: user's cursorline, user's cursorcolumn
11976 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011977 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011978" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011979 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011980 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011981" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011982 endif
11983
11984 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011985 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011986" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011987 let &l:cursorline = s:netrw_usercul
11988 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011989 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011990
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011991" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011992" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011993endfun
11994
11995" ---------------------------------------------------------------------
11996" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11997fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011998" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011999 if exists("s:netrw_usercul")
12000 let &l:cursorline = s:netrw_usercul
12001 endif
12002 if exists("s:netrw_usercuc")
12003 let &l:cursorcolumn = s:netrw_usercuc
12004 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012005" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012006" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12007endfun
12008
12009" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012010" s:NetrwDelete: Deletes a file. {{{2
12011" Uses Steve Hall's idea to insure that Windows paths stay
12012" acceptable. No effect on Unix paths.
12013" Examples of use: let result= s:NetrwDelete(path)
12014fun! s:NetrwDelete(path)
12015" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12016
Bram Moolenaar5c736222010-01-06 20:54:52 +010012017 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012018 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
12019 if exists("+shellslash")
12020 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012021 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012022 let result = delete(path)
12023 let &shellslash = sskeep
12024 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012025" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012026 let result= delete(path)
12027 endif
12028 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012029" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012030 let result= delete(path)
12031 endif
12032 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012033 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012034 endif
12035
12036" call Dret("s:NetrwDelete ".result)
12037 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012038endfun
12039
12040" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012041" s:NetrwBufRemover: removes a buffer that: {{{2s
12042" has buffer-id > 1
12043" is unlisted
12044" is unnamed
12045" does not appear in any window
12046fun! s:NetrwBufRemover(bufid)
12047" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12048" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12049" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12050" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12051" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12052
yasuda4dbb2662023-10-04 20:50:35 +020012053 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012054" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012055 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012056 endif
12057
12058" call Dret("s:NetrwBufRemover")
12059endfun
12060
12061" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012062" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012063fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012064" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012065" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012066
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012067 " Clean out the last buffer:
12068 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12069 " If so, delete it.
12070 call s:NetrwBufRemover(bufnr("$"))
12071
Bram Moolenaar446cb832008-06-24 21:56:24 +000012072 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012073" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012074 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12075 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12076 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12077 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12078 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12079 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12080 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12081 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12082 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12083 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12084 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12085 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12086 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12087 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12088 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12089 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12090
Bram Moolenaar85850f32019-07-19 22:05:51 +020012091 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012092" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012093 " when tree listing uses file TreeListing... a new buffer is made.
12094 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012095 " COMBAK: this causes a problem, see P43
12096" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012097 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012098 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012099 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012100" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012101 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012102
Bram Moolenaar446cb832008-06-24 21:56:24 +000012103 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012104" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012105 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12106 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12107 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12108 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12109 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12110 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12111 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12112 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12113 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12114 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12115 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12116 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12117 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12118 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12119 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12120 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12121
Bram Moolenaar5c736222010-01-06 20:54:52 +010012122 if a:0 > 0
12123 let b:netrw_curdir= a:1
12124 if b:netrw_curdir =~ '/$'
12125 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012126 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012127 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012128 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012129 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12130 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012131 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012132 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012133 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012134 endif
12135 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012136 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12137 let &l:bexpr = "netrw#BalloonHelp()"
12138 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012139
Bram Moolenaar8d043172014-01-23 14:24:41 +010012140" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012141endfun
12142
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012143" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012144" s:NetrwExe: executes a string using "!" {{{2
12145fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012146" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012147 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012148" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012149 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12150 set shell& shellcmdflag& shellxquote& shellxescape&
12151 set shellquote& shellpipe& shellredir& shellslash&
12152 exe a:cmd
12153 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12154 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012155" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012156 exe a:cmd
12157 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012158 if v:shell_error
12159 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12160 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012161" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012162endfun
12163
12164" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012165" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12166fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012167 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012168" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012169 let curbuf = bufnr("%")
12170 let curwin = winnr()
12171 let iwin = 1
12172 while iwin <= winnr("$")
12173 exe iwin."wincmd w"
12174 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12175 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12176 let winvars= w:
12177 break
12178 endif
12179 let iwin= iwin + 1
12180 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012181 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012182 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012183" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012184 for k in keys(winvars)
12185 let w:{k}= winvars[k]
12186 endfor
12187 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012188" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012189 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012190endfun
12191
Bram Moolenaara6878372014-03-22 21:02:50 +010012192" ---------------------------------------------------------------------
12193" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012194" Returns: 0=success
12195" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012196fun! s:NetrwLcd(newdir)
12197" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012198" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012199
Bram Moolenaar85850f32019-07-19 22:05:51 +020012200 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012201 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012202 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012203 catch /^Vim\%((\a\+)\)\=:E344/
12204 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12205 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012206 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012207 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12208 " forward slashes by earlier code; so check for both.
12209 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12210 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12211 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012212 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012213 endif
12214 endif
12215 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012216 let err472= 1
12217 endtry
12218
12219 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012220 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12221 if exists("w:netrw_prvdir")
12222 let a:newdir= w:netrw_prvdir
12223 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012224 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012225" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012226 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012227" 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 +010012228 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012229 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012230" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12231 return -1
12232 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012233
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012234" call Decho("getcwd <".getcwd().">")
12235" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012236" call Dret("s:NetrwLcd 0")
12237 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012238endfun
12239
Bram Moolenaar9964e462007-05-05 17:54:07 +000012240" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012241" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12242" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12243fun! s:NetrwSaveWordPosn()
12244" call Dfunc("NetrwSaveWordPosn()")
12245 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12246" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12247endfun
12248
12249" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012250" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12251" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12252fun! s:NetrwHumanReadable(sz)
12253" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12254
12255 if g:netrw_sizestyle == 'h'
12256 if a:sz >= 1000000000
12257 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12258 elseif a:sz >= 10000000
12259 let sz = printf("%d",a:sz/1000000)."m"
12260 elseif a:sz >= 1000000
12261 let sz = printf("%.1f",a:sz/1000000.0)."m"
12262 elseif a:sz >= 10000
12263 let sz = printf("%d",a:sz/1000)."k"
12264 elseif a:sz >= 1000
12265 let sz = printf("%.1f",a:sz/1000.0)."k"
12266 else
12267 let sz= a:sz
12268 endif
12269
12270 elseif g:netrw_sizestyle == 'H'
12271 if a:sz >= 1073741824
12272 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12273 elseif a:sz >= 10485760
12274 let sz = printf("%d",a:sz/1048576)."M"
12275 elseif a:sz >= 1048576
12276 let sz = printf("%.1f",a:sz/1048576.0)."M"
12277 elseif a:sz >= 10240
12278 let sz = printf("%d",a:sz/1024)."K"
12279 elseif a:sz >= 1024
12280 let sz = printf("%.1f",a:sz/1024.0)."K"
12281 else
12282 let sz= a:sz
12283 endif
12284
12285 else
12286 let sz= a:sz
12287 endif
12288
12289" call Dret("s:NetrwHumanReadable ".sz)
12290 return sz
12291endfun
12292
12293" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012294" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12295" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12296fun! s:NetrwRestoreWordPosn()
12297" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012298 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012299" call Dret("NetrwRestoreWordPosn")
12300endfun
12301
12302" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012303" s:RestoreBufVars: {{{2
12304fun! s:RestoreBufVars()
12305" call Dfunc("s:RestoreBufVars()")
12306
12307 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12308 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12309 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12310 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12311 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12312 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12313
12314" call Dret("s:RestoreBufVars")
12315endfun
12316
12317" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012318" s:RemotePathAnalysis: {{{2
12319fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012320" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012321
Bram Moolenaara6878372014-03-22 21:02:50 +010012322 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012323 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012324 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012325 let s:user = substitute(a:dirname,dirpat,'\3','')
12326 let s:machine = substitute(a:dirname,dirpat,'\4','')
12327 let s:port = substitute(a:dirname,dirpat,'\5','')
12328 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012329 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012330 if s:machine =~ '@'
12331 let dirpat = '^\(.*\)@\(.\{-}\)$'
12332 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12333 let s:machine = substitute(s:machine,dirpat,'\2','')
12334 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012335
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012336" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12337" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12338" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12339" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12340" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12341" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012342
12343" call Dret("s:RemotePathAnalysis")
12344endfun
12345
12346" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012347" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12348" Returns status
12349" Runs system() on
12350" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012351" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012352fun! s:RemoteSystem(cmd)
12353" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12354 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012355 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 +000012356 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012357 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012358 else
12359 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12360 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12361 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012362 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012363 else
12364 let cmd= cmd.' '
12365 endif
12366 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012367" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012368 let ret= system(cmd)
12369 endif
12370" call Dret("s:RemoteSystem ".ret)
12371 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012372endfun
12373
12374" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012375" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012376fun! s:RestoreWinVars()
12377" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012378 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012379 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12380 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12381 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12382 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12383 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12384 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12385 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12386 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12387 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12388 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12389 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12390 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012391 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12392 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012393 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12394 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12395 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12396" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012397endfun
12398
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012399" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012400" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12401"
12402" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12403" is true) and a command, :Rexplore, which call this function.
12404"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012405" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012406"
12407" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012408fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012409 if exists("s:netrwdrag")
12410 return
12411 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012412" 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 +010012413" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12414" 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 +010012415
12416 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012417 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012418" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012419 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012420 unlet w:netrw_rexfile
12421" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012422 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012423" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012424" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12425" 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 +020012426 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012427
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012428 " ---------------------------
12429 " :Rex issued while in a file
12430 " ---------------------------
12431
Bram Moolenaara6878372014-03-22 21:02:50 +010012432 " record current file so :Rex can return to it from netrw
12433 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012434" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012435
12436 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012437" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012438 return
12439 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012440" 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 +020012441 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012442 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012443 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012444 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012445 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012446 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012447 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012448 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012449 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012450" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12451 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012452" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12453 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012454 if exists("s:rexposn_".bufnr('%'))
12455 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012456 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012457 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012458" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012459 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012460
Bram Moolenaar85850f32019-07-19 22:05:51 +020012461 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12462 if exists("s:explore_match")
12463 exe "2match netrwMarkFile /".s:explore_match."/"
12464 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012465 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012466
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012467" 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 +010012468" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012469endfun
12470
12471" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012472" s:SaveBufVars: save selected b: variables to s: variables {{{2
12473" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012474fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012475" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012476
12477 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12478 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12479 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12480 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12481 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12482 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12483
12484" call Dret("s:SaveBufVars")
12485endfun
12486
12487" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012488" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12489fun! s:SavePosn(posndict)
12490" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12491
Bram Moolenaar85850f32019-07-19 22:05:51 +020012492 if !exists("a:posndict[bufnr('%')]")
12493 let a:posndict[bufnr("%")]= []
12494 endif
12495" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12496 call add(a:posndict[bufnr("%")],winsaveview())
12497" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012498
12499" call Dret("s:SavePosn posndict")
12500 return a:posndict
12501endfun
12502
12503" ---------------------------------------------------------------------
12504" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12505fun! s:RestorePosn(posndict)
12506" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012507 if exists("a:posndict")
12508 if has_key(a:posndict,bufnr("%"))
12509" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12510 let posnlen= len(a:posndict[bufnr("%")])
12511 if posnlen > 0
12512 let posnlen= posnlen - 1
12513" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12514 call winrestview(a:posndict[bufnr("%")][posnlen])
12515 call remove(a:posndict[bufnr("%")],posnlen)
12516" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12517 endif
12518 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012519 endif
12520" call Dret("s:RestorePosn")
12521endfun
12522
12523" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012524" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012525fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012526" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012527 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12528 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12529 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12530 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12531 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12532 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12533 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12534 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12535 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12536 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12537 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12538 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12539 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12540 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12541 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12542 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12543 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12544 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12545" call Dret("s:SaveWinVars")
12546endfun
12547
12548" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012549" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012550" To allow separate windows to have their own activities, such as
12551" Explore **/pattern, several variables have been made window-oriented.
12552" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012553" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012554" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012555fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012556" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012557 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12558 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12559 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12560 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12561 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12562 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12563 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12564 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12565 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12566 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12567" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012568endfun
12569
12570" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012571" s:SetRexDir: set directory for :Rexplore {{{2
12572fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012573" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012574 let w:netrw_rexdir = a:dirname
12575 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012576 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012577" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12578" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012579" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012580" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012581" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012582endfun
12583
12584" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012585" s:ShowLink: used to modify thin and tree listings to show links {{{2
12586fun! s:ShowLink()
12587" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012588" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12589" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012590 if exists("b:netrw_curdir")
12591 norm! $?\a
12592 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12593 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012594" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12595" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12596" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12597 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012598 let dirlen = strlen(b:netrw_curdir)
12599 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012600" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012601 endif
12602 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012603" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12604" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012605 setl noro ma
12606 call setline(".",modline)
12607 setl ro noma nomod
12608 endif
12609" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12610endfun
12611
12612" ---------------------------------------------------------------------
12613" s:ShowStyle: {{{2
12614fun! s:ShowStyle()
12615 if !exists("w:netrw_liststyle")
12616 let liststyle= g:netrw_liststyle
12617 else
12618 let liststyle= w:netrw_liststyle
12619 endif
12620 if liststyle == s:THINLIST
12621 return s:THINLIST.":thin"
12622 elseif liststyle == s:LONGLIST
12623 return s:LONGLIST.":long"
12624 elseif liststyle == s:WIDELIST
12625 return s:WIDELIST.":wide"
12626 elseif liststyle == s:TREELIST
12627 return s:TREELIST.":tree"
12628 else
12629 return 'n/a'
12630 endif
12631endfun
12632
12633" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012634" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12635" Solution from Nicolai Weibull, vim docs (:help strlen()),
12636" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012637fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012638" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12639
12640 if v:version >= 703 && exists("*strdisplaywidth")
12641 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012642
Bram Moolenaar8d043172014-01-23 14:24:41 +010012643 elseif type(g:Align_xstrlen) == 1
12644 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12645 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012646
Bram Moolenaar8d043172014-01-23 14:24:41 +010012647 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012648 " number of codepoints (Latin a + combining circumflex is two codepoints)
12649 " (comment from TM, solution from NW)
12650 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012651
Bram Moolenaar8d043172014-01-23 14:24:41 +010012652 elseif g:Align_xstrlen == 2
12653 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012654 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12655 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012656 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012657
Bram Moolenaar8d043172014-01-23 14:24:41 +010012658 elseif g:Align_xstrlen == 3
12659 " virtual length (counting, for instance, tabs as anything between 1 and
12660 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012661 " preceded by lam, one otherwise, etc.)
12662 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012663 let modkeep= &l:mod
12664 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012665 call setline(line("."),a:x)
12666 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012667 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012668 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012669 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012670
Bram Moolenaar446cb832008-06-24 21:56:24 +000012671 else
12672 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012673 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012674 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012675" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012676 return ret
12677endfun
12678
12679" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012680" s:ShellEscape: shellescape(), or special windows handling {{{2
12681fun! s:ShellEscape(s, ...)
12682 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12683 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12684 endif
12685 let f = a:0 > 0 ? a:1 : 0
12686 return shellescape(a:s, f)
12687endfun
12688
12689" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012690" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012691fun! s:TreeListMove(dir)
12692" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012693 let curline = getline('.')
12694 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12695 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12696 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12697 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12698 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12699 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12700" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12701" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12702" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12703" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12704" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12705 " COMBAK : need to handle when on a directory
12706 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012707 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012708 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012709 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012710 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012711" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012712 elseif a:dir == '[]' && nxtline != ''
12713 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012714" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012715 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12716 if nl != 0
12717 NetrwKeepj norm! k
12718 else
12719 NetrwKeepj norm! G
12720 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012721" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012722 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012723 endif
12724
12725" call Dret("s:TreeListMove")
12726endfun
12727
12728" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012729" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12730" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12731" can't be called except via emenu. But due to locale, that menu line may not be called
12732" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12733fun! s:UpdateBuffersMenu()
12734" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012735 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012736 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012737 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012738 catch /^Vim\%((\a\+)\)\=:E/
12739 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012740 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012741 endtry
12742 endif
12743" call Dret("s:UpdateBuffersMenu")
12744endfun
12745
12746" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012747" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012748" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012749fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012750" call Dfunc("s:UseBufWinVars()")
12751 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012752 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12753 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12754 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12755 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12756 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12757 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12758 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12759 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12760 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 +000012761" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012762endfun
12763
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012764" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012765" s:UserMaps: supports user-defined UserMaps {{{2
12766" * calls a user-supplied funcref(islocal,curdir)
12767" * interprets result
12768" See netrw#UserMaps()
12769fun! s:UserMaps(islocal,funcname)
12770" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12771
12772 if !exists("b:netrw_curdir")
12773 let b:netrw_curdir= getcwd()
12774 endif
12775 let Funcref = function(a:funcname)
12776 let result = Funcref(a:islocal)
12777
12778 if type(result) == 1
12779 " if result from user's funcref is a string...
12780" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12781 if result == "refresh"
12782" call Decho("refreshing display",'~'.expand("<slnum>"))
12783 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12784 elseif result != ""
12785" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12786 exe result
12787 endif
12788
12789 elseif type(result) == 3
12790 " if result from user's funcref is a List...
12791" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12792 for action in result
12793 if action == "refresh"
12794" call Decho("refreshing display",'~'.expand("<slnum>"))
12795 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12796 elseif action != ""
12797" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12798 exe action
12799 endif
12800 endfor
12801 endif
12802
12803" call Dret("s:UserMaps")
12804endfun
12805
Bram Moolenaar85850f32019-07-19 22:05:51 +020012806" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012807" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012808" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012809let &cpo= s:keepcpo
12810unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012811
Bram Moolenaar85850f32019-07-19 22:05:51 +020012812" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012813" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012814" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012815" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012816" doing autoload/netrw.vim version v172g ~57
12817" varname<g:netrw_dirhistcnt> value=0 ~1
12818" varname<s:THINLIST> value=0 ~1
12819" varname<s:LONGLIST> value=1 ~1
12820" varname<s:WIDELIST> value=2 ~1
12821" varname<s:TREELIST> value=3 ~1
12822" varname<s:MAXLIST> value=4 ~1
12823" varname<g:netrw_use_errorwindow> value=2 ~1
12824" varname<g:netrw_http_xcmd> value=-q -O ~1
12825" varname<g:netrw_http_put_cmd> value=curl -T ~1
12826" varname<g:netrw_keepj> value=keepj ~1
12827" varname<g:netrw_rcp_cmd> value=rcp ~1
12828" varname<g:netrw_rsync_cmd> value=rsync ~1
12829" varname<g:netrw_rsync_sep> value=/ ~1
12830" varname<g:netrw_scp_cmd> value=scp -q ~1
12831" varname<g:netrw_sftp_cmd> value=sftp ~1
12832" varname<g:netrw_ssh_cmd> value=ssh ~1
12833" varname<g:netrw_alto> value=0 ~1
12834" varname<g:netrw_altv> value=1 ~1
12835" varname<g:netrw_banner> value=1 ~1
12836" varname<g:netrw_browse_split> value=0 ~1
12837" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12838" varname<g:netrw_chgwin> value=-1 ~1
12839" varname<g:netrw_clipboard> value=1 ~1
12840" varname<g:netrw_compress> value=gzip ~1
12841" varname<g:netrw_ctags> value=ctags ~1
12842" varname<g:netrw_cursor> value=2 ~1
12843" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12844" varname<g:netrw_cygdrive> value=/cygdrive ~1
12845" varname<s:didstarstar> value=0 ~1
12846" varname<g:netrw_dirhistcnt> value=0 ~1
12847" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12848" varname<g:netrw_dirhistmax> value=10 ~1
12849" varname<g:netrw_errorlvl> value=0 ~1
12850" varname<g:netrw_fastbrowse> value=1 ~1
12851" 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
12852" varname<g:netrw_ftpmode> value=binary ~1
12853" varname<g:netrw_hide> value=1 ~1
12854" varname<g:netrw_keepdir> value=1 ~1
12855" varname<g:netrw_list_hide> value= ~1
12856" varname<g:netrw_localmkdir> value=mkdir ~1
12857" varname<g:netrw_remote_mkdir> value=mkdir ~1
12858" varname<g:netrw_liststyle> value=0 ~1
12859" varname<g:netrw_markfileesc> value=*./[\~ ~1
12860" varname<g:netrw_maxfilenamelen> value=32 ~1
12861" varname<g:netrw_menu> value=1 ~1
12862" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12863" varname<g:netrw_mousemaps> value=1 ~1
12864" varname<g:netrw_retmap> value=0 ~1
12865" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12866" varname<g:netrw_preview> value=0 ~1