blob: 7d1a35c1a192f1d37d846f3a66fc8677fe584c2e [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 Moolenaar89a9c152021-08-29 21:55:35 +02003" Date: Aug 16, 2021
4" Version: 171
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 Moolenaar89a9c152021-08-29 21:55:35 +020046let g:loaded_netrw = "v171"
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 = ""
211let g:netrw_localrmdiropt = ""
212
213" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000214" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200215if (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")
216 call s:NetrwInit("g:netrw_use_errorwindow",2)
217else
218 call s:NetrwInit("g:netrw_use_errorwindow",1)
219endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200220
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000221if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100222 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000223 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100224 elseif executable("curl")
225 let g:netrw_dav_cmd = "curl"
226 else
227 let g:netrw_dav_cmd = ""
228 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000230if !exists("g:netrw_fetch_cmd")
231 if executable("fetch")
232 let g:netrw_fetch_cmd = "fetch -o"
233 else
234 let g:netrw_fetch_cmd = ""
235 endif
236endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100237if !exists("g:netrw_file_cmd")
238 if executable("elinks")
239 call s:NetrwInit("g:netrw_file_cmd","elinks")
240 elseif executable("links")
241 call s:NetrwInit("g:netrw_file_cmd","links")
242 endif
243endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000244if !exists("g:netrw_ftp_cmd")
245 let g:netrw_ftp_cmd = "ftp"
246endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200247let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200248if !exists("g:netrw_ftp_options")
249 let g:netrw_ftp_options= "-i -n"
250endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000251if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100252 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100253 let g:netrw_http_cmd = "wget"
254 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100255 elseif executable("curl")
256 let g:netrw_http_cmd = "curl"
257 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200258 elseif executable("elinks")
259 let g:netrw_http_cmd = "elinks"
260 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000261 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100262 let g:netrw_http_cmd = "fetch"
263 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200264 elseif executable("links")
265 let g:netrw_http_cmd = "links"
266 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000267 else
268 let g:netrw_http_cmd = ""
269 endif
270endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100271call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100272call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100273call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
274call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200275call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200276if !exists("g:netrw_scp_cmd")
277 if executable("scp")
278 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
279 elseif executable("pscp")
280 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
281 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
282 else
283 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
284 endif
285 else
286 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
287 endif
288endif
289
Bram Moolenaar5c736222010-01-06 20:54:52 +0100290call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
291call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000292
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000293if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000294 \ && exists("g:netrw_use_nt_rcp")
295 \ && g:netrw_use_nt_rcp
296 \ && executable( $SystemRoot .'/system32/rcp.exe')
297 let s:netrw_has_nt_rcp = 1
298 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000299else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000300 let s:netrw_has_nt_rcp = 0
301 let s:netrw_rcpmode = ''
302endif
303
304" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000305" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000306" Cygwin Detection ------- {{{3
307if !exists("g:netrw_cygwin")
308 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100309 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000310 let g:netrw_cygwin= 1
311 else
312 let g:netrw_cygwin= 0
313 endif
314 else
315 let g:netrw_cygwin= 0
316 endif
317endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000318" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100319call s:NetrwInit("g:netrw_alto" , &sb)
320call s:NetrwInit("g:netrw_altv" , &spr)
321call s:NetrwInit("g:netrw_banner" , 1)
322call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200323call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100324call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200325call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100326call s:NetrwInit("g:netrw_compress" , "gzip")
327call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200328if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
329 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
330 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000331endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200332call s:NetrwInit("g:netrw_cursor" , 2)
333let s:netrw_usercul = &cursorline
334let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200335"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100336call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000337" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200338call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200339call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200340call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100341call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200342call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100343call s:NetrwInit("g:netrw_fastbrowse" , 1)
344call 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 +0000345if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000346 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
347 let g:netrw_ftp_list_cmd = "ls -lF"
348 let g:netrw_ftp_timelist_cmd = "ls -tlF"
349 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000350 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000351 let g:netrw_ftp_list_cmd = "dir"
352 let g:netrw_ftp_timelist_cmd = "dir"
353 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000354 endif
355endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100356call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000357" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100358call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000359if !exists("g:netrw_ignorenetrc")
360 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
361 let g:netrw_ignorenetrc= 1
362 else
363 let g:netrw_ignorenetrc= 0
364 endif
365endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100366call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000367if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000368 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000369 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200370 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000371 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
372 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100373 if exists("g:netrw_list_cmd_options")
374 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
375 else
376 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
377 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000378 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200379 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100380 if exists("g:netrw_list_cmd_options")
381 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
382 else
383 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
384 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000385 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100386" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000387 let g:netrw_list_cmd= ""
388 endif
389endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100390call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000391" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200392if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200393 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200394 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
395endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100396if !exists("g:netrw_localcmdshell")
397 let g:netrw_localcmdshell= ""
398endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000399if !exists("g:netrw_localcopycmd")
400 if has("win32") || has("win95") || has("win64") || has("win16")
401 if g:netrw_cygwin
402 let g:netrw_localcopycmd= "cp"
403 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200404 let g:netrw_localcopycmd = expand("$COMSPEC")
405 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000406 endif
407 elseif has("unix") || has("macunix")
408 let g:netrw_localcopycmd= "cp"
409 else
410 let g:netrw_localcopycmd= ""
411 endif
412endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100413if !exists("g:netrw_localcopydircmd")
414 if has("win32") || has("win95") || has("win64") || has("win16")
415 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200416 let g:netrw_localcopydircmd = "cp"
417 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100418 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200419 let g:netrw_localcopydircmd = expand("$COMSPEC")
420 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100421 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200422 elseif has("unix")
423 let g:netrw_localcopydircmd = "cp"
424 let g:netrw_localcopydircmdopt= " -R"
425 elseif has("macunix")
426 let g:netrw_localcopydircmd = "cp"
427 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100428 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200429 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 endif
431endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200432if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100433 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200434 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
435endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200436if has("win32") || has("win95") || has("win64") || has("win16")
437 if g:netrw_cygwin
438 call s:NetrwInit("g:netrw_localmkdir","mkdir")
439 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200440 let g:netrw_localmkdir = expand("$COMSPEC")
441 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200442 endif
443else
444 call s:NetrwInit("g:netrw_localmkdir","mkdir")
445endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200446call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200447if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200448 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
450endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000451if !exists("g:netrw_localmovecmd")
452 if has("win32") || has("win95") || has("win64") || has("win16")
453 if g:netrw_cygwin
454 let g:netrw_localmovecmd= "mv"
455 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200456 let g:netrw_localmovecmd = expand("$COMSPEC")
457 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000458 endif
459 elseif has("unix") || has("macunix")
460 let g:netrw_localmovecmd= "mv"
461 else
462 let g:netrw_localmovecmd= ""
463 endif
464endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100465" following serves as an example for how to insert a version&patch specific test
466"if v:version < 704 || (v:version == 704 && !has("patch1107"))
467"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100468call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
469" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000470if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000471 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000472endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000473if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000474 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
475endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000476" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100477call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
478call s:NetrwInit("g:netrw_maxfilenamelen", 32)
479call s:NetrwInit("g:netrw_menu" , 1)
480call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200481call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100482call s:NetrwInit("g:netrw_retmap" , 0)
483if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
484 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
485elseif has("win32") || has("win95") || has("win64") || has("win16")
486 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
487else
488 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000489endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100490call s:NetrwInit("g:netrw_preview" , 0)
491call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100492call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100493call s:NetrwInit("g:netrw_sshport" , "-p")
494call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
495call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
496call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100497call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
498" Default values - q-s ---------- {{{3
499call s:NetrwInit("g:netrw_quickhelp",0)
500let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100501 \ "(create new) %:file d:directory",
502 \ "(windows split&open) o:horz v:vert p:preview",
503 \ "i:style qf:file info O:obtain r:reverse",
504 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
505 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
506 \ "(history) qb:list u:go up U:go down",
507 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100508" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
509call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100510if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
511 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
512else
513 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
514endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100515call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
516call s:NetrwInit("g:netrw_sort_options" , "")
517call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000518if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100519 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200520 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100521 else
522 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000523 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000524endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525call s:NetrwInit("g:netrw_special_syntax" , 0)
526call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200527call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100528call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100529call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000530" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100531call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200532if !exists("g:netrw_xstrlen")
533 if exists("g:Align_xstrlen")
534 let g:netrw_xstrlen= g:Align_xstrlen
535 elseif exists("g:drawit_xstrlen")
536 let g:netrw_xstrlen= g:drawit_xstrlen
537 elseif &enc == "latin1" || !has("multi_byte")
538 let g:netrw_xstrlen= 0
539 else
540 let g:netrw_xstrlen= 1
541 endif
542endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200545call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100546call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200547if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000548" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000549" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100550call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200551if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200552 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200553else
Bram Moolenaarff034192013-04-24 18:51:19 +0200554 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200555endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200556call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100557call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
558call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100559if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100560 let s:treedepthstring= "│ "
561else
562 let s:treedepthstring= "| "
563endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200564call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000565
566" BufEnter event ignored by decho when following variable is true
567" Has a side effect that doau BufReadPost doesn't work, so
568" files read by network transfer aren't appropriately highlighted.
569"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570
Bram Moolenaaradc21822011-04-01 18:03:16 +0200571" ======================
572" Netrw Initialization: {{{1
573" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200574if 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 +0100575" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100576 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200577" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100578 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100579 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
580 au VimEnter * let s:initbeval= &beval
581"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100582" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
583" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
584" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
585" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
586" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
587" 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 +0200588endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200589au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200590
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200591if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100592 com! -nargs=* NetrwKeepj keepj <args>
593else
594 let g:netrw_keepj= ""
595 com! -nargs=* NetrwKeepj <args>
596endif
597
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000598" ==============================
599" Netrw Utility Functions: {{{1
600" ==============================
601
Bram Moolenaaradc21822011-04-01 18:03:16 +0200602" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100603" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100604if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100605" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100606 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100607 if &ft != "netrw"
608 return ""
609 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200610 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
611 " popup error window is still showing
612 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
613 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
614 " text under mouse hasn't changed; only close window when it changes
615 call popup_close(s:popuperr_id)
616 unlet s:popuperr_text
617 else
618 let s:popuperr_text= v:beval_text
619 endif
620 let mesg= ""
621 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 +0100622 let mesg= ""
623 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
624 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
625 elseif getline(v:beval_lnum) =~ '^"\s*/'
626 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
627 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100628 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100629 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
630 let mesg = "S: edit sorting sequence"
631 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
632 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
633 elseif v:beval_text == "Quick" || v:beval_text == "Help"
634 let mesg = "Help: press <F1>"
635 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
636 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
637 else
638 let mesg= ""
639 endif
640 return mesg
641 endfun
642"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100643" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
644" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
645" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
646" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
647" 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 +0200648endif
649
Bram Moolenaar071d4272004-06-13 20:20:40 +0000650" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200651" netrw#Explore: launch the local browser in the directory of the current file {{{2
652" indx: == -1: Nexplore
653" == -2: Pexplore
654" == +: this is overloaded:
655" * If Nexplore/Pexplore is in use, then this refers to the
656" indx'th item in the w:netrw_explore_list[] of items which
657" matched the */pattern **/pattern *//pattern **//pattern
658" * If Hexplore or Vexplore, then this will override
659" g:netrw_winsize to specify the qty of rows or columns the
660" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100661" 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 +0200662" dosplit==1: the window will be split before running the local browser
663" style == 0: Explore style == 1: Explore!
664" == 2: Hexplore style == 3: Hexplore!
665" == 4: Vexplore style == 5: Vexplore!
666" == 6: Texplore
667fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100668" 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 +0100669" 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 +0200670 if !exists("b:netrw_curdir")
671 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100672" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200673 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100674
675 " record current file for Rexplore's benefit
676 if &ft != "netrw"
677 let w:netrw_rexfile= expand("%:p")
678 endif
679
680 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200681 let curdir = simplify(b:netrw_curdir)
682 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200683 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
684 let curdir= substitute(curdir,'\','/','g')
685 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100686" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100687
688 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
689 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
690 " try Explore again.
691 if a:0 > 0
692" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100693 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
694 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
695 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
696 \ '~'.expand("<slnum>"))
697 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
698" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100699 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
700" call Dret("netrw#Explore : returning from retry")
701 return
702" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100703" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100704 endif
705 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200706
707 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200708 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100709" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100710 sil! let keepregstar = @*
711 sil! let keepregplus = @+
712 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200713 sil! let keepregslash= @/
714
Bram Moolenaar8d043172014-01-23 14:24:41 +0100715 " if dosplit
716 " -or- file has been modified AND file not hidden when abandoned
717 " -or- Texplore used
718 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100719" 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 +0200720 call s:SaveWinVars()
721 let winsz= g:netrw_winsize
722 if a:indx > 0
723 let winsz= a:indx
724 endif
725
726 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100727" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200728 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200729 if winsz == 0|let winsz= ""|endif
730 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100731" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200732
733 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100734" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200735 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200736 if winsz == 0|let winsz= ""|endif
737 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100738" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200739
740 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100741" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200742 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200743 if winsz == 0|let winsz= ""|endif
744 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100745" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200746
747 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100748" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200749 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200750 if winsz == 0|let winsz= ""|endif
751 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100752" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200753
754 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100755" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200756 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200757 if winsz == 0|let winsz= ""|endif
758 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100759" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200760
761 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100762" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200763 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200764 if winsz == 0|let winsz= ""|endif
765 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100766" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200767
768 elseif a:style == 6 " Texplore
769 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100770" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 call s:RestoreBufVars()
774 endif
775 call s:RestoreWinVars()
776" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" 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 +0200778 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100779 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200780
781 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
790 if dirname !~ '/$'
791 let dirname= dirname."/"
792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200798 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200800 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 let dirname= a:1
805 endif
806 else
807 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100808" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200809 call s:NetrwClearExplore()
810" call Dret("netrw#Explore : cleared list")
811 return
812 endif
813
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 if dirname =~ '\.\./\=$'
816 let dirname= simplify(fnamemodify(dirname,':p:h'))
817 elseif dirname =~ '\.\.' || dirname == '.'
818 let dirname= simplify(fnamemodify(dirname,':p'))
819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100820" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200821
822 if dirname =~ '^\*//'
823 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100824" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
826 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100827" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200828 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
829
830 elseif dirname =~ '^\*\*//'
831 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100832" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833 let pattern= substitute(dirname,'^\*\*//','','')
834 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100835" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200836
837 elseif dirname =~ '/\*\*/'
838 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100839" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
841 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
842 let b:netrw_curdir = prefixdir
843 else
844 let b:netrw_curdir= getcwd().'/'.prefixdir
845 endif
846 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
847 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100848" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
849" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200850
851 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200852 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200853 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855
856 elseif dirname=~ '^\*\*/'
857 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
858 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100859" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200860
861 else
862 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100863" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200864 endif
865
866 if starpat == 0 && a:indx >= 0
867 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100868" 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 +0200869 if dirname == ""
870 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100871" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200872 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200873 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200874 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200875 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200876 if dirname == ""
877 let dirname= getcwd()
878 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100879 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100880 " depending on whether backslashes have been converted to forward slashes by earlier code).
881 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200882 let dirname= b:netrw_curdir."/".dirname
883 endif
884 elseif dirname !~ '^/'
885 let dirname= b:netrw_curdir."/".dirname
886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100887" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200888 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100889" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
890" 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 +0200891 endif
892 if exists("w:netrw_bannercnt")
893 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
894 " If one wants to return the same place in the netrw window, use :Rex instead.
895 exe w:netrw_bannercnt
896 endif
897
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100898" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200899 " ---------------------------------------------------------------------
900 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
901" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100902" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200903" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100904" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200905" endif
906 " ---------------------------------------------------------------------
907
908 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
909 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
910 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
911 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
912 elseif a:indx <= 0
913 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100914" 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 +0200915 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 let s:didstarstar= 1
918 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
919 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
920 endif
921
922 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100923" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200924 if !exists("w:netrw_explore_indx")
925 let w:netrw_explore_indx= 0
926 endif
927
928 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100929" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200930
931 if indx == -1
932 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100933" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100935 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 +0200936 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100937" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100938 if @* != keepregstar | sil! let @* = keepregstar | endif
939 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100940 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200941 sil! let @/ = keepregslash
942" call Dret("netrw#Explore")
943 return
944 endif
945 let indx= w:netrw_explore_indx
946 if indx < 0 | let indx= 0 | endif
947 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
948 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100949" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200950 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
951 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100952" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 endwhile
954 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100955" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200956
957 elseif indx == -2
958 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100959" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200960 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100961 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 +0200962 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100963" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100964 if @* != keepregstar | sil! let @* = keepregstar | endif
965 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100966 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200967 sil! let @/ = keepregslash
968" call Dret("netrw#Explore")
969 return
970 endif
971 let indx= w:netrw_explore_indx
972 if indx < 0 | let indx= 0 | endif
973 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
974 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200976 while indx >= 0 && curfile == w:netrw_explore_list[indx]
977 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100978" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200979 endwhile
980 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100981" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200982
983 else
984 " Explore -- initialize
985 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100986" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100987 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200988 let w:netrw_explore_indx= 0
989 if !exists("b:netrw_curdir")
990 let b:netrw_curdir= getcwd()
991 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100992" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200993
994 " switch on starpat to build the w:netrw_explore_list of files
995 if starpat == 1
996 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100997" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
998" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001000 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 catch /^Vim\%((\a\+)\)\=:E480/
1002 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1003" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1004 return
1005 endtry
1006 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1007 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1008
1009 elseif starpat == 2
1010 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001011" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1012" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001013 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001014 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 catch /^Vim\%((\a\+)\)\=:E480/
1016 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1017 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001018 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001019" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001020 if @* != keepregstar | sil! let @* = keepregstar | endif
1021 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001022 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001023 sil! let @/ = keepregslash
1024" call Dret("netrw#Explore : no files matched pattern")
1025 return
1026 endtry
1027 let s:netrw_curdir = b:netrw_curdir
1028 let w:netrw_explore_list = getqflist()
1029 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1030 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1031
1032 elseif starpat == 3
1033 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001034" 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 +02001035 let filepat= substitute(dirname,'^\*/','','')
1036 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001037" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1038" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001039 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1040 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1041
1042 elseif starpat == 4
1043 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001044" 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 +02001045 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1046 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1047 endif " switch on starpat to build w:netrw_explore_list
1048
1049 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001050" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1051" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001052
1053 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001054 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001055 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001056" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001057 if @* != keepregstar | sil! let @* = keepregstar | endif
1058 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001059 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001060 sil! let @/ = keepregslash
1061" call Dret("netrw#Explore : no files matched")
1062 return
1063 endif
1064 endif " if indx ... endif
1065
1066 " NetrwStatusLine support - for exploring support
1067 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001068" 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 +02001069
1070 " wrap the indx around, but issue a note
1071 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001072" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1074 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001075 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 endif
1077
1078 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001079" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001080 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001081" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001082
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 call netrw#LocalBrowseCheck(newdir)
1085 if !exists("w:netrw_liststyle")
1086 let w:netrw_liststyle= g:netrw_liststyle
1087 endif
1088 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001089 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001090 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001092 endif
1093 let w:netrw_explore_mtchcnt = indx + 1
1094 let w:netrw_explore_bufnr = bufnr("%")
1095 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001096 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001097" 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 +02001098
1099 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001100" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001101 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001102 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 +02001103 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001104 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001105" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001106 if @* != keepregstar | sil! let @* = keepregstar | endif
1107 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001108 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001109 sil! let @/ = keepregslash
1110" call Dret("netrw#Explore : missing +path_extra")
1111 return
1112 endif
1113
1114 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001115" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001116 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1117 sil! unlet w:netrw_treedict
1118 sil! unlet w:netrw_treetop
1119 endif
1120 let newdir= dirname
1121 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001122 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001124 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 endif
1126 endif
1127
1128 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001129" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1130" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001132" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001134 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001135" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001136 let s:explore_prvdir = b:netrw_curdir
1137 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001138 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001139 if b:netrw_curdir !~ '/$'
1140 let dirlen= dirlen + 1
1141 endif
1142 let prvfname= ""
1143 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001144" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001145 if fname =~ '^'.b:netrw_curdir
1146 if s:explore_match == ""
1147 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1148 else
1149 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1150 endif
1151 elseif fname !~ '^/' && fname != prvfname
1152 if s:explore_match == ""
1153 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1154 else
1155 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1156 endif
1157 endif
1158 let prvfname= fname
1159 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001160" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001161 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1162 exe "2match netrwMarkFile /".s:explore_match."/"
1163 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001164 endif
1165 echo "<s-up>==Pexplore <s-down>==Nexplore"
1166 else
1167 2match none
1168 if exists("s:explore_match") | unlet s:explore_match | endif
1169 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1170 echo " "
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001171" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001172 endif
1173
Bram Moolenaara6878372014-03-22 21:02:50 +01001174 " since Explore may be used to initialize netrw's browser,
1175 " there's no danger of a late FocusGained event on initialization.
1176 " Consequently, set s:netrw_events to 2.
1177 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001178 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001179" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001180 if @* != keepregstar | sil! let @* = keepregstar | endif
1181 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001182 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001183 sil! let @/ = keepregslash
1184" call Dret("netrw#Explore : @/<".@/.">")
1185endfun
1186
1187" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001188" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001189fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001190" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001191 let curwin= winnr()
1192
Bram Moolenaara6878372014-03-22 21:02:50 +01001193 if a:0 > 0 && a:1 != ""
1194 " if a netrw window is already on the left-side of the tab
1195 " and a directory has been specified, explore with that
1196 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001197" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001198 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001199" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001200 exe "1wincmd w"
1201 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001202" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001203 exe "Explore ".fnameescape(a1)
1204 exe curwin."wincmd w"
1205 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001206" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 unlet t:netrw_lexposn
1208 endif
1209" call Dret("netrw#Lexplore")
1210 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001211 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 exe curwin."wincmd w"
1213 else
1214 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001215" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001216 endif
1217
Bram Moolenaar8d043172014-01-23 14:24:41 +01001218 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001220 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001221" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001222 else
1223 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001224" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001226" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227
1228 if lexwinnr > 0
1229 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001230" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001231 exe lexwinnr."wincmd w"
1232 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001233 let t:netrw_lexposn = winsaveview()
1234" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001235" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 close
1237 if lexwinnr < curwin
1238 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001239 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001240 if lexwinnr != curwin
1241 exe curwin."wincmd w"
1242 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001243 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001244" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001245
1246 else
1247 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001248" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001249 exe "1wincmd w"
1250 let keep_altv = g:netrw_altv
1251 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001252 if a:count != 0
1253 let netrw_winsize = g:netrw_winsize
1254 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001255 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001256 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001257" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 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 +02001259" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001261" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001262 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001263 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001264 elseif curfile =~ '^\a\{3,}://'
1265" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001266 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001267 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001268" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001269 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001270 endif
1271 if a:count != 0
1272 let g:netrw_winsize = netrw_winsize
1273 endif
1274 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001275 let g:netrw_altv = keep_altv
1276 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001277 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1278 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
1279 " effort to mis-use :Lex is warranted.
1280 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001281" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1282" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001283 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001284" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001285" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1286 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001287 unlet t:netrw_lexposn
1288 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001289 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001290
1291 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001292 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001293 if a:rightside
1294 let g:netrw_chgwin= 1
1295 else
1296 let g:netrw_chgwin= 2
1297 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001298" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001299 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001300
Bram Moolenaar8d043172014-01-23 14:24:41 +01001301" call Dret("netrw#Lexplore")
1302endfun
1303
1304" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001305" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001306" supports :NetrwClean -- remove netrw from first directory on runtimepath
1307" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001308fun! netrw#Clean(sys)
1309" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001310
1311 if a:sys
1312 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1313 else
1314 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1315 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001316" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001317 let diddel= 0
1318 let diddir= ""
1319
1320 if choice == 1
1321 for dir in split(&rtp,',')
1322 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001323" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001324 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1325 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1326 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1327 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1328 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1329 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 +00001330 let diddir= dir
1331 let diddel= diddel + 1
1332 if !a:sys|break|endif
1333 endif
1334 endfor
1335 endif
1336
1337 echohl WarningMsg
1338 if diddel == 0
1339 echomsg "netrw is either not installed or not removable"
1340 elseif diddel == 1
1341 echomsg "removed one copy of netrw from <".diddir.">"
1342 else
1343 echomsg "removed ".diddel." copies of netrw"
1344 endif
1345 echohl None
1346
Bram Moolenaara6878372014-03-22 21:02:50 +01001347" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001348endfun
1349
Bram Moolenaar5c736222010-01-06 20:54:52 +01001350" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001351" netrw#MakeTgt: make a target out of the directory name provided {{{2
1352fun! netrw#MakeTgt(dname)
1353" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1354 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001355 let svpos = winsaveview()
1356" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001357 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1358" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001359 if s:netrwmftgt_islocal
1360 let netrwmftgt= simplify(a:dname)
1361 else
1362 let netrwmftgt= a:dname
1363 endif
1364 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1365 " re-selected target, so just clear it
1366 unlet s:netrwmftgt s:netrwmftgt_islocal
1367 else
1368 let s:netrwmftgt= netrwmftgt
1369 endif
1370 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001371 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001372 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001373" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1374 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001375" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001376endfun
1377
Bram Moolenaara6878372014-03-22 21:02:50 +01001378" ---------------------------------------------------------------------
1379" netrw#Obtain: {{{2
1380" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001381" islocal=0 obtain from remote source
1382" =1 obtain from local source
1383" fname : a filename or a list of filenames
1384" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001385fun! netrw#Obtain(islocal,fname,...)
1386" 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 +02001387 " NetrwStatusLine support - for obtaining support
1388
1389 if type(a:fname) == 1
1390 let fnamelist= [ a:fname ]
1391 elseif type(a:fname) == 3
1392 let fnamelist= a:fname
1393 else
1394 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 +01001395" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 return
1397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001398" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 if a:0 > 0
1400 let tgtdir= a:1
1401 else
1402 let tgtdir= getcwd()
1403 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001405
1406 if exists("b:netrw_islocal") && b:netrw_islocal
1407 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001408" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001409 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1410 let topath= s:ComposePath(tgtdir,"")
1411 if (has("win32") || has("win95") || has("win64") || has("win16"))
1412 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001413" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001414 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001415" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001416 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 if v:shell_error != 0
1418 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 +01001419" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 return
1421 endif
1422 endfor
1423 else
1424 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001425" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1426 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1427" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001428 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001429 if v:shell_error != 0
1430 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 +01001431" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 return
1433 endif
1434 endif
1435 elseif !exists("b:netrw_curdir")
1436 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1437 else
1438 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1439 endif
1440
1441 else
1442 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001443" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001444 if type(a:fname) == 1
1445 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1446 endif
1447 call s:NetrwMethod(b:netrw_curdir)
1448
1449 if b:netrw_method == 4
1450 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001451" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 if exists("g:netrw_port") && g:netrw_port != ""
1453 let useport= " ".g:netrw_scpport." ".g:netrw_port
1454 else
1455 let useport= ""
1456 endif
1457 if b:netrw_fname =~ '/'
1458 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1459 else
1460 let path= ""
1461 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001462 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001463 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 +02001464
1465 elseif b:netrw_method == 2
1466 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001467" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001468 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001469 let tmpbufnr= bufnr("%")
1470 setl ff=unix
1471 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001472 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001473" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 endif
1475
1476 if exists("b:netrw_fname") && b:netrw_fname != ""
1477 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
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("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001482 NetrwKeepj put =g:netrw_ftpextracmd
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 for fname in fnamelist
1486 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001487" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001488 endfor
1489 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490 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 +02001491 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 endif
1494 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1495 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1496 let debugkeep= &debug
1497 setl debug=msg
1498 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1499 let &debug= debugkeep
1500 endif
1501
1502 elseif b:netrw_method == 3
1503 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001504" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001505 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001506 let tmpbufnr= bufnr("%")
1507 setl ff=unix
1508
1509 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001510 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001511" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001512 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001514" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001515 endif
1516
1517 if exists("g:netrw_uid") && g:netrw_uid != ""
1518 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001519 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001520" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001522 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001524" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001525 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001526 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001527" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001528 endif
1529 endif
1530
1531 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001532 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001533" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001534 endif
1535
1536 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
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("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001542 NetrwKeepj put =g:netrw_ftpextracmd
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 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001551 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001552 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001553" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001554
1555 " perform ftp:
1556 " -i : turns off interactive prompting from ftp
1557 " -n unix : DON'T use <.netrc>, even though it exists
1558 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001559 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1560 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001561 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001562 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1563 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001564" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001565 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001566 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001567 endif
1568 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001569
1570 elseif b:netrw_method == 9
1571 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001572" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001573 if a:fname =~ '/'
1574 let localfile= substitute(a:fname,'^.*/','','')
1575 else
1576 let localfile= a:fname
1577 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001578 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 +02001579
Bram Moolenaarff034192013-04-24 18:51:19 +02001580 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001581 " probably a badly formed url; protocol not recognized
1582" call Dret("netrw#Obtain : unsupported method")
1583 return
1584
1585 else
1586 " protocol recognized but not supported for Obtain (yet?)
1587 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001588 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001589 endif
1590" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001591 return
1592 endif
1593
1594 " restore status line
1595 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001596 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001597 endif
1598
1599 endif
1600
1601 " cleanup
1602 if exists("tmpbufnr")
1603 if bufnr("%") != tmpbufnr
1604 exe tmpbufnr."bw!"
1605 else
1606 q!
1607 endif
1608 endif
1609
Bram Moolenaara6878372014-03-22 21:02:50 +01001610" call Dret("netrw#Obtain")
1611endfun
1612
1613" ---------------------------------------------------------------------
1614" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1615fun! netrw#Nread(mode,fname)
1616" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001617 let svpos= winsaveview()
1618" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001619 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001620" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1621 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001622
1623 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1624 if exists("w:netrw_bannercnt")
1625 " start with cursor just after the banner
1626 exe w:netrw_bannercnt
1627 endif
1628 endif
1629" call Dret("netrw#Nread")
1630endfun
1631
1632" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001633" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1634" Options get restored by s:NetrwOptionsRestore()
1635"
1636" Option handling:
1637" * save user's options (s:NetrwOptionsSave)
1638" * set netrw-safe options (s:NetrwOptionsSafe)
1639" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1640" * restore user's options (s:netrwOPtionsRestore)
1641" - restore a user option when != safe option (s:NetrwRestoreSetting)
1642" vt: (variable type) normally its either "w:" or "s:"
1643fun! s:NetrwOptionsSave(vt)
1644" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1645" 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 +02001646" 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>"))
1647" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001648
1649 if !exists("{a:vt}netrw_optionsave")
1650 let {a:vt}netrw_optionsave= 1
1651 else
1652" call Dret("s:NetrwOptionsSave : options already saved")
1653 return
1654 endif
1655" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1656
1657 " Save current settings and current directory
1658" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1659 let s:yykeep = @@
1660 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1661 let {a:vt}netrw_aikeep = &l:ai
1662 let {a:vt}netrw_awkeep = &l:aw
1663 let {a:vt}netrw_bhkeep = &l:bh
1664 let {a:vt}netrw_blkeep = &l:bl
1665 let {a:vt}netrw_btkeep = &l:bt
1666 let {a:vt}netrw_bombkeep = &l:bomb
1667 let {a:vt}netrw_cedit = &cedit
1668 let {a:vt}netrw_cikeep = &l:ci
1669 let {a:vt}netrw_cinkeep = &l:cin
1670 let {a:vt}netrw_cinokeep = &l:cino
1671 let {a:vt}netrw_comkeep = &l:com
1672 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001673 let {a:vt}netrw_cuckeep = &l:cuc
1674 let {a:vt}netrw_culkeep = &l:cul
1675" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001676 let {a:vt}netrw_diffkeep = &l:diff
1677 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001678 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1679 let {a:vt}netrw_ffkeep = &l:ff
1680 endif
1681 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1682 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001683 let {a:vt}netrw_gokeep = &l:go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 let {a:vt}netrw_hidkeep = &l:hidden
1685 let {a:vt}netrw_imkeep = &l:im
1686 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001687 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001688 let {a:vt}netrw_lskeep = &l:ls
1689 let {a:vt}netrw_makeep = &l:ma
1690 let {a:vt}netrw_magickeep = &l:magic
1691 let {a:vt}netrw_modkeep = &l:mod
1692 let {a:vt}netrw_nukeep = &l:nu
1693 let {a:vt}netrw_rnukeep = &l:rnu
1694 let {a:vt}netrw_repkeep = &l:report
1695 let {a:vt}netrw_rokeep = &l:ro
1696 let {a:vt}netrw_selkeep = &l:sel
1697 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001698 if !g:netrw_use_noswf
1699 let {a:vt}netrw_swfkeep = &l:swf
1700 endif
1701 let {a:vt}netrw_tskeep = &l:ts
1702 let {a:vt}netrw_twkeep = &l:tw " textwidth
1703 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1704 let {a:vt}netrw_wrapkeep = &l:wrap
1705 let {a:vt}netrw_writekeep = &l:write
1706
1707 " save a few selected netrw-related variables
1708" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1709 if g:netrw_keepdir
1710 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001711" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001712 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001713 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001714 sil! let {a:vt}netrw_starkeep = @*
1715 sil! let {a:vt}netrw_pluskeep = @+
1716 endif
1717 sil! let {a:vt}netrw_slashkeep= @/
1718
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001719" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720" 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>"))
1721" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1722endfun
1723
1724" ---------------------------------------------------------------------
1725" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1726" Use s:NetrwSaveOptions() to save user settings
1727" Use s:NetrwOptionsRestore() to restore user settings
1728fun! s:NetrwOptionsSafe(islocal)
1729" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1730" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1731" 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>"))
1732 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1733 call s:NetrwSetSafeSetting("&l:ai",0)
1734 call s:NetrwSetSafeSetting("&l:aw",0)
1735 call s:NetrwSetSafeSetting("&l:bl",0)
1736 call s:NetrwSetSafeSetting("&l:bomb",0)
1737 if a:islocal
1738 call s:NetrwSetSafeSetting("&l:bt","nofile")
1739 else
1740 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1741 endif
1742 call s:NetrwSetSafeSetting("&l:ci",0)
1743 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001744 if g:netrw_fastbrowse > a:islocal
1745 call s:NetrwSetSafeSetting("&l:bh","hide")
1746 else
1747 call s:NetrwSetSafeSetting("&l:bh","delete")
1748 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001749 call s:NetrwSetSafeSetting("&l:cino","")
1750 call s:NetrwSetSafeSetting("&l:com","")
1751 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1752 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1753 setl fo=nroql2
Bram Moolenaar6e649222021-10-04 21:32:54 +01001754 " call s:NetrwSetSafeSetting("&go","begmr")
1755 if &go =~ '\ca' | call s:NetrwSetSafeSetting("&go",substitute(&go,'\ca','','g')) | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001756 call s:NetrwSetSafeSetting("&l:hid",0)
1757 call s:NetrwSetSafeSetting("&l:im",0)
1758 setl isk+=@ isk+=* isk+=/
1759 call s:NetrwSetSafeSetting("&l:magic",1)
1760 if g:netrw_use_noswf
1761 call s:NetrwSetSafeSetting("swf",0)
1762 endif
1763 call s:NetrwSetSafeSetting("&l:report",10000)
1764 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1765 call s:NetrwSetSafeSetting("&l:spell",0)
1766 call s:NetrwSetSafeSetting("&l:tw",0)
1767 call s:NetrwSetSafeSetting("&l:wig","")
1768 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001769
1770 " set up cuc and cul based on g:netrw_cursor and listing style
1771 " COMBAK -- cuc cul related
1772 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001773
1774 " allow the user to override safe options
1775" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1776 if &ft == "netrw"
1777" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1778 keepalt NetrwKeepj doau FileType netrw
1779 endif
1780
1781" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1782" 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>"))
1783" call Dret("s:NetrwOptionsSafe")
1784endfun
1785
1786" ---------------------------------------------------------------------
1787" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1788fun! s:NetrwOptionsRestore(vt)
1789" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001790" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001791" 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 +01001792 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001793" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001794" call Decho("..doing filetype detect anyway")
1795 filetype detect
1796" 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>"))
1797" 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 +02001798" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001799 return
1800 endif
1801 unlet {a:vt}netrw_optionsave
1802
1803 if exists("+acd")
1804 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001805" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001806 let curdir = getcwd()
1807 let &l:acd = {a:vt}netrw_acdkeep
1808 unlet {a:vt}netrw_acdkeep
1809 if &l:acd
1810 call s:NetrwLcd(curdir)
1811 endif
1812 endif
1813 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001814" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001815 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1816 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1817 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1818 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1819 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001820" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001821 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1822 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1823 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1824 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1825 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001826" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001827 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1828 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1829 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1830 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1831 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001832 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001833" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1834 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1835 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
1836 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&l:go")
1837 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1838" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1839 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1840 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1841" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1842 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1843" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1844 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1845 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001846 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001847 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1848 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1849" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1850 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1851 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1852 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1853 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1854" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001855 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001856 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1857 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1858 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001859 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001860" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting("s:yykeep","@@")
1862 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1863 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1864 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1865 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1866
Bram Moolenaara6878372014-03-22 21:02:50 +01001867 if exists("{a:vt}netrw_swfkeep")
1868 if &directory == ""
1869 " user hasn't specified a swapfile directory;
1870 " netrw will temporarily set the swapfile directory
1871 " to the current directory as returned by getcwd().
1872 let &l:directory= getcwd()
1873 sil! let &l:swf = {a:vt}netrw_swfkeep
1874 setl directory=
1875 unlet {a:vt}netrw_swfkeep
1876 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001877 if !g:netrw_use_noswf
1878 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1879 sil! let &l:swf= {a:vt}netrw_swfkeep
1880 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001881 unlet {a:vt}netrw_swfkeep
1882 endif
1883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001884 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001885 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1886 if exists("{a:vt}netrw_dirkeep")
1887 call s:NetrwLcd(dirkeep)
1888 unlet {a:vt}netrw_dirkeep
1889 endif
1890 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001891 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001892" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001893 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1894 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001895 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001896 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001897
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001898" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1899" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1900" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1901" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1902" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001903 " Moved the filetype detect here from NetrwGetFile() because remote files
1904 " were having their filetype detect-generated settings overwritten by
1905 " NetrwOptionRestore.
1906 if &ft != "netrw"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001907" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001908 filetype detect
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001909" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001910 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001911" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001912" 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 +02001913" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001914endfun
1915
1916" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001917" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1918" but only when the options' value and the safe setting differ
1919" Doing this means that netrw will not come up as having changed a
1920" setting last when it really didn't actually change it.
1921"
1922" Called from s:NetrwOptionsSafe
1923" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1924fun! s:NetrwSetSafeSetting(setting,safesetting)
1925" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001926
Bram Moolenaar85850f32019-07-19 22:05:51 +02001927 if a:setting =~ '^&'
1928" call Decho("fyi: a:setting starts with &")
1929 exe "let settingval= ".a:setting
1930" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001931
Bram Moolenaar85850f32019-07-19 22:05:51 +02001932 if settingval != a:safesetting
1933" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1934 if type(a:safesetting) == 0
1935 exe "let ".a:setting."=".a:safesetting
1936 elseif type(a:safesetting) == 1
1937 exe "let ".a:setting."= '".a:safesetting."'"
1938 else
1939 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1940 endif
1941 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001942 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001943
Bram Moolenaar85850f32019-07-19 22:05:51 +02001944" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001945endfun
1946
1947" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001948" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1949" but only if the setting value differs from the associated keepvar.
1950" Doing this means that netrw will not come up as having changed a
1951" setting last when it really didn't actually change it.
1952"
1953" Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
1954" keepvars are set up by s:NetrwOptionsSave
1955fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001956""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001957
Bram Moolenaar85850f32019-07-19 22:05:51 +02001958 " typically called from s:NetrwOptionsRestore
1959 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1960 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001961 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001962 if exists(a:keepvar)
1963 exe "let keepvarval= ".a:keepvar
1964 exe "let setting= ".a:setting
1965
1966"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1967"" call Decho("fyi: keepvarval=".keepvarval)
1968"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1969
1970 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001971"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001972 if type(a:setting) == 0
1973 exe "let ".a:setting."= ".keepvarval
1974 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001975 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001976 else
1977 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1978 endif
1979 endif
1980
1981 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001982 endif
1983
Bram Moolenaar85850f32019-07-19 22:05:51 +02001984"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001985endfun
1986
1987" ---------------------------------------------------------------------
1988" NetrwStatusLine: {{{2
1989fun! NetrwStatusLine()
1990
1991" vvv NetrwStatusLine() debugging vvv
1992" let g:stlmsg=""
1993" if !exists("w:netrw_explore_bufnr")
1994" let g:stlmsg="!X<explore_bufnr>"
1995" elseif w:netrw_explore_bufnr != bufnr("%")
1996" let g:stlmsg="explore_bufnr!=".bufnr("%")
1997" endif
1998" if !exists("w:netrw_explore_line")
1999" let g:stlmsg=" !X<explore_line>"
2000" elseif w:netrw_explore_line != line(".")
2001" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2002" endif
2003" if !exists("w:netrw_explore_list")
2004" let g:stlmsg=" !X<explore_list>"
2005" endif
2006" ^^^ NetrwStatusLine() debugging ^^^
2007
2008 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")
2009 " restore user's status line
2010 let &stl = s:netrw_users_stl
2011 let &laststatus = s:netrw_users_ls
2012 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2013 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2014 return ""
2015 else
2016 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2017 endif
2018endfun
2019
Bram Moolenaar85850f32019-07-19 22:05:51 +02002020" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002021" Netrw Transfer Functions: {{{1
2022" ===============================
2023
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002025" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002026" mode: =0 read remote file and insert before current line
2027" =1 read remote file and insert after current line
2028" =2 replace with remote file
2029" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002030fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002031" 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 +00002032
Bram Moolenaar5c736222010-01-06 20:54:52 +01002033 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002034 call s:NetrwOptionsSave("w:")
2035 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002036 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002037 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2038 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2039 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002040" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002041
Bram Moolenaar5c736222010-01-06 20:54:52 +01002042 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002044 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002046 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002047 elseif a:mode == 2 " replace with remote file
2048 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002049 elseif a:mode == 3 " skip read of file (leave as temporary)
2050 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051 else
2052 exe a:mode
2053 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002054 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002056" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002057
Bram Moolenaar5c736222010-01-06 20:54:52 +01002058 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002059 let tmpfile= s:GetTempfile("")
2060 if tmpfile == ""
2061" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002062 return
2063 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002064
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002065 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002067 " attempt to repeat with previous host-file-etc
2068 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002069" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002070 let choice = b:netrw_lastfile
2071 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 else
2074 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002075" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002078 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002079 echomsg 'NetRead Usage:'
2080 echomsg ':Nread machine:path uses rcp'
2081 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2082 echomsg ':Nread "machine id password path" uses ftp'
2083 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2084 echomsg ':Nread fetch://machine/path uses fetch'
2085 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2086 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002087 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002088 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002089 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2090 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2091 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2092 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002093 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002094 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002095
Bram Moolenaar9964e462007-05-05 17:54:07 +00002096 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002097 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002098" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002099 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002100 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002101 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002102 else
2103 " case "... ... ..."
2104 let choice = strpart(choice,1,strlen(choice)-1)
2105 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002106
Bram Moolenaar9964e462007-05-05 17:54:07 +00002107 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 let wholechoice = wholechoice . " " . choice
2109 let ichoice = ichoice + 1
2110 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002111 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002112 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002113 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 return
2116 endif
2117 let choice= a:{ichoice}
2118 endwhile
2119 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2120 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002121 endif
2122 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002124" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002125 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002126
Bram Moolenaar5c736222010-01-06 20:54:52 +01002127 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002128 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002129 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002130" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002131 return
2132 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002133 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002134
Bram Moolenaar8d043172014-01-23 14:24:41 +01002135 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002136" 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 +02002137 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002138" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002139 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002140" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002141 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002142 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002143
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002144 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002145 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002146 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002147 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2148 echo "(netrw) Processing your read request..."
2149 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002150
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002151 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002152 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002154" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002155 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002157 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 " ER: the tmpfile is full path: rcp sees C:\... as host C
2159 if s:netrw_has_nt_rcp == 1
2160 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2161 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2162 else
2163 " Any way needed it machine contains a '.'
2164 let uid_machine = g:netrw_machine .'.'. $USERNAME
2165 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2168 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2169 else
2170 let uid_machine = g:netrw_machine
2171 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002172 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002173 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 +00002174 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002176
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002177 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002178 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002179 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002180" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002181 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002182 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002183 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002184 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002185 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002186" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002187 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002188 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002189" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002190 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002191 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002193 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002194 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 +00002195 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002197 endif
2198 " 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 +00002199 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002200 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002201 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002202 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002203 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002204 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002205 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002207 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2208 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002209 q!
2210 endif
2211 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002212 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002213 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002214
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002215 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002216 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002217 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2218 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002219" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002220 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002221 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002222 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002223 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002224 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002225 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002226" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002227 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002228 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002229" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002231
Bram Moolenaar97d62492012-11-15 21:28:22 +01002232 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002233 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002234 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002235" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002236 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002237 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002238 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002239" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002240 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002243 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002244 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002245
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002246 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002247 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002248" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002250 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002251 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002252" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002253 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002256
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002257 " perform ftp:
2258 " -i : turns off interactive prompting from ftp
2259 " -n unix : DON'T use <.netrc>, even though it exists
2260 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002261 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002263 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2264 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002265" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002266 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002267 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002268 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002269 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002271 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002273
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002275 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002279 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 else
2281 let useport= ""
2282 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002283 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2284 " This is workaround to avoid mis-handle windows local-path:
2285 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2286 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2287 else
2288 let tmpfile_get = tmpfile
2289 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002290 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 +00002291 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002292 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002293
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002294 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002295 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002296 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002297" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002298 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002299 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002300 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002301 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002302" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002303 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002304 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002305
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002306 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2307 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002308" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002309 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002310 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 +00002311 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002312 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 +00002313 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002314 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002315
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002316 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002317 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002318" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002319 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2320 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002321" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2322" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2323 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 +00002324 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002326 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002327 endif
2328 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002330 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002331
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002332 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002333 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002334 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002335" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002336
Bram Moolenaar5c736222010-01-06 20:54:52 +01002337 if !executable(g:netrw_dav_cmd)
2338 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2339" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2340 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002341 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002342 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002343 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 +01002344 else
2345 " Construct execution string (four lines) which will be passed through filter
2346 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2347 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002348 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002349 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002350 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002351 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002352 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002354 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002355 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002356 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002357 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2358 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002359
Bram Moolenaar5c736222010-01-06 20:54:52 +01002360 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002361 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002363 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002365 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002366 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002367
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002368 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002369 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002370 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002371" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002372 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 +00002373 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002374 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002375
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002376 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002377 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002379 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002380" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002382 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002383 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002384 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002385" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002386 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002388 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 let netrw_option= "http"
2390 else
2391 let netrw_option= "ftp"
2392 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002393" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002394
Bram Moolenaar446cb832008-06-24 21:56:24 +00002395 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002396 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 +00002397 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002398 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 +00002399 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002400
Bram Moolenaar446cb832008-06-24 21:56:24 +00002401 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002402 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002403" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002404 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002405
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002407 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002408 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002409" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2410 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 +00002411 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002413
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002415 " NetRead: (file) NetRead Method #10 {{{3
2416 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002417" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2418 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002419 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2420 let b:netrw_lastfile = choice
2421
2422 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002423 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002424 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002425 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002426 endif
2427 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002428
Bram Moolenaar5c736222010-01-06 20:54:52 +01002429 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002430 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002431" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002432 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002433 unlet b:netrw_fname
2434 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002435 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 +01002436" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002437 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002438 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002439 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002440
Bram Moolenaar9964e462007-05-05 17:54:07 +00002441" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442endfun
2443
2444" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002445" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002446fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002447" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002448
Bram Moolenaar5c736222010-01-06 20:54:52 +01002449 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002450 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002451 call s:NetrwOptionsSave("w:")
2452 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002453
Bram Moolenaar5c736222010-01-06 20:54:52 +01002454 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002455 let tmpfile= s:GetTempfile("")
2456 if tmpfile == ""
2457" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002458 return
2459 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002460
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002461 if a:0 == 0
2462 let ichoice = 0
2463 else
2464 let ichoice = 1
2465 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002466
Bram Moolenaar9964e462007-05-05 17:54:07 +00002467 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002468" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002469 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002470 " For binary writes, always write entire file.
2471 " (line numbers don't really make sense for that).
2472 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002473" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002474 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002475 elseif g:netrw_cygwin
2476 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002477 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002478" 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 +01002479 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002480 else
2481 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002482" 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 +01002483 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002484 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002485
Bram Moolenaar9964e462007-05-05 17:54:07 +00002486 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002487 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002488 " on the temporary file's name. Deletion of the temporary file during
2489 " cleanup then causes an error message.
2490 0file!
2491 endif
2492
Bram Moolenaar5c736222010-01-06 20:54:52 +01002493 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002494 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002495
Bram Moolenaar9964e462007-05-05 17:54:07 +00002496 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002497 " attempt to repeat with previous host-file-etc
2498 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002499" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002500 let choice = b:netrw_lastfile
2501 let ichoice= ichoice + 1
2502 else
2503 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002504
Bram Moolenaar8d043172014-01-23 14:24:41 +01002505 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002506 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002507 echomsg 'NetWrite Usage:"'
2508 echomsg ':Nwrite machine:path uses rcp'
2509 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2510 echomsg ':Nwrite "machine id password path" uses ftp'
2511 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2512 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2513 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2514 echomsg ':Nwrite rcp://machine/path uses rcp'
2515 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2516 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2517 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002518 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002519 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002520
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002521 elseif match(choice,"^\"") != -1
2522 if match(choice,"\"$") != -1
2523 " case "..."
2524 let choice=strpart(choice,1,strlen(choice)-2)
2525 else
2526 " case "... ... ..."
2527 let choice = strpart(choice,1,strlen(choice)-1)
2528 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002529
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002530 while match(choice,"\"$") == -1
2531 let wholechoice= wholechoice . " " . choice
2532 let ichoice = ichoice + 1
2533 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002534 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002535 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002536 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002537" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002538 return
2539 endif
2540 let choice= a:{ichoice}
2541 endwhile
2542 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2543 endif
2544 endif
2545 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002546 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002547" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002548
Bram Moolenaar9964e462007-05-05 17:54:07 +00002549 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002550 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002551 if !exists("b:netrw_method") || b:netrw_method < 0
2552" call Dfunc("netrw#NetWrite : unsupported method")
2553 return
2554 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002555
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002556 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002557 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002558 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002559 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2560 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002561" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002562 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002563
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002564 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002565 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002566 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002567" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 if s:netrw_has_nt_rcp == 1
2569 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2570 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2571 else
2572 let uid_machine = g:netrw_machine .'.'. $USERNAME
2573 endif
2574 else
2575 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2576 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2577 else
2578 let uid_machine = g:netrw_machine
2579 endif
2580 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002581 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 +00002582 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002583
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002584 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002585 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002586 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002587" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002588 let netrw_fname = b:netrw_fname
2589
2590 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2591 let bhkeep = &l:bh
2592 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002593 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002594 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002595
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002596" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002597 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002598 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002599" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002600 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002601 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002603 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002604 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002606 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607 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 +00002608 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2610 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 endif
2612 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2613 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002614 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002615 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002616 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002617 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002619
2620 " remove enew buffer (quietly)
2621 let filtbuf= bufnr("%")
2622 exe curbuf."b!"
2623 let &l:bh = bhkeep
2624 exe filtbuf."bw!"
2625
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002627
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002628 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002629 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002630 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002631 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002632" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002633 let netrw_fname = b:netrw_fname
2634 let bhkeep = &l:bh
2635
2636 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2637 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002638 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002639 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002640 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002642 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002643 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002644" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002645 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002646 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002647" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002648 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002649 if exists("g:netrw_uid") && g:netrw_uid != ""
2650 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002651 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002653 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002654 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002655 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002657 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002660 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002661 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002664 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002665 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002667 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002668 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002670 " save choice/id/password for future use
2671 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002672
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002673 " perform ftp:
2674 " -i : turns off interactive prompting from ftp
2675 " -n unix : DON'T use <.netrc>, even though it exists
2676 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002677 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002678 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2680 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002681 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002682 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002683 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002684 let mod=1
2685 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002686
2687 " remove enew buffer (quietly)
2688 let filtbuf= bufnr("%")
2689 exe curbuf."b!"
2690 let &l:bh= bhkeep
2691 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002692
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002693 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002694 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002695 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002696" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002697 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002698 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 else
2700 let useport= ""
2701 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002702 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 +00002703 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002704
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002705 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002706 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002707 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002708" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002709 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2710 if executable(curl)
2711 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002712 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 +01002713 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002714 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002715 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002716
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002717 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002718 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002719 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002720" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002721
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002722 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002723 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2724 let bhkeep = &l:bh
2725
2726 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2727 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002728 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002729 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002730
Bram Moolenaarff034192013-04-24 18:51:19 +02002731 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002732 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002733 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002734 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002735 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002736 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002737 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002738 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002739 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002740 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002741
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002742 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002743 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002744 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002745
2746 " remove enew buffer (quietly)
2747 let filtbuf= bufnr("%")
2748 exe curbuf."b!"
2749 let &l:bh = bhkeep
2750 exe filtbuf."bw!"
2751
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002752 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002753
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002754 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002755 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002756 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002757" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002758 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 +00002759 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002760
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002761 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002762 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002763 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002764" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002765 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2767 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2768 else
2769 let uid_machine = g:netrw_machine
2770 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002771
2772 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2773 let bhkeep = &l:bh
2774 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002775 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002776 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002777
Bram Moolenaarff034192013-04-24 18:51:19 +02002778 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002779 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002780" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002781 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002782 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002783 let filtbuf= bufnr("%")
2784 exe curbuf."b!"
2785 let &l:bh = bhkeep
2786 exe filtbuf."bw!"
2787 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002788
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002789 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002790 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002791 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002792 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002793 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002795 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002796
Bram Moolenaar5c736222010-01-06 20:54:52 +01002797 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002798" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002799 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002800" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002801 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002802 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002803 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002804
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002805 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806 " restore modifiability; usually equivalent to set nomod
2807 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002808" 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 +02002809 elseif !exists("leavemod")
2810 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002811" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002812 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" 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 +00002814 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002815
Bram Moolenaar9964e462007-05-05 17:54:07 +00002816" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002817endfun
2818
2819" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002820" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002821" uses NetRead to get a copy of the file into a temporarily file,
2822" then sources that file,
2823" then removes that file.
2824fun! netrw#NetSource(...)
2825" call Dfunc("netrw#NetSource() a:0=".a:0)
2826 if a:0 > 0 && a:1 == '?'
2827 " give help
2828 echomsg 'NetSource Usage:'
2829 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2830 echomsg ':Nsource fetch://machine/path uses fetch'
2831 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002832 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002833 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2834 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2835 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2836 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2837 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002838 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002839 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002840 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002841 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002842" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002843 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002844" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002845 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002846" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002847 if delete(s:netrw_tmpfile)
2848 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2849 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 unlet s:netrw_tmpfile
2851 else
2852 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2853 endif
2854 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002855 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 endif
2857" call Dret("netrw#NetSource")
2858endfun
2859
Bram Moolenaar8d043172014-01-23 14:24:41 +01002860" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002861" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2862" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002863fun! netrw#SetTreetop(iscmd,...)
2864" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2865" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002866
Bram Moolenaar85850f32019-07-19 22:05:51 +02002867 " iscmd==0: netrw#SetTreetop called using gn mapping
2868 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2869" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002870 " clear out the current tree
2871 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002872" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002873 let inittreetop= w:netrw_treetop
2874 unlet w:netrw_treetop
2875 endif
2876 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002877" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002878 unlet w:netrw_treedict
2879 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002880" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002881
Bram Moolenaar85850f32019-07-19 22:05:51 +02002882 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002883 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002884" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002886 if isdirectory(s:NetrwFile(a:1))
2887" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002888 let treedir = a:1
2889 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002890 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002891 let treedir = b:netrw_curdir."/".a:1
2892 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002893" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002894 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895 " normally the cursor is left in the message window.
2896 " However, here this results in the directory being listed in the message window, which is not wanted.
2897 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002898 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002900 let treedir = "."
2901 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002902 endif
2903 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002904" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002905
2906 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907 let islocal= expand("%") !~ '^\a\{3,}://'
2908" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002909
2910 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002911 if islocal
2912 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2913 else
2914 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2915 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002916
Bram Moolenaara6878372014-03-22 21:02:50 +01002917" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002918endfun
2919
Bram Moolenaar9964e462007-05-05 17:54:07 +00002920" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002921" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002922" readcmd == %r : replace buffer with newly read file
2923" == 0r : read file at top of buffer
2924" == r : read file after current line
2925" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002926fun! s:NetrwGetFile(readcmd, tfile, method)
2927" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002928
2929 " readcmd=='t': simply do nothing
2930 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002931" 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 +01002932" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002933 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002934 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002935
Bram Moolenaar9964e462007-05-05 17:54:07 +00002936 " get name of remote filename (ie. url and all)
2937 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002938" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002939
Bram Moolenaar9964e462007-05-05 17:54:07 +00002940 if exists("*NetReadFixup")
2941 " for the use of NetReadFixup (not otherwise used internally)
2942 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002943 endif
2944
Bram Moolenaar9964e462007-05-05 17:54:07 +00002945 if a:readcmd[0] == '%'
2946 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002947" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002948
2949 " rename the current buffer to the temp file (ie. tfile)
2950 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002951 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952 else
2953 let tfile= a:tfile
2954 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002955 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956
2957 " edit temporary file (ie. read the temporary file in)
2958 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002959" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960 call zip#Browse(tfile)
2961 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002962" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002964 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002965" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002966 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002967 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002968" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002969 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002970 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002971" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002972 call tar#Browse(tfile)
2973 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002975 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002978 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002979 endif
2980
2981 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002982 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002983
Bram Moolenaar97d62492012-11-15 21:28:22 +01002984 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002985 " Note that isk must not include a "/" for scripts.vim
2986 " to process this detection correctly.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002988 let iskkeep= &l:isk
2989 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002990 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002991" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002992 let line1 = 1
2993 let line2 = line("$")
2994
Bram Moolenaar8d043172014-01-23 14:24:41 +01002995 elseif !&ma
2996 " 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 +01002997 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002998" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002999 return
3000
Bram Moolenaar9964e462007-05-05 17:54:07 +00003001 elseif s:FileReadable(a:tfile)
3002 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003003" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003004 let curline = line(".")
3005 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003006" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003007 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003008 let line1= curline + 1
3009 let line2= line("$") - lastline + 1
3010
3011 else
3012 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003013" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3014" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003015 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003016" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003017 return
3018 endif
3019
3020 " User-provided (ie. optional) fix-it-up command
3021 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003022" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003023 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003024" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003025" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003026 endif
3027
Bram Moolenaaradc21822011-04-01 18:03:16 +02003028 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003029 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003030 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003031 endif
3032
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003033" 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 +00003034
3035 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003036" redraw!
3037
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003038" 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 +00003039" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003040endfun
3041
Bram Moolenaar9964e462007-05-05 17:54:07 +00003042" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003043" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003044" Input:
3045" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3046" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003047" b:netrw_method= 1: rcp
3048" 2: ftp + <.netrc>
3049" 3: ftp + machine, id, password, and [path]filename
3050" 4: scp
3051" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003052" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003053" 7: rsync
3054" 8: fetch
3055" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003056" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003057" g:netrw_machine= hostname
3058" b:netrw_fname = filename
3059" g:netrw_port = optional port number (for ftp)
3060" g:netrw_choice = copy of input url (choice)
3061fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003062" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003063
Bram Moolenaar251e1912011-06-19 05:09:16 +02003064 " sanity check: choice should have at least three slashes in it
3065 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3066 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3067 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003068" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003069 return
3070 endif
3071
Bram Moolenaar5c736222010-01-06 20:54:52 +01003072 " record current g:netrw_machine, if any
3073 " curmachine used if protocol == ftp and no .netrc
3074 if exists("g:netrw_machine")
3075 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003076" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003077 else
3078 let curmachine= "N O T A HOST"
3079 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003080 if exists("g:netrw_port")
3081 let netrw_port= g:netrw_port
3082 endif
3083
3084 " insure that netrw_ftp_cmd starts off every method determination
3085 " with the current g:netrw_ftp_cmd
3086 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003087
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003088 " initialization
3089 let b:netrw_method = 0
3090 let g:netrw_machine = ""
3091 let b:netrw_fname = ""
3092 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003093 let g:netrw_choice = a:choice
3094
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003095 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003096 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003097 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3098 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003099 " rcpurm : rcp://[user@]host/filename Use rcp
3100 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003101 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003102 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003103 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 " rsyncurm : rsync://host[:port]/path Use rsync
3105 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3106 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003107 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003108 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3109 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003110 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3111 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003113 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003114 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003115 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003117 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003118 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003119 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003120
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003121" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003123 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003125" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003126 let b:netrw_method = 1
3127 let userid = substitute(a:choice,rcpurm,'\1',"")
3128 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3129 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003130 if userid != ""
3131 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003133
Bram Moolenaaradc21822011-04-01 18:03:16 +02003134 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003136" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003137 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003138 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3139 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3140 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003141
Bram Moolenaar15146672011-10-20 22:22:38 +02003142 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003144" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003145 let b:netrw_method = 5
3146 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3147 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003148 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003149
Bram Moolenaaradc21822011-04-01 18:03:16 +02003150 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003152" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003153 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003154 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003155 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3156 else
3157 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3158 endif
3159 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003160
Bram Moolenaaradc21822011-04-01 18:03:16 +02003161 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003163" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 let b:netrw_method = 7
3165 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3166 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003167
Bram Moolenaaradc21822011-04-01 18:03:16 +02003168 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003169 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003170" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003171 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3173 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3174 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003175" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 if userid != ""
3177 let g:netrw_uid= userid
3178 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003179
Bram Moolenaaradc21822011-04-01 18:03:16 +02003180 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003181 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003182 call NetUserPass("ftp:".g:netrw_machine)
3183 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003184 " if there's a change in hostname, require password re-entry
3185 unlet s:netrw_passwd
3186 endif
3187 if exists("netrw_port")
3188 unlet netrw_port
3189 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003190 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003191
Bram Moolenaar446cb832008-06-24 21:56:24 +00003192 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003193 let b:netrw_method = 3
3194 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003195 let host= substitute(g:netrw_machine,'\..*$','','')
3196 if exists("s:netrw_hup[host]")
3197 call NetUserPass("ftp:".host)
3198
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003199 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003200" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3201" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003202 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003203 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003204" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003205 endif
3206 let b:netrw_method= 2
3207 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003208" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003209 let b:netrw_method= 2
3210 else
3211 if !exists("g:netrw_uid") || g:netrw_uid == ""
3212 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003213 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003214 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003215 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003216 endif
3217 let b:netrw_method= 3
3218 endif
3219 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003220
Bram Moolenaaradc21822011-04-01 18:03:16 +02003221 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003222 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003223" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003224 let b:netrw_method = 8
3225 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3226 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3227 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3228 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003229
Bram Moolenaaradc21822011-04-01 18:03:16 +02003230 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003231 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003232" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003233 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003234 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3235 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003236 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003237 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003238 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003239
Bram Moolenaaradc21822011-04-01 18:03:16 +02003240 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003242" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003243 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003244 let b:netrw_method = 3
3245 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3246 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003247
Bram Moolenaar9964e462007-05-05 17:54:07 +00003248 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003249 let b:netrw_method = 2
3250 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3251 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3252 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003253
Bram Moolenaaradc21822011-04-01 18:03:16 +02003254 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003256" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003257 let b:netrw_method = 9
3258 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3259 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003260
Bram Moolenaaradc21822011-04-01 18:03:16 +02003261 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003263" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003264 let b:netrw_method = 1
3265 let userid = substitute(a:choice,rcphf,'\2',"")
3266 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3267 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003268" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3269" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3270" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3271" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003272 if userid != ""
3273 let g:netrw_uid= userid
3274 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003275
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003276 " Method#10: file://user@hostname/...path-to-file {{{3
3277 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003278" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003279 let b:netrw_method = 10
3280 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003281" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003282
Bram Moolenaaradc21822011-04-01 18:03:16 +02003283 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003284 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003285 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003286 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003287 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003288 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003290 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003291
Bram Moolenaar81695252004-12-29 20:58:21 +00003292 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003293 " remove any leading [:#] from port number
3294 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3295 elseif exists("netrw_port")
3296 " retain port number as implicit for subsequent ftp operations
3297 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003298 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003299
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003300" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3301" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3302" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3303" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003304" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003305" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003306" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003307" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003308" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003309" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003310" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003311" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313
3314" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003315" NetReadFixup: this sort of function is typically written by the user {{{2
3316" to handle extra junk that their system's ftp dumps
3317" into the transfer. This function is provided as an
3318" example and as a fix for a Windows 95 problem: in my
3319" experience, win95's ftp always dumped four blank lines
3320" at the end of the transfer.
3321if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3322 fun! NetReadFixup(method, line1, line2)
3323" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003324
3325 " sanity checks -- attempt to convert inputs to integers
3326 let method = a:method + 0
3327 let line1 = a:line1 + 0
3328 let line2 = a:line2 + 0
3329 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3330" call Dret("NetReadFixup")
3331 return
3332 endif
3333
Bram Moolenaar9964e462007-05-05 17:54:07 +00003334 if method == 3 " ftp (no <.netrc>)
3335 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003336 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003337 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003338 call histdel("/",-1)
3339 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003340 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003341
Bram Moolenaar9964e462007-05-05 17:54:07 +00003342" call Dret("NetReadFixup")
3343 endfun
3344endif
3345
3346" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003347" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003348" Usage: :call NetUserPass() -- will prompt for userid and password
3349" :call NetUserPass("uid") -- will prompt for password
3350" :call NetUserPass("uid","password") -- sets global userid and password
3351" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3352" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353fun! NetUserPass(...)
3354
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003355" call Dfunc("NetUserPass() a:0=".a:0)
3356
3357 if !exists('s:netrw_hup')
3358 let s:netrw_hup= {}
3359 endif
3360
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003362 " case: no input arguments
3363
3364 " change host and username if not previously entered; get new password
3365 if !exists("g:netrw_machine")
3366 let g:netrw_machine= input('Enter hostname: ')
3367 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003369 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370 let g:netrw_uid= input('Enter username: ')
3371 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003372 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003373 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003374
3375 " set up hup database
3376 let host = substitute(g:netrw_machine,'\..*$','','')
3377 if !exists('s:netrw_hup[host]')
3378 let s:netrw_hup[host]= {}
3379 endif
3380 let s:netrw_hup[host].uid = g:netrw_uid
3381 let s:netrw_hup[host].passwd = s:netrw_passwd
3382
3383 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003384 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003385
3386 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003387 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003388 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003389" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003390 let host = substitute(a:1,'^ftp:','','')
3391 let host = substitute(host,'\..*','','')
3392 if exists("s:netrw_hup[host]")
3393 let g:netrw_uid = s:netrw_hup[host].uid
3394 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003395" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3396" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003397 else
3398 let g:netrw_uid = input("Enter UserId: ")
3399 let s:netrw_passwd = inputsecret("Enter Password: ")
3400 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003401
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003402 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003403 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003404" 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 +02003405 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003406 if g:netrw_machine =~ '[0-9.]\+'
3407 let host= g:netrw_machine
3408 else
3409 let host= substitute(g:netrw_machine,'\..*$','','')
3410 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003411 else
3412 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003413 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003414 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003415" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003416 if exists("g:netrw_passwd")
3417 " ask for password if one not previously entered
3418 let s:netrw_passwd= g:netrw_passwd
3419 else
3420 let s:netrw_passwd = inputsecret("Enter Password: ")
3421 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003422 endif
3423
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003424" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003425 if exists("host")
3426 if !exists('s:netrw_hup[host]')
3427 let s:netrw_hup[host]= {}
3428 endif
3429 let s:netrw_hup[host].uid = g:netrw_uid
3430 let s:netrw_hup[host].passwd = s:netrw_passwd
3431 endif
3432
3433 elseif a:0 == 2
3434 let g:netrw_uid = a:1
3435 let s:netrw_passwd = a:2
3436
3437 elseif a:0 == 3
3438 " enter hostname, user-id, and password into the hup dictionary
3439 let host = substitute(a:1,'^\a\+:','','')
3440 let host = substitute(host,'\..*$','','')
3441 if !exists('s:netrw_hup[host]')
3442 let s:netrw_hup[host]= {}
3443 endif
3444 let s:netrw_hup[host].uid = a:2
3445 let s:netrw_hup[host].passwd = a:3
3446 let g:netrw_uid = s:netrw_hup[host].uid
3447 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003448" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3449" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003451
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003452" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454
Bram Moolenaar85850f32019-07-19 22:05:51 +02003455" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003456" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003457" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003459" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003460" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3461fun! s:ExplorePatHls(pattern)
3462" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3463 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003464" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003465 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003466" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003467 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3468" call Dret("s:ExplorePatHls repat<".repat.">")
3469 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003470endfun
3471
3472" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003473" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003474" 0: (user: <mb>) bookmark current directory
3475" 1: (user: <gb>) change to the bookmarked directory
3476" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003477" 3: (browsing) records current directory history
3478" 4: (user: <u>) go up (previous) directory, using history
3479" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003480" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003481fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003482" 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 +02003483 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3484" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3485 return
3486 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003487
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003488 let ykeep = @@
3489 let curbufnr = bufnr("%")
3490
Bram Moolenaar9964e462007-05-05 17:54:07 +00003491 if a:chg == 0
3492 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003493" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003494 if exists("s:netrwmarkfilelist_{curbufnr}")
3495 call s:NetrwBookmark(0)
3496 echo "bookmarked marked files"
3497 else
3498 call s:MakeBookmark(a:curdir)
3499 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003500 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003501
3502 elseif a:chg == 1
3503 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003504" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003505 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003506" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003507 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003508 else
3509 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3510 endif
3511
3512 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003513" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003514 let didwork= 0
3515 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003516" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003517 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003518" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003519 let cnt= 1
3520 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003521" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003522 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003523 let didwork = 1
3524 let cnt = cnt + 1
3525 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003526 endif
3527
3528 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003529 " Note: history is saved only when PerformListing is done;
3530 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3531 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003532 let first = 1
3533 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003534 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003535 while ( first || cnt != g:netrw_dirhistcnt )
3536" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003537 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003538" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003539 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003540 let didwork= 1
3541 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003542 let histcnt = histcnt + 1
3543 let first = 0
3544 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003545 if cnt < 0
3546 let cnt= cnt + g:netrw_dirhistmax
3547 endif
3548 endwhile
3549 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003550 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003552 if didwork
3553 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3554 endif
3555
3556 elseif a:chg == 3
3557 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003558" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003559 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 +02003560 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3562 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003563 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003564" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003565 endif
3566
3567 elseif a:chg == 4
3568 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003569" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003570 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003571 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3572 if g:netrw_dirhistcnt < 0
3573 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003574 endif
3575 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003576 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003577 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003578 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3579" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003580 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003581 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003582" call Decho("setl ma noro",'~'.expand("<slnum>"))
3583 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003584 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003585" call Decho("setl nomod",'~'.expand("<slnum>"))
3586" 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 +00003587 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003588" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3589 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003590 else
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
Bram Moolenaaradc21822011-04-01 18:03:16 +02003593 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003594 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003595 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003596 echo "Sorry, no predecessor directory exists yet"
3597 endif
3598
3599 elseif a:chg == 5
3600 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003601" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003602 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003603 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3604 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3605" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003606 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003607" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003608 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003609 sil! NetrwKeepj %d _
3610" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3611" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003612 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003613" 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 +02003614 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003615" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3616 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003617 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003618 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3619 if g:netrw_dirhistcnt < 0
3620 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003621 endif
3622 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003623 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003624 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003625 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003626 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003627 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003628
3629 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003631 if exists("s:netrwmarkfilelist_{curbufnr}")
3632 call s:NetrwBookmark(1)
3633 echo "removed marked files from bookmarks"
3634 else
3635 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003636 let iremove = v:count
3637 let dremove = g:netrw_bookmarklist[iremove - 1]
3638" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003639 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003640" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3641 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3642 echo "removed ".dremove." from g:netrw_bookmarklist"
3643" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003644 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003645" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003646 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003647 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003648 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003649 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003650" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003651endfun
3652
3653" ---------------------------------------------------------------------
3654" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003655" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003656" Sister function: s:NetrwBookHistSave()
3657fun! s:NetrwBookHistRead()
3658" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003659 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003660" 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 +02003661 return
3662 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003663 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003664
3665 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003666 if !exists("s:netrw_initbookhist")
3667 let home = s:NetrwHome()
3668 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003669 if filereadable(s:NetrwFile(savefile))
3670" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003671 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003672 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003673
3674 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003675 if g:netrw_dirhistmax > 0
3676 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003677 if filereadable(s:NetrwFile(savefile))
3678" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003679 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003680 endif
3681 let s:netrw_initbookhist= 1
3682 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003684 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003685
Bram Moolenaar97d62492012-11-15 21:28:22 +01003686 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003687" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3688" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003689" call Dret("s:NetrwBookHistRead")
3690endfun
3691
3692" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003693" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003694" Sister function: s:NetrwBookHistRead()
3695" I used to do this via viminfo but that appears to
3696" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003697" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3698" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003699" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003700fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003701" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003702 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003703" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003704 return
3705 endif
3706
Bram Moolenaar5c736222010-01-06 20:54:52 +01003707 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003708" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003709 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003710
3711 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003712 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003713" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003714 if g:netrw_use_noswf
3715 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3716 else
3717 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3718 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003719 setl nocin noai noci magic nospell nohid wig= noaw
3720 setl ma noro write
3721 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003722 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003723
Bram Moolenaar85850f32019-07-19 22:05:51 +02003724 " rename enew'd file: .netrwhist -- no attempt to merge
3725 " record dirhistmax and current dirhistcnt
3726 " save history
3727" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003728 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003729 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003730 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3731 if g:netrw_dirhistmax > 0
3732 let lastline = line("$")
3733 let cnt = g:netrw_dirhistcnt
3734 let first = 1
3735 while ( first || cnt != g:netrw_dirhistcnt )
3736 let lastline= lastline + 1
3737 if exists("g:netrw_dirhist_{cnt}")
3738 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3739" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3740 endif
3741 let first = 0
3742 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3743 if cnt < 0
3744 let cnt= cnt + g:netrw_dirhistmax
3745 endif
3746 endwhile
3747 exe "sil! w! ".savefile
3748" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3749 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750
Bram Moolenaar85850f32019-07-19 22:05:51 +02003751 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003752 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003753 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003754" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003755 " merge and write .netrwbook
3756 let savefile= s:NetrwHome()."/.netrwbook"
3757
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003758 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003759 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003760 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003761 for bdm in booklist
3762 if index(g:netrw_bookmarklist,bdm) == -1
3763 call add(g:netrw_bookmarklist,bdm)
3764 endif
3765 endfor
3766 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003767 endif
3768
3769 " construct and save .netrwbook
3770 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003771 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003772" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003773 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003774
3775 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003776 let bgone= bufnr("%")
3777 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003778 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003779
3780" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003781endfun
3782
3783" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003784" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3785" list of the contents of a local or remote directory. It is assumed that the
3786" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3787" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003788" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003789fun! s:NetrwBrowse(islocal,dirname)
3790 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003791" 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 +02003792" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3793" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3794" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003795
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003796 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3797 " This is useful when one edits a local file, then :e ., then :Rex
3798 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3799 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003800" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003803 " s:NetrwBrowse : initialize history {{{3
3804 if !exists("s:netrw_initbookhist")
3805 NetrwKeepj call s:NetrwBookHistRead()
3806 endif
3807
3808 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003809 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003810 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003811" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003812 else
3813 let dirname= a:dirname
3814 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003815
Bram Moolenaar85850f32019-07-19 22:05:51 +02003816 " repoint t:netrw_lexbufnr if appropriate
3817 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3818" call Decho("set repointlexbufnr to true!")
3819 let repointlexbufnr= 1
3820 endif
3821
3822 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003823 if exists("s:netrw_skipbrowse")
3824 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003825" 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 +01003826" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003827 return
3828 endif
3829 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003830 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003831" call Dret("s:NetrwBrowse : missing shellescape()")
3832 return
3833 endif
3834 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003835 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003836" call Dret("s:NetrwBrowse : missing fnameescape()")
3837 return
3838 endif
3839
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003840 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003841 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003842
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003843 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003844 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3845 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3846" call Decho("clearing marked files",'~'.expand("<slnum>"))
3847 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3848 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003849 endif
3850
3851 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003852 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003853" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3854" 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 +02003855 if s:NetrwLcd(dirname)
3856" call Dret("s:NetrwBrowse : lcd failure")
3857 return
3858 endif
3859 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003860" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003861
Bram Moolenaar5c736222010-01-06 20:54:52 +01003862 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003863 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003864" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003865 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003866" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003868 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003871
3872 " remove any filetype indicator from end of dirname, except for the
3873 " "this is a directory" indicator (/).
3874 " There shouldn't be one of those here, anyway.
3875 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003876" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003877 call s:RemotePathAnalysis(dirname)
3878
3879 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3880 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003881 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003882 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003883" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003884 let b:netrw_curdir = dirname
3885 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003886 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003887 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3888 sil call netrw#NetRead(2,url)
3889 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003890" call Decho("url<".url.">",'~'.expand("<slnum>"))
3891" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3892" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003893 if s:path =~ '.bz2'
3894 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3895 elseif s:path =~ '.gz'
3896 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3897 elseif s:path =~ '.gz'
3898 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3899 else
3900 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3901 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003902 endif
3903
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003904 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003905 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003906 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003907" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003908 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003909" 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 +00003910
Bram Moolenaar446cb832008-06-24 21:56:24 +00003911" call Dret("s:NetrwBrowse : file<".s:fname.">")
3912 return
3913 endif
3914
Bram Moolenaaradc21822011-04-01 18:03:16 +02003915 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003916 call s:UseBufWinVars()
3917
3918 " set up some variables {{{3
3919 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003920 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921 let s:last_sort_by = g:netrw_sort_by
3922
3923 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003924 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925
Bram Moolenaar97d62492012-11-15 21:28:22 +01003926 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003927" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003928 let svpos = winsaveview()
3929" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003930 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003931
Bram Moolenaar446cb832008-06-24 21:56:24 +00003932 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003933 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3934 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3935" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3936" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3937 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3938 else
3939" " call Decho("2match none",'~'.expand("<slnum>"))
3940 2match none
3941 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003942 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003943 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003944 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003945" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003946 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003947" 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 +01003948" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003949 return
3950 endif
3951
3952 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003953" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003954 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003955 if b:netrw_curdir =~ '[/\\]$'
3956 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3957 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003958 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3959 let b:netrw_curdir= b:netrw_curdir."/"
3960 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003961 if b:netrw_curdir == ''
3962 if has("amiga")
3963 " On the Amiga, the empty string connotes the current directory
3964 let b:netrw_curdir= getcwd()
3965 else
3966 " under unix, when the root directory is encountered, the result
3967 " from the preceding substitute is an empty string.
3968 let b:netrw_curdir= '/'
3969 endif
3970 endif
3971 if !a:islocal && b:netrw_curdir !~ '/$'
3972 let b:netrw_curdir= b:netrw_curdir.'/'
3973 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003974" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003975
3976 " ------------
3977 " (local only) {{{3
3978 " ------------
3979 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003980" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003981
3982 " Set up ShellCmdPost handling. Append current buffer to browselist
3983 call s:LocalFastBrowser()
3984
3985 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3986 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3988" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003989 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003990 if s:NetrwLcd(b:netrw_curdir)
3991" call Dret("s:NetrwBrowse : lcd failure")
3992 return
3993 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994 endif
3995 endif
3996
3997 " --------------------------------
3998 " remote handling: {{{3
3999 " --------------------------------
4000 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004001" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004002
Bram Moolenaar97d62492012-11-15 21:28:22 +01004003 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004004" 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 +02004005 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004007" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004008 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4009 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4010 if dirname !~ '/$'
4011 let dirname= dirname.'/'
4012 endif
4013 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004014" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004015 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004016 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004017" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004018 endif
4019
4020 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4021 if dirname !~ dirpat
4022 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004023 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004024 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004025 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004026" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004027 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004028" 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 +00004029" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4030 return
4031 endif
4032 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004033" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004034 endif " (additional remote handling)
4035
Bram Moolenaar85850f32019-07-19 22:05:51 +02004036 " -------------------------------
4037 " Perform Directory Listing: {{{3
4038 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004039 NetrwKeepj call s:NetrwMaps(a:islocal)
4040 NetrwKeepj call s:NetrwCommands(a:islocal)
4041 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004042
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004043 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004044 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004045" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4046
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004047 " If there is a rexposn: restore position with rexposn
4048 " Otherwise : set rexposn
4049 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004050" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4051 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4052 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4053 NetrwKeepj exe w:netrw_bannercnt
4054 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004055 else
4056 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4057 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004058 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004059 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004060" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004061 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004062 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004063
Bram Moolenaar85850f32019-07-19 22:05:51 +02004064 " repoint t:netrw_lexbufnr if appropriate
4065 if exists("repointlexbufnr")
4066 let t:netrw_lexbufnr= bufnr("%")
4067" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4068 endif
4069
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004070 " restore position
4071 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004072" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4073 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004074 endif
4075
Bram Moolenaara6878372014-03-22 21:02:50 +01004076 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004077 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4078 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004079" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4080" 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 +02004081" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004082 return
4083endfun
4084
4085" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004086" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4087" may not apply correctly; ie. netrw's idea of the current directory may
4088" differ from vim's. This function insures that netrw's idea of the current
4089" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004090" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004091fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004092" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4093" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4094" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4095" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4096" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004097
4098 " clean up any leading treedepthstring
4099 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4100 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004101" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004102 else
4103 let fname= a:fname
4104 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105
4106 if g:netrw_keepdir
4107 " vim's idea of the current directory possibly may differ from netrw's
4108 if !exists("b:netrw_curdir")
4109 let b:netrw_curdir= getcwd()
4110 endif
4111
4112 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004113 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004115 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004116" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117 else
4118 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004120" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004121 endif
4122
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004123 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004124 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004125 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004126" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004127 else
4128 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004129 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004130" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131 endif
4132 else
4133 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004134 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004135" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4136" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4137" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004138 endif
4139
Bram Moolenaar85850f32019-07-19 22:05:51 +02004140" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004141 return ret
4142endfun
4143
4144" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004145" s:NetrwFileInfo: supports qf (query for file information) {{{2
4146fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004147" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004148 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004150 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004151 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004152 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004153 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 let lsopt= "-lsadh --si"
4155 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004156" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004157 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004158
4159 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004160 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004162
Bram Moolenaara6878372014-03-22 21:02:50 +01004163 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004164 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004166
4167 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004168 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004170
Bram Moolenaar446cb832008-06-24 21:56:24 +00004171 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004172" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004173 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004174" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004175 endif
4176 else
4177 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004178" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4179 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004180 let fname= substitute(a:fname,".$","","")
4181 else
4182 let fname= a:fname
4183 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004184 let t = getftime(s:NetrwFile(fname))
4185 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004186 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004187 let sz= s:NetrwHumanReadable(sz)
4188 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004189 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4190" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004191 endif
4192 else
4193 echo "sorry, \"qf\" not supported yet for remote files"
4194 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004195 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004196" call Dret("s:NetrwFileInfo")
4197endfun
4198
4199" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004200" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4201fun! s:NetrwFullPath(filename)
4202" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4203 let filename= a:filename
4204 if filename !~ '^/'
4205 let filename= resolve(getcwd().'/'.filename)
4206 endif
4207 if filename != "/" && filename =~ '/$'
4208 let filename= substitute(filename,'/$','','')
4209 endif
4210" " call Dret("s:NetrwFullPath <".filename.">")
4211 return filename
4212endfun
4213
4214" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004215" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004216" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004217" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004218" 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 +00004219fun! s:NetrwGetBuffer(islocal,dirname)
4220" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004221" 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 +02004222" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4223" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004224 let dirname= a:dirname
4225
4226 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004227" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004228 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004229" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004230 let s:netrwbuf= {}
4231 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004232" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4233" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4234
4235 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4236 let bufnum = -1
4237
4238 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4239 if has_key(s:netrwbuf,"NetrwTreeListing")
4240 let bufnum= s:netrwbuf["NetrwTreeListing"]
4241 else
4242 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4243 endif
4244" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4245 if !bufexists(bufnum)
4246 call remove(s:netrwbuf,"NetrwTreeListing"])
4247 let bufnum= -1
4248 endif
4249 elseif bufnr("NetrwTreeListing") != -1
4250 let bufnum= bufnr("NetrwTreeListing")
4251" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4252 else
4253" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4254 let bufnum= -1
4255 endif
4256
4257 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004258 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004259" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004260 if !bufexists(bufnum)
4261 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4262 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004263 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004264
Bram Moolenaar446cb832008-06-24 21:56:24 +00004265 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004266" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004267 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004268 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004269" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4270
Bram Moolenaar6c391a72021-09-09 21:55:11 +02004271 " hijack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004272 " IF the buffer already has the desired name
4273 " AND it is empty
4274 let curbuf = bufname("%")
4275 if curbuf == '.'
4276 let curbuf = getcwd()
4277 endif
4278" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar6c391a72021-09-09 21:55:11 +02004279" call Decho("deciding if netrw may hijack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004280" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4281" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4282" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4283" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4284 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004285" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4286 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004287 else " DEBUG
Bram Moolenaar6c391a72021-09-09 21:55:11 +02004288" call Decho("..did NOT hijack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004289 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004290 " 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 +00004291
4292 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004293 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004294" 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 +00004295 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004296" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004297 " name the buffer
4298 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4299 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004300" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004301 let w:netrw_treebufnr = bufnr("%")
4302 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004303 if g:netrw_use_noswf
4304 setl nobl bt=nofile noswf
4305 else
4306 setl nobl bt=nofile
4307 endif
4308 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4309 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4310 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4311 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004312" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004314 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004315 " enter the new buffer into the s:netrwbuf dictionary
4316 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4317" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4318" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004319 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004320" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004321
4322 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004323" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004325 setl ei=all
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004326 if getline(2) =~# '^" Netrw Directory Listing'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004327" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
4328 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004330" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
4331 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004333" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004334 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004335 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336 endif
4337 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004338
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004339 if line("$") <= 1 && getline(1) == ""
4340 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004341 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004342" 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>"))
4343" 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 +01004344" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4345 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004346
Bram Moolenaar97d62492012-11-15 21:28:22 +01004347 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004348" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004349 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350 sil NetrwKeepj %d _
4351" 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>"))
4352" 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 +01004353" 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 +00004354 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004355
Bram Moolenaar446cb832008-06-24 21:56:24 +00004356 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004357" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4358" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004359 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004360 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004361 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362" 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>"))
4363" 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 +01004364" 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 +00004365 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004366
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004368" 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>"))
4369" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4370" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 return 1
4372 endif
4373 endif
4374
4375 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4376 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4377 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4378 " med 1 D H
4379 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380" 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 +00004381 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004382 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004383 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004384
4385 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004386" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4387" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4388 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004390" 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>"))
4391" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4392" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004393 return 0
4394endfun
4395
4396" ---------------------------------------------------------------------
4397" s:NetrwGetcwd: get the current directory. {{{2
4398" Change backslashes to forward slashes, if any.
4399" If doesc is true, escape certain troublesome characters
4400fun! s:NetrwGetcwd(doesc)
4401" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4402 let curdir= substitute(getcwd(),'\\','/','ge')
4403 if curdir !~ '[\/]$'
4404 let curdir= curdir.'/'
4405 endif
4406 if a:doesc
4407 let curdir= fnameescape(curdir)
4408 endif
4409" call Dret("NetrwGetcwd <".curdir.">")
4410 return curdir
4411endfun
4412
4413" ---------------------------------------------------------------------
4414" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4415fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004416" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4417" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4418 let keepsol= &l:sol
4419 setl nosol
4420
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421 call s:UseBufWinVars()
4422
4423 " insure that w:netrw_liststyle is set up
4424 if !exists("w:netrw_liststyle")
4425 if exists("g:netrw_liststyle")
4426 let w:netrw_liststyle= g:netrw_liststyle
4427 else
4428 let w:netrw_liststyle= s:THINLIST
4429 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004430" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004431 endif
4432
4433 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4434 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004435" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004436 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004437 let dirname= "./"
4438 let curline= getline('.')
4439
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004440 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004441 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442 let s:netrw_skipbrowse= 1
4443 echo 'Pressing "s" also works'
4444
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004445 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004446 let s:netrw_skipbrowse= 1
4447 echo 'Press "S" to edit sorting sequence'
4448
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004449 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004450 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004451 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004452
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004453 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004454 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455 let s:netrw_skipbrowse= 1
4456 echo 'Pressing "a" also works'
4457
4458 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004459 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004460 endif
4461
4462 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004463" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004464 NetrwKeepj norm! 0
4465 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466
4467 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004468" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004469 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004470 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4471
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004472 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004473" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004474 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004475 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004476
4477 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004478" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004479 let dirname= getline('.')
4480
4481 if !exists("b:netrw_cpf")
4482 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004483 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 +01004484 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004485" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 endif
4487
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004488" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004490" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4491" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004493 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 else
4495 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004496 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004497 endif
4498 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004499 let eofname= filestart + b:netrw_cpf + 1
4500 if eofname <= col("$")
4501 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004502 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004503 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004504 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004505 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004506 let dirname = @a
4507 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004508" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004509 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004510" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004511 endif
4512
4513 " symlinks are indicated by a trailing "@". Remove it before further processing.
4514 let dirname= substitute(dirname,"@$","","")
4515
4516 " executables are indicated by a trailing "*". Remove it before further processing.
4517 let dirname= substitute(dirname,"\*$","","")
4518
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004519 let &l:sol= keepsol
4520
Bram Moolenaar446cb832008-06-24 21:56:24 +00004521" call Dret("s:NetrwGetWord <".dirname.">")
4522 return dirname
4523endfun
4524
4525" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004526" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4527" g:netrw_bufsettings will be used after the listing is produced.
4528" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004529fun! s:NetrwListSettings(islocal)
4530" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004531" 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 +00004532 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004533" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4534 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4535 setl bt=nofile nobl ma nonu nowrap noro nornu
4536 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004537 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004538 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004539 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004540" call Dredir("ls!","s:NetrwListSettings")
4541" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004542 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004543 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004545 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004546 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004547 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004549" 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 +00004550" call Dret("s:NetrwListSettings")
4551endfun
4552
4553" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004554" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004555" islocal=0: remote browsing
4556" =1: local browsing
4557fun! s:NetrwListStyle(islocal)
4558" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004559
Bram Moolenaar97d62492012-11-15 21:28:22 +01004560 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561 let fname = s:NetrwGetWord()
4562 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004563 let svpos = winsaveview()
4564" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004566" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4567" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4568" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569
Bram Moolenaar85850f32019-07-19 22:05:51 +02004570 " repoint t:netrw_lexbufnr if appropriate
4571 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4572" call Decho("set repointlexbufnr to true!")
4573 let repointlexbufnr= 1
4574 endif
4575
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576 if w:netrw_liststyle == s:THINLIST
4577 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004578" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004579 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4580
4581 elseif w:netrw_liststyle == s:LONGLIST
4582 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004583" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4585
4586 elseif w:netrw_liststyle == s:WIDELIST
4587 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004588" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4590
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004591 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004592" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004593 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4594
4595 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004596 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 let g:netrw_liststyle = s:THINLIST
4598 let w:netrw_liststyle = g:netrw_liststyle
4599 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4600 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004601 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004602" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004603
4604 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004605" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4606 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004607 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004608" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004609 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" 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 +00004611
4612 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004613" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004614 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004615 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004616
Bram Moolenaar85850f32019-07-19 22:05:51 +02004617 " repoint t:netrw_lexbufnr if appropriate
4618 if exists("repointlexbufnr")
4619 let t:netrw_lexbufnr= bufnr("%")
4620" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4621 endif
4622
Bram Moolenaar13600302014-05-22 18:26:40 +02004623 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004624" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4625 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004626 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004627
4628" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4629endfun
4630
4631" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004632" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4633fun! s:NetrwBannerCtrl(islocal)
4634" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4635
Bram Moolenaar97d62492012-11-15 21:28:22 +01004636 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004637 " toggle the banner (enable/suppress)
4638 let g:netrw_banner= !g:netrw_banner
4639
4640 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004641 let svpos= winsaveview()
4642" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004643 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4644
4645 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004646 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4647 let fname= s:NetrwGetWord()
4648 sil NetrwKeepj $
4649 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4650" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4651 if result <= 0 && exists("w:netrw_bannercnt")
4652 exe "NetrwKeepj ".w:netrw_bannercnt
4653 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004654 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004655 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004656" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4657endfun
4658
4659" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004660" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4661"
4662" No bang: enters files/directories into Netrw's bookmark system
4663" No argument and in netrw buffer:
4664" if there are marked files: bookmark marked files
4665" otherwise : bookmark file/directory under cursor
4666" No argument and not in netrw buffer: bookmarks current open file
4667" Has arguments: globs them individually and bookmarks them
4668"
4669" With bang: deletes files/directories from Netrw's bookmark system
4670fun! s:NetrwBookmark(del,...)
4671" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4672 if a:0 == 0
4673 if &ft == "netrw"
4674 let curbufnr = bufnr("%")
4675
4676 if exists("s:netrwmarkfilelist_{curbufnr}")
4677 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004678" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004679 let svpos = winsaveview()
4680" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004681 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004682 for fname in s:netrwmarkfilelist_{curbufnr}
4683 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4684 endfor
4685 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4686 call s:NetrwUnmarkList(curbufnr,curdir)
4687 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004688" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4689 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004690 else
4691 let fname= s:NetrwGetWord()
4692 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4693 endif
4694
4695 else
4696 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004697" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004698 let fname= expand("%")
4699 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4700 endif
4701
4702 else
4703 " bookmark specified files
4704 " attempts to infer if working remote or local
4705 " by deciding if the current file begins with an url
4706 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004707 let islocal= expand("%") !~ '^\a\{3,}://'
4708" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004709 let i = 1
4710 while i <= a:0
4711 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004712 if v:version > 704 || (v:version == 704 && has("patch656"))
4713 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004714 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004715 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004716 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004717 else
4718 let mbfiles= [a:{i}]
4719 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004720" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004721 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004723 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4724 endfor
4725 let i= i + 1
4726 endwhile
4727 endif
4728
4729 " update the menu
4730 call s:NetrwBookmarkMenu()
4731
4732" call Dret("s:NetrwBookmark")
4733endfun
4734
4735" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004736" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4737" .2.[cnt] for bookmarks, and
4738" .3.[cnt] for history
4739" (see s:NetrwMenu())
4740fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004741 if !exists("s:netrw_menucnt")
4742 return
4743 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004744" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004745
4746 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004747 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004748 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004749" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004750 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4751 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004752 endif
4753 if !exists("s:netrw_initbookhist")
4754 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004755 endif
4756
4757 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004758 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004759 let cnt= 1
4760 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004761" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004762 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004763
4764 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004765 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004766
4767 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004768 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 +01004769 let cnt= cnt + 1
4770 endfor
4771
4772 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004773
4774 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004775 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004776 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004777 let first = 1
4778 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004779 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004780 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004781 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 if exists("g:netrw_dirhist_{cnt}")
4783 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004784" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004785 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4786 endif
4787 let first = 0
4788 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4789 if cnt < 0
4790 let cnt= cnt + g:netrw_dirhistmax
4791 endif
4792 endwhile
4793 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004794
Bram Moolenaar9964e462007-05-05 17:54:07 +00004795 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004796" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004797endfun
4798
4799" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004800" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4801" directory and a new directory name. Also, if the
4802" "new directory name" is actually a file,
4803" NetrwBrowseChgDir() edits the file.
4804fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004805" 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 +01004806" 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 +00004807
Bram Moolenaar97d62492012-11-15 21:28:22 +01004808 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004809 if !exists("b:netrw_curdir")
4810 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4811 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004812 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004813" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4814" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004815" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004816" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004817 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004818 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004819" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004820
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004821 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004822" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004823 call s:SavePosn(s:netrw_posn)
4824 NetrwKeepj call s:NetrwOptionsSave("s:")
4825 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004826 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004827 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004828 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004829 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004830 endif
4831 let newdir = a:newdir
4832 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004833 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004834" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004835" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004836" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004837
4838 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004839" 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 +01004840 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004841" 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 +01004842 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004843 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004844" 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 +01004845 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004846" 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 +02004847 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004848 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004849 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004850 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004851" 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 +01004852 endif
4853 endif
4854" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004855" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004856 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004857
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858 " set up o/s-dependent directory recognition pattern
4859 if has("amiga")
4860 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004861 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004862 let dirpat= '[\/]$'
4863 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004864" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865
4866 if dirname !~ dirpat
4867 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004868 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004869 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004870" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871 endif
4872
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004873" 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 +01004874 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004875 " ------------------------------
4876 " NetrwBrowseChgDir: edit a file {{{3
4877 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004878" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004879
Bram Moolenaar97d62492012-11-15 21:28:22 +01004880 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004881 let s:rexposn_{bufnr("%")}= winsaveview()
4882" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004883" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4884" 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 +01004885
Bram Moolenaar446cb832008-06-24 21:56:24 +00004886 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004887" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4888" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004889" let newdir = s:NetrwTreePath(s:netrw_treetop)
4890" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004891 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004892 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4893" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4894 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004895 if dirname =~ '/$'
4896 let dirname= dirname.newdir
4897 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004898 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004900" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4901" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004903" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004905 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004907 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004908" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004909 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004911" 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 +02004912 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004913 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004915" " 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 +01004916 if type(g:netrw_browse_split) == 3
4917 " open file in server
4918 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004919" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004920 call s:NetrwServerEdit(a:islocal,dirname)
4921" call Dret("s:NetrwBrowseChgDir")
4922 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004923
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004924 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004925 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004926" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004927 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4928 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004929 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004930 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004931 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004932 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004933
Bram Moolenaar446cb832008-06-24 21:56:24 +00004934 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004935 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004936" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004937 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4938 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004939 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004940 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004941 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004942 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004943
Bram Moolenaar446cb832008-06-24 21:56:24 +00004944 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004945 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004946" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004947 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004948 if !exists("b:netrw_curdir")
4949 let b:netrw_curdir= getcwd()
4950 endif
4951 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004952
Bram Moolenaar446cb832008-06-24 21:56:24 +00004953 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004954 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004955" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004956 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004957 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004958" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004959 return
4960 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004961 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004962
Bram Moolenaar9964e462007-05-05 17:54:07 +00004963 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004964 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004965" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966 call s:NetrwMenu(0)
4967 " optional change to window
4968 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004969" 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 +02004970 if winnr("$")+1 == g:netrw_chgwin
4971 " if g:netrw_chgwin is set to one more than the last window, then
4972 " vertically split the last window to make that window available.
4973 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004974 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004975 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004976 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004977 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004978 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004979 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004980 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004981 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004982
Bram Moolenaar9964e462007-05-05 17:54:07 +00004983 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004984
Bram Moolenaar446cb832008-06-24 21:56:24 +00004985 " the point where netrw actually edits the (local) file
4986 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004987 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004988 if !&mod
4989 " if e the new file would fail due to &mod, then don't change any of the flags
4990 let dolockout= 1
4991 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004992 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004993" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004994 " some like c-^ to return to the last edited file
4995 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004996 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4997 " so emit error E37 instead.
Bram Moolenaar8d043172014-01-23 14:24:41 +01004998 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004999 exe "NetrwKeepj keepalt e ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01005000 else
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005001 exe "NetrwKeepj e ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01005002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005003" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005004 " COMBAK -- cuc cul related
5005 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005006 if &hidden || &bufhidden == "hide"
5007 " file came from vim's hidden storage. Don't "restore" options with it.
5008 let dorestore= 0
5009 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005010 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005011" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005012 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005013
5014 " handle g:Netrw_funcref -- call external-to-netrw functions
5015 " This code will handle g:Netrw_funcref as an individual function reference
5016 " or as a list of function references. It will ignore anything that's not
5017 " a function reference. See :help Funcref for information about function references.
5018 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005019" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005020 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005021" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005022 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005023 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005024" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005025 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005026 if type(Fncref) == 2
5027 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005028 endif
5029 endfor
5030 endif
5031 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005032 endif
5033
5034 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005035 " ----------------------------------------------------
5036 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5037 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005039 let dirname = newdir
5040 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005041 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005042 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005043
5044 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005045 " ---------------------------------------------
5046 " NetrwBrowseChgDir: refresh the directory list {{{3
5047 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005048" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005049 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005050 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005051
5052 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005053 " --------------------------------------
5054 " NetrwBrowseChgDir: go up one directory {{{3
5055 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005056" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005057
5058 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5059 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005060" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5061" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005062 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005063 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005064 endif
5065
5066 if has("amiga")
5067 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005068" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005069 if a:islocal
5070 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5071 let dirname= substitute(dirname,'/$','','')
5072 else
5073 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5074 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005075" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005076
Bram Moolenaar8d043172014-01-23 14:24:41 +01005077 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5078 " windows
5079 if a:islocal
5080 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5081 if dirname == ""
5082 let dirname= '/'
5083 endif
5084 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005085 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005086 endif
5087 if dirname =~ '^\a:$'
5088 let dirname= dirname.'/'
5089 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005090" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005091
Bram Moolenaar446cb832008-06-24 21:56:24 +00005092 else
5093 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005094" 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 +00005095 if a:islocal
5096 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5097 if dirname == ""
5098 let dirname= '/'
5099 endif
5100 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005101 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005102 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005103" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005104 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005105 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005106 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005107
5108 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005109 " --------------------------------------
5110 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5111 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005112" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5114" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005115 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005116 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005117" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5118 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005119 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005120 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005122 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005123 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005124" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125
5126 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005127" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005128 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005129" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130 let haskey= 1
5131 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005132" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005133 endif
5134
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005135 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005136" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005137 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005138 if has_key(w:netrw_treedict,treedir."/")
5139 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005140" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141 let haskey = 1
5142 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005143" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144 endif
5145 endif
5146
5147 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005148" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 if !haskey && treedir =~ '/$'
5150 let treedir= substitute(treedir,'/$','','')
5151 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005152" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 let haskey = 1
5154 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005155" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156 endif
5157 endif
5158
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005159" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 if haskey
5161 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005162" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005163 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005164" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5165" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005166 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 else
5168 " go down one directory
5169 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005170" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5171" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005172 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005173 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005174" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005175 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005176
5177 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005178 " ----------------------------------------
5179 " NetrwBrowseChgDir: Go down one directory {{{3
5180 " ----------------------------------------
5181 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005182" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005183 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005184 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005185 endif
5186
Bram Moolenaar97d62492012-11-15 21:28:22 +01005187 " --------------------------------------
5188 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5189 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005190 if dorestore
5191 " dorestore is zero'd when a local file was hidden or bufhidden;
5192 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005194 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005195" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005196" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005197 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005198 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005199" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005200 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005201" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5202" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005203 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" 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 +02005205 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005206" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5207" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005208 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005209" 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 +02005210 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005211 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005212 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005213 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005214
Bram Moolenaar446cb832008-06-24 21:56:24 +00005215" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5216 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005217endfun
5218
5219" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005220" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5221" for thin, long, and wide: cursor placed just after banner
5222" for tree, keeps cursor on current filename
5223fun! s:NetrwBrowseUpDir(islocal)
5224" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005225 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5226 " this test needed because occasionally this function seems to be incorrectly called
5227 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005228 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005229 " directories.
5230" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5231 return
5232 endif
5233
Bram Moolenaara6878372014-03-22 21:02:50 +01005234 norm! 0
5235 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005236" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005237 let curline= getline(".")
5238 let swwline= winline() - 1
5239 if exists("w:netrw_treetop")
5240 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005241 elseif exists("b:netrw_curdir")
5242 let w:netrw_treetop= b:netrw_curdir
5243 else
5244 let w:netrw_treetop= getcwd()
5245 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005247 let curfile = getline(".")
5248 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005249 if a:islocal
5250 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5251 else
5252 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5253 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005254" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5255" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5256 if w:netrw_treetop == '/'
5257 keepj call search('^\M'.curfile,"w")
5258 elseif curfile == '../'
5259 keepj call search('^\M'.curfile,"wb")
5260 else
5261" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5262 while 1
5263 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5264 let treepath= s:NetrwTreePath(w:netrw_treetop)
5265" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5266 if treepath == curpath
5267 break
5268 endif
5269 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005270 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005271
Bram Moolenaara6878372014-03-22 21:02:50 +01005272 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005273" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005274 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005275 if exists("b:netrw_curdir")
5276 let curdir= b:netrw_curdir
5277 else
5278 let curdir= expand(getcwd())
5279 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005280 if a:islocal
5281 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5282 else
5283 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5284 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005285 call s:RestorePosn(s:netrw_posn)
5286 let curdir= substitute(curdir,'^.*[\/]','','')
5287 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005288 endif
5289" call Dret("s:NetrwBrowseUpDir")
5290endfun
5291
5292" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005293" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005294" given filename; typically this means given their extension.
5295" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005296fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005297 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005298" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005299
Bram Moolenaar91359012019-11-30 17:57:03 +01005300 if a:remote == 0 && isdirectory(a:fname)
5301 " if its really just a local directory, then do a "gf" instead
5302" 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 +01005303" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5304 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005305" call Dret("netrw#BrowseX")
5306 return
5307 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5308 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5309" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5310" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5311" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5312" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5313 norm! gf
5314" call Dret("netrw#BrowseX")
5315 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005316 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005317" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005318
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005319 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5320 let remote = a:remote
5321 else
5322 let remote = 0
5323 endif
5324
Bram Moolenaar97d62492012-11-15 21:28:22 +01005325 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005326 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005327" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005328
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005329 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5330 let awkeep = &aw
5331 set noaw
5332
Bram Moolenaar5c736222010-01-06 20:54:52 +01005333 " special core dump handler
5334 if a:fname =~ '/core\(\.\d\+\)\=$'
5335 if exists("g:Netrw_corehandler")
5336 if type(g:Netrw_corehandler) == 2
5337 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005338" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005339 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005340 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005341 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005342" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343 for Fncref in g:Netrw_corehandler
5344 if type(FncRef) == 2
5345 call FncRef(a:fname)
5346 endif
5347 endfor
5348 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005349" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005350 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005351 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005352 let &aw= awkeep
5353" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005354 return
5355 endif
5356 endif
5357
Bram Moolenaar446cb832008-06-24 21:56:24 +00005358 " set up the filename
5359 " (lower case the extension, make a local copy of a remote file)
5360 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5361 if has("win32") || has("win95") || has("win64") || has("win16")
5362 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005363 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005364 if exten =~ "[\\/]"
5365 let exten= ""
5366 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005367" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005368
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005369 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005370 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005371" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005372 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005373 call netrw#NetRead(3,a:fname)
5374 " attempt to rename tempfile
5375 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005376 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005377" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5378" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005379 if s:netrw_tmpfile != newname && newname != ""
5380 if rename(s:netrw_tmpfile,newname) == 0
5381 " renaming succeeded
5382" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5383 let fname= newname
5384 else
5385 " renaming failed
5386" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5387 let fname= s:netrw_tmpfile
5388 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005390 let fname= s:netrw_tmpfile
5391 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005392 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005393" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005394 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005395 " special ~ handler for local
5396 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005397" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5398 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005399 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005400 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005401" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5402" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005403
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005404 " set up redirection (avoids browser messages)
5405 " by default, g:netrw_suppress_gx_mesg is true
5406 if g:netrw_suppress_gx_mesg
5407 if &srr =~ "%s"
5408 if (has("win32") || has("win95") || has("win64") || has("win16"))
5409 let redir= substitute(&srr,"%s","nul","")
5410 else
5411 let redir= substitute(&srr,"%s","/dev/null","")
5412 endif
5413 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5414 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005415 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005416 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005419" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005421 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005423" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424 if g:netrw_browsex_viewer =~ '\s'
5425 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5426 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5427 let oviewer = ''
5428 let cnt = 1
5429 while !executable(viewer) && viewer != oviewer
5430 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5431 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5432 let cnt = cnt + 1
5433 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005434" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005435 endwhile
5436 else
5437 let viewer = g:netrw_browsex_viewer
5438 let viewopt = ""
5439 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005440" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005441 endif
5442
5443 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005444" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005446" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447 let ret= netrwFileHandlers#Invoke(exten,fname)
5448
5449 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005450" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005451 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005452 let ret= v:shell_error
5453
5454 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005455" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005456 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005457 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005458 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005459 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005460 else
5461 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5462 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005463 let ret= v:shell_error
5464
Bram Moolenaar97d62492012-11-15 21:28:22 +01005465 elseif has("win32unix")
5466 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005467" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005468 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005469" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005470 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005471 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005472" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005473 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005474 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005475" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005476 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005477 else
5478 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5479 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005480 let ret= v:shell_error
5481
Bram Moolenaar85850f32019-07-19 22:05:51 +02005482 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005483" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5484 if a:fname =~ '^https\=://'
5485 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5486 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005487" call Decho("fname<".fname.">")
5488" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005489 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5490
5491 else
5492 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5493 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005494 let ret= v:shell_error
5495
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005496 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5497" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5498 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5499 let ret= v:shell_error
5500
5501 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5502" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5503 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5504 let ret= v:shell_error
5505
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005506 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005507" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005508 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005509 let ret= v:shell_error
5510
5511 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005512" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005513 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005514 let ret= v:shell_error
5515
5516 else
5517 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005518" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005519 let ret= netrwFileHandlers#Invoke(exten,fname)
5520 endif
5521
5522 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5523 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005524" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005525 let ret= netrwFileHandlers#Invoke(exten,fname)
5526 endif
5527
Bram Moolenaarc236c162008-07-13 17:41:49 +00005528 " restoring redraw! after external file handlers
5529 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005530
5531 " cleanup: remove temporary file,
5532 " delete current buffer if success with handler,
5533 " return to prior buffer (directory listing)
5534 " Feb 12, 2008: had to de-activiate removal of
5535 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005536" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005537"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005538" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005539" endif
5540
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005541 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005542 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005544 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005545 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005546 if use_ctrlo
5547 exe "sil! NetrwKeepj norm! \<c-o>"
5548 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005550" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005551 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005552 let @@ = ykeep
5553 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005554
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005555" call Dret("netrw#BrowseX")
5556endfun
5557
5558" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005559" netrw#GX: gets word under cursor for gx support {{{2
5560" See also: netrw#BrowseXVis
5561" netrw#BrowseX
5562fun! netrw#GX()
5563" call Dfunc("netrw#GX()")
5564 if &ft == "netrw"
5565 let fname= s:NetrwGetWord()
5566 else
5567 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5568 endif
5569" call Dret("netrw#GX <".fname.">")
5570 return fname
5571endfun
5572
5573" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005574" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5575fun! netrw#BrowseXVis()
5576" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005577 let akeep = @a
5578 norm! gv"ay
5579 let gxfile= @a
5580 let @a = akeep
5581 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005582" call Dret("netrw#BrowseXVis")
5583endfun
5584
5585" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005586" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5587" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5588" to become an unlisted buffer, so in that case don't bwipe it.
5589fun! s:NetrwBufRename(newname)
5590" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5591" call Dredir("ls!","s:NetrwBufRename (before rename)")
5592 let oldbufname= bufname(bufnr("%"))
5593" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5594
5595 if oldbufname != a:newname
5596" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5597 let b:junk= 1
5598" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5599 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005600" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005601 let oldbufnr= bufnr(oldbufname)
5602" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5603" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5604 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5605" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5606 exe "bwipe! ".oldbufnr
5607" else " Decho
5608" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005609" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5610" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5611" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005612 endif
5613" call Dredir("ls!","s:NetrwBufRename (after rename)")
5614" else " Decho
5615" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5616 endif
5617
5618" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5619endfun
5620
5621" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005622" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005623fun! netrw#CheckIfRemote(...)
5624" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5625 if a:0 > 0
5626 let curfile= a:1
5627 else
5628 let curfile= expand("%")
5629 endif
5630" call Decho("curfile<".curfile.">")
5631 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005632" call Dret("netrw#CheckIfRemote 1")
5633 return 1
5634 else
5635" call Dret("netrw#CheckIfRemote 0")
5636 return 0
5637 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005638endfun
5639
5640" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005641" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5642fun! s:NetrwChgPerm(islocal,curdir)
5643" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005644 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005645 call inputsave()
5646 let newperm= input("Enter new permission: ")
5647 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005648 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5649 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5650" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005651 call system(chgperm)
5652 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005653 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654 endif
5655 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005656 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005657 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005658 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005659" call Dret("s:NetrwChgPerm")
5660endfun
5661
5662" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005663" s:CheckIfKde: checks if kdeinit is running {{{2
5664" Returns 0: kdeinit not running
5665" 1: kdeinit is running
5666fun! s:CheckIfKde()
5667" call Dfunc("s:CheckIfKde()")
5668 " seems kde systems often have gnome-open due to dependencies, even though
5669 " gnome-open's subsidiary display tools are largely absent. Kde systems
5670 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5671 if !exists("s:haskdeinit")
5672 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005673 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 if v:shell_error
5675 let s:haskdeinit = 0
5676 endif
5677 else
5678 let s:haskdeinit= 0
5679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005680" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005681 endif
5682
5683" call Dret("s:CheckIfKde ".s:haskdeinit)
5684 return s:haskdeinit
5685endfun
5686
5687" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005688" s:NetrwClearExplore: clear explore variables (if any) {{{2
5689fun! s:NetrwClearExplore()
5690" call Dfunc("s:NetrwClearExplore()")
5691 2match none
5692 if exists("s:explore_match") |unlet s:explore_match |endif
5693 if exists("s:explore_indx") |unlet s:explore_indx |endif
5694 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5695 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5696 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5697 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5698 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5699 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5700 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5701" redraw!
5702 echo " "
5703 echo " "
5704" call Dret("s:NetrwClearExplore")
5705endfun
5706
5707" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005708" s:NetrwExploreListUniq: {{{2
5709fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005710" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005711
5712 " this assumes that the list is already sorted
5713 let newexplist= []
5714 for member in a:explist
5715 if !exists("uniqmember") || member != uniqmember
5716 let uniqmember = member
5717 let newexplist = newexplist + [ member ]
5718 endif
5719 endfor
5720
Bram Moolenaar15146672011-10-20 22:22:38 +02005721" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005722 return newexplist
5723endfun
5724
5725" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005726" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5727fun! s:NetrwForceChgDir(islocal,newdir)
5728" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005729 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005730 if a:newdir !~ '/$'
5731 " ok, looks like force is needed to get directory-style treatment
5732 if a:newdir =~ '@$'
5733 let newdir= substitute(a:newdir,'@$','/','')
5734 elseif a:newdir =~ '[*=|\\]$'
5735 let newdir= substitute(a:newdir,'.$','/','')
5736 else
5737 let newdir= a:newdir.'/'
5738 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005739" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005740 else
5741 " should already be getting treatment as a directory
5742 let newdir= a:newdir
5743 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005744 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005745 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005746 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005747" call Dret("s:NetrwForceChgDir")
5748endfun
5749
5750" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005751" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005752" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5753" expr : this is the expression to follow the directory. Will use s:ComposePath()
5754" pare =1: remove the current directory from the resulting glob() filelist
5755" =0: leave the current directory in the resulting glob() filelist
5756fun! s:NetrwGlob(direntry,expr,pare)
5757" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005758 if netrw#CheckIfRemote()
5759 keepalt 1sp
5760 keepalt enew
5761 let keep_liststyle = w:netrw_liststyle
5762 let w:netrw_liststyle = s:THINLIST
5763 if s:NetrwRemoteListing() == 0
5764 keepj keepalt %s@/@@
5765 let filelist= getline(1,$)
5766 q!
5767 else
5768 " remote listing error -- leave treedict unchanged
5769 let filelist= w:netrw_treedict[a:direntry]
5770 endif
5771 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005772 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5773 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5774 if a:pare
5775 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5776 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005777 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005778 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5779 if a:pare
5780 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5781 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005782 endif
5783" call Dret("s:NetrwGlob ".string(filelist))
5784 return filelist
5785endfun
5786
5787" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005788" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5789fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005790" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005791 if a:newfile =~ '[/@*=|\\]$'
5792 let newfile= substitute(a:newfile,'.$','','')
5793 else
5794 let newfile= a:newfile
5795 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005796 if a:islocal
5797 call s:NetrwBrowseChgDir(a:islocal,newfile)
5798 else
5799 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5800 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005801" call Dret("s:NetrwForceFile")
5802endfun
5803
5804" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005805" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5806" and switches the hiding mode. The actual hiding is done by
5807" s:NetrwListHide().
5808" g:netrw_hide= 0: show all
5809" 1: show not-hidden files
5810" 2: show hidden files only
5811fun! s:NetrwHide(islocal)
5812" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005813 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005814 let svpos= winsaveview()
5815" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005816
5817 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005818" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5819" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005820
5821 " hide the files in the markfile list
5822 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005823" 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 +00005824 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5825 " remove fname from hiding list
5826 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5827 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5828 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005829" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005830 else
5831 " append fname to hiding list
5832 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5833 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5834 else
5835 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005837" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005838 endif
5839 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005840 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005841 let g:netrw_hide= 1
5842
5843 else
5844
5845 " switch between show-all/show-not-hidden/show-hidden
5846 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005847 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005848 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005849 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005850 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005851" call Dret("NetrwHide")
5852 return
5853 endif
5854 endif
5855
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005856 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005857" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5858 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005859 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005860" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005861endfun
5862
5863" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005864" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5865fun! s:NetrwHideEdit(islocal)
5866" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5867
5868 let ykeep= @@
5869 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005870 let svpos= winsaveview()
5871" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005872
5873 " get new hiding list from user
5874 call inputsave()
5875 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5876 call inputrestore()
5877 let g:netrw_list_hide= newhide
5878" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5879
5880 " refresh the listing
5881 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5882
5883 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005884" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5885 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005886 let @@= ykeep
5887
5888" call Dret("NetrwHideEdit")
5889endfun
5890
5891" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005892" s:NetrwHidden: invoked by "gh" {{{2
5893fun! s:NetrwHidden(islocal)
5894" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005895 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005896 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005897 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005898" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005899
5900 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005901 " remove .file pattern from hiding list
5902" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005903 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005904 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005905" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005906 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5907 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005908" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005909 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5910 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005911 if g:netrw_list_hide =~ '^,'
5912 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5913 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005914
5915 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005916 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005917" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5918 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005919 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005920" call Dret("s:NetrwHidden")
5921endfun
5922
5923" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005924" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5925fun! s:NetrwHome()
5926 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005927 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005928 else
5929 " go to vim plugin home
5930 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005931 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005932 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005933 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005934 let home= basehome."/.vim"
5935 break
5936 endif
5937 endfor
5938 if home == ""
5939 " just pick the first directory
5940 let home= substitute(&rtp,',.*$','','')
5941 endif
5942 if (has("win32") || has("win95") || has("win64") || has("win16"))
5943 let home= substitute(home,'/','\\','g')
5944 endif
5945 endif
5946 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005947 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005948" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005949 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005950" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005951 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005952 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005953" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005954 call mkdir(home)
5955 endif
5956 endif
5957 let g:netrw_home= home
5958 return home
5959endfun
5960
5961" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005962" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5963fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005964 if exists("s:netrwdrag")
5965 return
5966 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005967 if &ft != "netrw"
5968 return
5969 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005970" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005971
Bram Moolenaar97d62492012-11-15 21:28:22 +01005972 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005973 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005974 while getchar(0) != 0
5975 "clear the input stream
5976 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005977 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005978 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005979 let mouse_lnum = v:mouse_lnum
5980 let wlastline = line('w$')
5981 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005982" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5983" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005984 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5985 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005986 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005987" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5988 return
5989 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005990 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005991 " 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 +01005992 " without this test when its disabled.
5993 " 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 +01005994" 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 +01005995 if v:mouse_col > virtcol('.')
5996 let @@= ykeep
5997" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5998 return
5999 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006000
Bram Moolenaar446cb832008-06-24 21:56:24 +00006001 if a:islocal
6002 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006003 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006004 endif
6005 else
6006 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006007 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006008 endif
6009 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006010 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006011" call Dret("s:NetrwLeftmouse")
6012endfun
6013
6014" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006015" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6016fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006017 if &ft != "netrw"
6018 return
6019 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006020" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6021 call s:NetrwMarkFileTgt(a:islocal)
6022" call Dret("s:NetrwCLeftmouse")
6023endfun
6024
6025" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006026" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6027" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006028" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006029" a:islocal=2 : <c-r> used, remote
6030" a:islocal=3 : <c-r> used, local
6031fun! s:NetrwServerEdit(islocal,fname)
6032" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6033 let islocal = a:islocal%2 " =0: remote =1: local
6034 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006035" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006036
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006037 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006038 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006039 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006040" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006041 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006042 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006043 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6044 unlet s:netrw_browse_split_{winnr()}
6045 endif
6046 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6047" call Dret("s:NetrwServerEdit")
6048 return
6049 endif
6050
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006051" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006052 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006053" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006054
6055 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006056" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006057 let srvrname = g:netrw_browse_split[0]
6058 let tabnum = g:netrw_browse_split[1]
6059 let winnum = g:netrw_browse_split[2]
6060
6061 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006062" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006063
6064 if !ctrlr
6065 " user must have closed the server window and the user did not use <c-r>, but
6066 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006067" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006068 if exists("g:netrw_browse_split")
6069 unlet g:netrw_browse_split
6070 endif
6071 let g:netrw_browse_split= 0
6072 if exists("s:netrw_browse_split_".winnr())
6073 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6074 endif
6075 call s:NetrwBrowseChgDir(islocal,a:fname)
6076" call Dret("s:NetrwServerEdit")
6077 return
6078
6079 elseif has("win32") && executable("start")
6080 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006081" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006082 call system("start gvim --servername ".srvrname)
6083
6084 else
6085 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006086" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006087 call system("gvim --servername ".srvrname)
6088 endif
6089 endif
6090
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006091" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006092 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6093 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006094 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006095
6096 else
6097
6098 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6099
6100 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006101" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006102 if exists("g:netrw_browse_split")
6103 unlet g:netrw_browse_split
6104 endif
6105 let g:netrw_browse_split= 0
6106 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6107" call Dret("s:NetrwServerEdit")
6108 return
6109
6110 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006111" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006112 if has("win32") && executable("start")
6113 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006114" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006115 call system("start gvim --servername ".g:netrw_servername)
6116 else
6117 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006118" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006119 call system("gvim --servername ".g:netrw_servername)
6120 endif
6121 endif
6122 endif
6123
6124 while 1
6125 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006126" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6127 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006128 break
6129 catch /^Vim\%((\a\+)\)\=:E241/
6130 sleep 200m
6131 endtry
6132 endwhile
6133
6134 if exists("g:netrw_browse_split")
6135 if type(g:netrw_browse_split) != 3
6136 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6137 endif
6138 unlet g:netrw_browse_split
6139 endif
6140 let g:netrw_browse_split= [g:netrw_servername,1,1]
6141 endif
6142
6143 else
6144 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6145 endif
6146
6147" call Dret("s:NetrwServerEdit")
6148endfun
6149
6150" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006151" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6152fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006153 if &ft != "netrw"
6154 return
6155 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006156" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006157
Bram Moolenaar8d043172014-01-23 14:24:41 +01006158 let s:ngw= s:NetrwGetWord()
6159 call s:NetrwMarkFile(a:islocal,s:ngw)
6160
6161" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006162endfun
6163
6164" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006165" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6166" Used to mark multiple files.
6167fun! s:NetrwSLeftdrag(islocal)
6168" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6169 if !exists("s:netrwdrag")
6170 let s:netrwdrag = winnr()
6171 if a:islocal
6172 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006173 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006174 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006175 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006176 endif
6177 let ngw = s:NetrwGetWord()
6178 if !exists("s:ngw") || s:ngw != ngw
6179 call s:NetrwMarkFile(a:islocal,ngw)
6180 endif
6181 let s:ngw= ngw
6182" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6183endfun
6184
6185" ---------------------------------------------------------------------
6186" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6187fun! s:NetrwSLeftrelease(islocal)
6188" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6189 if exists("s:netrwdrag")
6190 nunmap <s-leftrelease>
6191 let ngw = s:NetrwGetWord()
6192 if !exists("s:ngw") || s:ngw != ngw
6193 call s:NetrwMarkFile(a:islocal,ngw)
6194 endif
6195 if exists("s:ngw")
6196 unlet s:ngw
6197 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006198 unlet s:netrwdrag
6199 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006200" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006201endfun
6202
6203" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006204" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6205" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006206fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006207" 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 +02006208" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006209 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006210
6211 " 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 +02006212 " How-it-works: take the hiding command, convert it into a range.
6213 " Duplicate characters don't matter.
6214 " Remove all such characters from the '/~@#...890' string.
6215 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006216" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006217 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006218 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006219" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006220
6221 while listhide != ""
6222 if listhide =~ ','
6223 let hide = substitute(listhide,',.*$','','e')
6224 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6225 else
6226 let hide = listhide
6227 let listhide = ""
6228 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006229" 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 +01006230 if g:netrw_sort_by =~ '^[ts]'
6231 if hide =~ '^\^'
6232" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6233 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6234 elseif hide =~ '^\\(\^'
6235 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6236 endif
6237" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6238 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006239
6240 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006241" 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 +00006242 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006243" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006244 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006245 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006246" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006247 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006248 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006249" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006250 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006251
Bram Moolenaar446cb832008-06-24 21:56:24 +00006252 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006253 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006254" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006255 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006256" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006257 endif
6258
Bram Moolenaaradc21822011-04-01 18:03:16 +02006259 " remove any blank lines that have somehow remained.
6260 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006261 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006262
Bram Moolenaar97d62492012-11-15 21:28:22 +01006263 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006264" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006265endfun
6266
6267" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006268" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006269" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006270fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006271" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006272
Bram Moolenaar97d62492012-11-15 21:28:22 +01006273 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274 " get name of new directory from user. A bare <CR> will skip.
6275 " if its currently a directory, also request will be skipped, but with
6276 " a message.
6277 call inputsave()
6278 let newdirname= input("Please give directory name: ")
6279 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006280" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006281
6282 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006283 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006284" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006285 return
6286 endif
6287
6288 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006289" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006290
6291 " Local mkdir:
6292 " sanity checks
6293 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006294" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6295 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006296 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006297 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006298 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006299 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006300" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006301 return
6302 endif
6303 if s:FileReadable(fullnewdir)
6304 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006305 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006306 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006307 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006308" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309 return
6310 endif
6311
6312 " requested new local directory is neither a pre-existing file or
6313 " directory, so make it!
6314 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006315 if has("unix")
6316 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6317 else
6318 call mkdir(fullnewdir,"p")
6319 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006320 else
6321 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006322 if s:NetrwLcd(b:netrw_curdir)
6323" call Dret("s:NetrwMakeDir : lcd failure")
6324 return
6325 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006326" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006327 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006328 if v:shell_error != 0
6329 let @@= ykeep
6330 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 +01006331" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006332 return
6333 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006334 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006335" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006336 if s:NetrwLcd(netrw_origdir)
6337" call Dret("s:NetrwBrowse : lcd failure")
6338 return
6339 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006340 endif
6341 endif
6342
6343 if v:shell_error == 0
6344 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006345" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006346 let svpos= winsaveview()
6347" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006348 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006349" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6350 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006351 elseif !exists("g:netrw_quiet")
6352 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6353 endif
6354" redraw!
6355
6356 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006357 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006358" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006359 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6360 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006361 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006362 if v:shell_error == 0
6363 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006364 let svpos= winsaveview()
6365" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006366 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006367" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6368 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006369 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006370 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006371 endif
6372" redraw!
6373
6374 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006375 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006376 let svpos= winsaveview()
6377" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006378" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006379 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006380" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006381 let remotepath= b:netrw_fname
6382 else
6383 let remotepath= ""
6384 endif
6385 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006386 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006387" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6388 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006389
Bram Moolenaar446cb832008-06-24 21:56:24 +00006390 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006391 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006392 let svpos= winsaveview()
6393" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006394" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006395 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006396" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006397 let remotepath= b:netrw_fname
6398 else
6399 let remotepath= ""
6400 endif
6401 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006402 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006403" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6404 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006405 endif
6406
Bram Moolenaar97d62492012-11-15 21:28:22 +01006407 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006408" call Dret("s:NetrwMakeDir")
6409endfun
6410
6411" ---------------------------------------------------------------------
6412" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6413fun! s:TreeSqueezeDir(islocal)
6414" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6415 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6416 " its a tree-listing style
6417 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006418 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006419 let depth = strchars(substitute(curdepth,' ','','g'))
6420 let srch = -1
6421" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6422" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006423" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006424" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6425 if depth >= 2
6426 NetrwKeepj norm! 0
6427 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6428 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6429" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6430" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6431 elseif depth == 1
6432 NetrwKeepj norm! 0
6433 let treedepthchr= substitute(s:treedepthstring,' ','','')
6434 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6435" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6436 endif
6437 if srch > 0
6438" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6439 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6440 exe srch
6441 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006442 endif
6443" call Dret("s:TreeSqueezeDir")
6444endfun
6445
6446" ---------------------------------------------------------------------
6447" s:NetrwMaps: {{{2
6448fun! s:NetrwMaps(islocal)
6449" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6450
Bram Moolenaar85850f32019-07-19 22:05:51 +02006451 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006452 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006453" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006454 if !hasmapto("<Plug>NetrwReturn")
6455 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006456" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006457 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6458 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006459" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006460 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6461 endif
6462 endif
6463 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006464" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006465 endif
6466
Bram Moolenaar85850f32019-07-19 22:05:51 +02006467 " generate default <Plug> maps {{{3
6468 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006469 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006470 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6471 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6472 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6473 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6474 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6475 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6476 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6477 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6478 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6479 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6480" ---------------------------------------------------------------------
6481" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6482" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6483" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6484" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6485" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6486" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6487" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6488" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6489" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6490" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6491" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6492" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6493" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6494" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6495" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6496" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6497" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6498" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6499" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6500" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6501" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6502" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6503" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6504" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6505" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6506" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6507" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6508" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6509" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6510" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6511" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6512" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6513" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6514" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6515" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6516" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6517" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6518" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6519" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6520" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6521" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6522" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6523" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6524" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6525" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6526" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6527" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6528
Bram Moolenaara6878372014-03-22 21:02:50 +01006529 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006530" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006531 " local normal-mode maps {{{3
6532 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6533 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6534 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6535 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6536 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6537 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6538 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6539 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6540 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6541 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6542 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6543" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006544 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6545 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6546 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006547 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006548 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006549 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6550 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6551 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6552 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006553 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6554 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6555 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6556 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6557 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6558 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6559 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6560 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6561 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6562 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6563 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6564 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6565 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006566 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006567 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006568 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6569 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6570 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6571 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6572 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006573 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006574 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006575 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6576 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006577 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6578 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6579 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006580 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006581 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006582 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6583 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006584 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006585 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006586 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6587 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6588 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006589 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6590 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006591
6592 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 +01006593 if !hasmapto('<Plug>NetrwHideEdit')
6594 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006595 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006596 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006597 if !hasmapto('<Plug>NetrwRefresh')
6598 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006599 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006600 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 +01006601 if s:didstarstar || !mapcheck("<s-down>","n")
6602 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006603 endif
6604 if s:didstarstar || !mapcheck("<s-up>","n")
6605 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006606 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006607 if !hasmapto('<Plug>NetrwTreeSqueeze')
6608 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006609 endif
6610 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006611 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6612 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006613 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6614 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6615 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6616 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6617 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6618 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6619 imap <buffer> <leftmouse> <Plug>ILeftmouse
6620 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006621 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006622 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006623 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006624 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006625 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006626 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006627 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6628 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006629 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006630 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6631 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6632 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6633 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6634 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6635 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6636 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006637 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6638
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006639 " support user-specified maps
6640 call netrw#UserMaps(1)
6641
Bram Moolenaar85850f32019-07-19 22:05:51 +02006642 else
6643 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006644" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006645 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006646 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6647 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6648 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6649 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6650 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6651 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6652 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6653 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6654 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6655 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6656 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6657" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006658 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6659 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6660 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6661 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6662 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6663 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6664 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6665 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006666 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006667 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006668 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6669 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6670 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6671 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6672 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6673 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6674 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6675 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6676 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6677 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6678 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006679 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006680 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006681 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6682 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6683 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6684 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6685 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006686 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6687 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6688 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6689 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006690 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006691 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6692 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006693 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006694 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 +01006695 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6696 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6697 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6698 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6699 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6700 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6701 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6702 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6703 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006704 if !hasmapto('<Plug>NetrwHideEdit')
6705 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006706 endif
6707 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6708 if !hasmapto('<Plug>NetrwRefresh')
6709 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006710 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006711 if !hasmapto('<Plug>NetrwTreeSqueeze')
6712 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006713 endif
6714 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006715
6716 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006717 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006718
6719 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6720 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006721 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6722 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6723 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6724 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6725 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6726 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6727 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6728 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6729 nmap <middlemouse> <Plug>NetrwMiddlemouse
6730 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6731 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6732 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6733 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006734 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006735 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006736 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6737 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006738 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006739 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6740 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6741 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6742 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6743 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6744 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6745 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006746 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006747
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748 " support user-specified maps
6749 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006750 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006751
6752" call Dret("s:NetrwMaps")
6753endfun
6754
6755" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006756" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006757" If -buffer, the command is only available from within netrw buffers
6758" Otherwise, the command is available from any window, so long as netrw
6759" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006760fun! s:NetrwCommands(islocal)
6761" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6762
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006763 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6764 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006765 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 +01006766 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006767 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006768 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006769 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006770 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006771 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006772
6773" call Dret("s:NetrwCommands")
6774endfun
6775
6776" ---------------------------------------------------------------------
6777" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6778" glob()ing only works with local files
6779fun! s:NetrwMarkFiles(islocal,...)
6780" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006781 let curdir = s:NetrwGetCurdir(a:islocal)
6782 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006783 while i <= a:0
6784 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006785 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006786 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006787 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006788 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006789 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006790 else
6791 let mffiles= [a:{i}]
6792 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006793" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006794 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006795" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006796 call s:NetrwMarkFile(a:islocal,mffile)
6797 endfor
6798 let i= i + 1
6799 endwhile
6800" call Dret("s:NetrwMarkFiles")
6801endfun
6802
6803" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006804" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006805fun! s:NetrwMarkTarget(...)
6806" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6807 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006808 let curdir = s:NetrwGetCurdir(1)
6809 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006810 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006811 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6812 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006813 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006814" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006815 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006816 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6817 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006818 let svpos = winsaveview()
6819" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006820 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006821" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6822 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006823" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006824endfun
6825
6826" ---------------------------------------------------------------------
6827" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6828" mark and unmark files. If a markfile list exists,
6829" then the rename and delete functions will use it instead
6830" of whatever may happen to be under the cursor at that
6831" moment. When the mouse and gui are available,
6832" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006833"
6834" Creates two lists
6835" s:netrwmarkfilelist -- holds complete paths to all marked files
6836" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6837"
6838" Creates a marked file match string
6839" s:netrwmarfilemtch_# -- used with 2match to display marked files
6840"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006841" Creates a buffer version of islocal
6842" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006843fun! s:NetrwMarkFile(islocal,fname)
6844" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006846
6847 " sanity check
6848 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006849" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006850 return
6851 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006852 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006853
Bram Moolenaar97d62492012-11-15 21:28:22 +01006854 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006856 if a:fname =~ '^\a'
6857 let leader= '\<'
6858 else
6859 let leader= ''
6860 endif
6861 if a:fname =~ '\a$'
6862 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6863 else
6864 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6865 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006866
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006867 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006868 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006869" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6870" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6871" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006872 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006873
6874 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006875 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006876" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006878 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006879
6880 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006881 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006882" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006883 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6884 if s:netrwmarkfilelist_{curbufnr} == []
6885 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006886" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006887 call s:NetrwUnmarkList(curbufnr,curdir)
6888 else
6889 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006890" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006891 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006892 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006893 for fname in s:netrwmarkfilelist_{curbufnr}
6894 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006895 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006896 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006897 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006898 endif
6899 let first= 0
6900 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006901" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902 endif
6903 endif
6904
6905 else
6906 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006907" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006909" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6912" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006913
6914 " build initial markfile matching pattern
6915 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006916 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006917 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006918 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006919 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 endif
6922
6923 " handle global markfilelist
6924 if exists("s:netrwmarkfilelist")
6925 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6926 if index(s:netrwmarkfilelist,dname) == -1
6927 " append new filename to global markfilelist
6928 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006929" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 else
6931 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006932" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6933" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006934 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006935" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006936 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006937" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 unlet s:netrwmarkfilelist
6939 endif
6940 endif
6941 else
6942 " initialize new global-directory markfilelist
6943 let s:netrwmarkfilelist= []
6944 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006945" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946 endif
6947
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006948 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006949 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6950 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6951" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6952 if exists("g:did_drchip_netrwlist_syntax")
6953 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6954 endif
6955 else
6956" " call Decho("2match none",'~'.expand("<slnum>"))
6957 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006958 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006959 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006960 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006961" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6962" 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 +00006963endfun
6964
6965" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006966" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6967" mA: move the argument list to marked file list (tomflist=1)
6968" Uses the global marked file list
6969fun! s:NetrwMarkFileArgList(islocal,tomflist)
6970" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6971
6972 let svpos = winsaveview()
6973" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6974 let curdir = s:NetrwGetCurdir(a:islocal)
6975 let curbufnr = bufnr("%")
6976
6977 if a:tomflist
6978 " mA: move argument list to marked file list
6979 while argc()
6980 let fname= argv(0)
6981" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6982 exe "argdel ".fnameescape(fname)
6983 call s:NetrwMarkFile(a:islocal,fname)
6984 endwhile
6985
6986 else
6987 " ma: move marked file list to argument list
6988 if exists("s:netrwmarkfilelist")
6989
6990 " for every filename in the marked list
6991 for fname in s:netrwmarkfilelist
6992" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6993 exe "argadd ".fnameescape(fname)
6994 endfor " for every file in the marked list
6995
6996 " unmark list and refresh
6997 call s:NetrwUnmarkList(curbufnr,curdir)
6998 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6999" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7000 NetrwKeepj call winrestview(svpos)
7001 endif
7002 endif
7003
7004" call Dret("s:NetrwMarkFileArgList")
7005endfun
7006
7007" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007008" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7009" compress/decompress files using the programs
7010" in g:netrw_compress and g:netrw_uncompress,
7011" using g:netrw_compress_suffix to know which to
7012" do. By default:
7013" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007014" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007015fun! s:NetrwMarkFileCompress(islocal)
7016" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007017 let svpos = winsaveview()
7018" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007019 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007020 let curbufnr = bufnr("%")
7021
Bram Moolenaarff034192013-04-24 18:51:19 +02007022 " sanity check
7023 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007024 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007025" call Dret("s:NetrwMarkFileCompress")
7026 return
7027 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007028" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007029
Bram Moolenaar446cb832008-06-24 21:56:24 +00007030 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007031
7032 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007033 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007034 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007035" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007036 if exists("g:netrw_decompress['".sfx."']")
7037 " fname has a suffix indicating that its compressed; apply associated decompression routine
7038 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007039" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007040 let exe= netrw#WinPath(exe)
7041 if a:islocal
7042 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007043 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007044 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007045 call system(exe." ".fname)
7046 if v:shell_error
7047 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007048 endif
7049 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007050 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7051 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007052 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007053
Bram Moolenaarff034192013-04-24 18:51:19 +02007054 endif
7055 unlet sfx
7056
Bram Moolenaar446cb832008-06-24 21:56:24 +00007057 if exists("exe")
7058 unlet exe
7059 elseif a:islocal
7060 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007061 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007062 if v:shell_error
7063 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7064 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007065 else
7066 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007067 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007068 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007069 endfor " for every file in the marked list
7070
Bram Moolenaar446cb832008-06-24 21:56:24 +00007071 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007072 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007073" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7074 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075 endif
7076" call Dret("s:NetrwMarkFileCompress")
7077endfun
7078
7079" ---------------------------------------------------------------------
7080" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7081" If no marked files, then set up directory as the
7082" target. Currently does not support copying entire
7083" directories. Uses the local-buffer marked file list.
7084" Returns 1=success (used by NetrwMarkFileMove())
7085" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007086fun! s:NetrwMarkFileCopy(islocal,...)
7087" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7088
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007089 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007090 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007091 if b:netrw_curdir !~ '/$'
7092 if !exists("b:netrw_curdir")
7093 let b:netrw_curdir= curdir
7094 endif
7095 let b:netrw_curdir= b:netrw_curdir."/"
7096 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007097
Bram Moolenaarff034192013-04-24 18:51:19 +02007098 " sanity check
7099 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007100 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007101" call Dret("s:NetrwMarkFileCopy")
7102 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007104" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007105
Bram Moolenaar446cb832008-06-24 21:56:24 +00007106 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007107 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007108" call Dret("s:NetrwMarkFileCopy 0")
7109 return 0
7110 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007111" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007112
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007113 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007114 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007115" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007116 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007117 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7118" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7119 return
7120 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007121
7122 " copy marked files while within the same directory (ie. allow renaming)
7123 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7124 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7125 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007126" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007127 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007128 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7129 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007130" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007131 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007132 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007133 let oldname = a:1
7134 else
7135 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007136" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007137 let s:recursive= 1
7138 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7139 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7140 if ret == 0
7141 break
7142 endif
7143 endfor
7144 unlet s:recursive
7145 call s:NetrwUnmarkList(curbufnr,curdir)
7146" call Dret("s:NetrwMarkFileCopy ".ret)
7147 return ret
7148 endif
7149
7150 call inputsave()
7151 let newname= input("Copy ".oldname." to : ",oldname,"file")
7152 call inputrestore()
7153 if newname == ""
7154" call Dret("s:NetrwMarkFileCopy 0")
7155 return 0
7156 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007157 let args= s:ShellEscape(oldname)
7158 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007159 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007160 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7161 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007162 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007163 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7164 let args= substitute(args,'/','\\','g')
7165 let tgt = substitute(tgt, '/','\\','g')
7166 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007167 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7168 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7169 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7170 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7171" call Decho("args <".args.">",'~'.expand("<slnum>"))
7172" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007173 if isdirectory(s:NetrwFile(args))
7174" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007175 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007176" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007177 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7178 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7179 " contents to a target. One must append the source directory name to the target to get xcopy to
7180 " do the right thing.
7181 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007182" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007183 endif
7184 else
7185 let copycmd= g:netrw_localcopycmd
7186 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007187 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007188 let copycmd = substitute(copycmd,'\s.*$','','')
7189 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007190 let copycmd = netrw#WinPath(copycmd).copycmdargs
7191 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007192 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007193 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007194" call Decho("args <".args.">",'~'.expand("<slnum>"))
7195" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7196" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7197" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007198 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007199 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007200 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007201 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 +01007202 else
7203 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7204 endif
7205" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007206 return 0
7207 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007208
7209 elseif a:islocal && !s:netrwmftgt_islocal
7210 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007211" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007212 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007213
7214 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007215 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007217 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007218
7219 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007220 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007221" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007222 let curdir = getcwd()
7223 let tmpdir = s:GetTempfile("")
7224 if tmpdir !~ '/'
7225 let tmpdir= curdir."/".tmpdir
7226 endif
7227 if exists("*mkdir")
7228 call mkdir(tmpdir)
7229 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007230 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007231 if v:shell_error != 0
7232 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 +01007233" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007234 return
7235 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007236 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007237 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007238 if s:NetrwLcd(tmpdir)
7239" call Dret("s:NetrwMarkFileCopy : lcd failure")
7240 return
7241 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007242 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007243 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007244 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007245 if getcwd() == tmpdir
7246 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007247 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007248 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007249 if s:NetrwLcd(curdir)
7250" call Dret("s:NetrwMarkFileCopy : lcd failure")
7251 return
7252 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007253 if delete(tmpdir,"d")
7254 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007255 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007256 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007257 if s:NetrwLcd(curdir)
7258" call Dret("s:NetrwMarkFileCopy : lcd failure")
7259 return
7260 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007261 endif
7262 endif
7263 endif
7264
7265 " -------
7266 " cleanup
7267 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007268" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007269 " remove markings from local buffer
7270 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007271" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7272" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7273" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7274" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7275" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7276" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7277 if exists("s:recursive")
7278" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7279 else
7280" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007281 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007282 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007283 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007284 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007285 else
7286 " refresh local and targets for fast browsing
7287 if !exists("s:recursive")
7288 " remove markings from local buffer
7289" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7290 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7291 endif
7292
7293 " refresh buffers
7294 if s:netrwmftgt_islocal
7295" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7296 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7297 endif
7298 if a:islocal && s:netrwmftgt != curdir
7299" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7300 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7301 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007302 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007303
Bram Moolenaar446cb832008-06-24 21:56:24 +00007304" call Dret("s:NetrwMarkFileCopy 1")
7305 return 1
7306endfun
7307
7308" ---------------------------------------------------------------------
7309" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7310" invoke vim's diff mode on the marked files.
7311" Either two or three files can be so handled.
7312" Uses the global marked file list.
7313fun! s:NetrwMarkFileDiff(islocal)
7314" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7315 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007316
Bram Moolenaarff034192013-04-24 18:51:19 +02007317 " sanity check
7318 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007319 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007320" call Dret("s:NetrwMarkFileDiff")
7321 return
7322 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007323 let curdir= s:NetrwGetCurdir(a:islocal)
7324" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007325
Bram Moolenaara6878372014-03-22 21:02:50 +01007326 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007327 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007328 for fname in s:netrwmarkfilelist
7329 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007330 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007331" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007332 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007333 diffthis
7334 elseif cnt == 2 || cnt == 3
7335 vsplit
7336 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007337" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007338 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007339 diffthis
7340 else
7341 break
7342 endif
7343 endfor
7344 call s:NetrwUnmarkList(curbufnr,curdir)
7345 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007346
Bram Moolenaar446cb832008-06-24 21:56:24 +00007347" call Dret("s:NetrwMarkFileDiff")
7348endfun
7349
7350" ---------------------------------------------------------------------
7351" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7352" Uses global markfilelist
7353fun! s:NetrwMarkFileEdit(islocal)
7354" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7355
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007356 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007357 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007358
7359 " sanity check
7360 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007361 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007362" call Dret("s:NetrwMarkFileEdit")
7363 return
7364 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007365" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007366
Bram Moolenaar446cb832008-06-24 21:56:24 +00007367 if exists("s:netrwmarkfilelist_{curbufnr}")
7368 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007369 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007370 " unmark markedfile list
7371" call s:NetrwUnmarkList(curbufnr,curdir)
7372 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007373" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007374 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007375 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007376 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007377
Bram Moolenaar446cb832008-06-24 21:56:24 +00007378" call Dret("s:NetrwMarkFileEdit")
7379endfun
7380
7381" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007382" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007383fun! s:NetrwMarkFileQFEL(islocal,qfel)
7384" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7385 call s:NetrwUnmarkAll()
7386 let curbufnr= bufnr("%")
7387
7388 if !empty(a:qfel)
7389 for entry in a:qfel
7390 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007391" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007392 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007393" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007394 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7395 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7396 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7397 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007398" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007399 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7400 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007401" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007402 endif
7403 endfor
7404 echo "(use me to edit marked files)"
7405 else
7406 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7407 endif
7408
7409" call Dret("s:NetrwMarkFileQFEL")
7410endfun
7411
7412" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007413" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7414" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7415" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7416fun! s:NetrwMarkFileExe(islocal,enbloc)
7417" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007418 let svpos = winsaveview()
7419" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007420 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007421 let curbufnr = bufnr("%")
7422
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007423 if a:enbloc == 0
7424 " individually apply command to files, one at a time
7425 " sanity check
7426 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7427 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7428" call Dret("s:NetrwMarkFileExe")
7429 return
7430 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007431" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007432
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007433 if exists("s:netrwmarkfilelist_{curbufnr}")
7434 " get the command
7435 call inputsave()
7436 let cmd= input("Enter command: ","","file")
7437 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007438" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007439 if cmd == ""
7440" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7441 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007442 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007443
7444 " apply command to marked files, individually. Substitute: filename -> %
7445 " If no %, then append a space and the filename to the command
7446 for fname in s:netrwmarkfilelist_{curbufnr}
7447 if a:islocal
7448 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007449 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007450 endif
7451 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007452 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007453 endif
7454 if cmd =~ '%'
7455 let xcmd= substitute(cmd,'%',fname,'g')
7456 else
7457 let xcmd= cmd.' '.fname
7458 endif
7459 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007460" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007461 let ret= system(xcmd)
7462 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007463" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007464 let ret= s:RemoteSystem(xcmd)
7465 endif
7466 if v:shell_error < 0
7467 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7468 break
7469 else
7470 echo ret
7471 endif
7472 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007473
7474 " unmark marked file list
7475 call s:NetrwUnmarkList(curbufnr,curdir)
7476
7477 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007478 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007479" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7480 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007481 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007483 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007484
7485 else " apply command to global list of files, en bloc
7486
7487 call inputsave()
7488 let cmd= input("Enter command: ","","file")
7489 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007490" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007491 if cmd == ""
7492" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7493 return
7494 endif
7495 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007498 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007499 endif
7500 if a:islocal
7501 call system(cmd)
7502 if v:shell_error < 0
7503 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7504 endif
7505 else
7506 let ret= s:RemoteSystem(cmd)
7507 endif
7508 call s:NetrwUnmarkAll()
7509
7510 " refresh the listing
7511 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007512" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7513 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007514
7515 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007516
Bram Moolenaar446cb832008-06-24 21:56:24 +00007517" call Dret("s:NetrwMarkFileExe")
7518endfun
7519
7520" ---------------------------------------------------------------------
7521" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7522" as the marked file(s) (toggles suffix presence)
7523" Uses the local marked file list.
7524fun! s:NetrwMarkHideSfx(islocal)
7525" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007526 let svpos = winsaveview()
7527" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007528 let curbufnr = bufnr("%")
7529
7530 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7531 if exists("s:netrwmarkfilelist_{curbufnr}")
7532
7533 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007534" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007535 " construct suffix pattern
7536 if fname =~ '\.'
7537 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7538 else
7539 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7540 endif
7541 " determine if its in the hiding list or not
7542 let inhidelist= 0
7543 if g:netrw_list_hide != ""
7544 let itemnum = 0
7545 let hidelist= split(g:netrw_list_hide,',')
7546 for hidepat in hidelist
7547 if sfxpat == hidepat
7548 let inhidelist= 1
7549 break
7550 endif
7551 let itemnum= itemnum + 1
7552 endfor
7553 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007554" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007555 if inhidelist
7556 " remove sfxpat from list
7557 call remove(hidelist,itemnum)
7558 let g:netrw_list_hide= join(hidelist,",")
7559 elseif g:netrw_list_hide != ""
7560 " append sfxpat to non-empty list
7561 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7562 else
7563 " set hiding list to sfxpat
7564 let g:netrw_list_hide= sfxpat
7565 endif
7566 endfor
7567
7568 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007569 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007570" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7571 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007572 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007573 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007574 endif
7575
7576" call Dret("s:NetrwMarkHideSfx")
7577endfun
7578
7579" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007580" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007581" Uses the local marked-file list.
7582fun! s:NetrwMarkFileVimCmd(islocal)
7583" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007584 let svpos = winsaveview()
7585" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007586 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007587 let curbufnr = bufnr("%")
7588
Bram Moolenaarff034192013-04-24 18:51:19 +02007589 " sanity check
7590 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007591 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007592" call Dret("s:NetrwMarkFileVimCmd")
7593 return
7594 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007595" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007596
Bram Moolenaar15146672011-10-20 22:22:38 +02007597 if exists("s:netrwmarkfilelist_{curbufnr}")
7598 " get the command
7599 call inputsave()
7600 let cmd= input("Enter vim command: ","","file")
7601 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007602" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007603 if cmd == ""
7604" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7605 return
7606 endif
7607
7608 " apply command to marked files. Substitute: filename -> %
7609 " If no %, then append a space and the filename to the command
7610 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007611" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007612 if a:islocal
7613 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007614 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007615" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007616 exe cmd
7617 exe "sil! keepalt wq!"
7618 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007620 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007621 endif
7622 endfor
7623
7624 " unmark marked file list
7625 call s:NetrwUnmarkList(curbufnr,curdir)
7626
7627 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007628 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007629" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7630 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007631 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007632 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007634
Bram Moolenaar15146672011-10-20 22:22:38 +02007635" call Dret("s:NetrwMarkFileVimCmd")
7636endfun
7637
7638" ---------------------------------------------------------------------
7639" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7640" as the marked file(s) (toggles suffix presence)
7641" Uses the local marked file list.
7642fun! s:NetrwMarkHideSfx(islocal)
7643" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007644 let svpos = winsaveview()
7645" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007646 let curbufnr = bufnr("%")
7647
7648 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7649 if exists("s:netrwmarkfilelist_{curbufnr}")
7650
7651 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007653 " construct suffix pattern
7654 if fname =~ '\.'
7655 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7656 else
7657 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7658 endif
7659 " determine if its in the hiding list or not
7660 let inhidelist= 0
7661 if g:netrw_list_hide != ""
7662 let itemnum = 0
7663 let hidelist= split(g:netrw_list_hide,',')
7664 for hidepat in hidelist
7665 if sfxpat == hidepat
7666 let inhidelist= 1
7667 break
7668 endif
7669 let itemnum= itemnum + 1
7670 endfor
7671 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007672" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007673 if inhidelist
7674 " remove sfxpat from list
7675 call remove(hidelist,itemnum)
7676 let g:netrw_list_hide= join(hidelist,",")
7677 elseif g:netrw_list_hide != ""
7678 " append sfxpat to non-empty list
7679 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7680 else
7681 " set hiding list to sfxpat
7682 let g:netrw_list_hide= sfxpat
7683 endif
7684 endfor
7685
7686 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007687 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007688" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7689 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007690 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007691 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007692 endif
7693
7694" call Dret("s:NetrwMarkHideSfx")
7695endfun
7696
7697" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007698" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7699" Uses the global markfilelist
7700fun! s:NetrwMarkFileGrep(islocal)
7701" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007702 let svpos = winsaveview()
7703" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007704 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007705 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007706
7707 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007708" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007709 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007710" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007711 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007712 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007713" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007714 let netrwmarkfilelist= "*"
7715 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007716
Bram Moolenaarff034192013-04-24 18:51:19 +02007717 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007718" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007719 call inputsave()
7720 let pat= input("Enter pattern: ","")
7721 call inputrestore()
7722 let patbang = ""
7723 if pat =~ '^!'
7724 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007725 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007726 endif
7727 if pat =~ '^\i'
7728 let pat = escape(pat,'/')
7729 let pat = '/'.pat.'/'
7730 else
7731 let nonisi = pat[0]
7732 endif
7733
7734 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007735" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007736 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007737 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007738 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007739 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007740" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7741 return
7742 endtry
7743 echo "(use :cn, :cp to navigate, :Rex to return)"
7744
7745 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007746" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7747 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007748
7749 if exists("nonisi")
7750 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007751" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007752 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007753 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007754 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007755 endif
7756
7757" call Dret("s:NetrwMarkFileGrep")
7758endfun
7759
7760" ---------------------------------------------------------------------
7761" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7762" uses the global marked file list
7763" s:netrwmfloc= 0: target directory is remote
7764" = 1: target directory is local
7765fun! s:NetrwMarkFileMove(islocal)
7766" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007767 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007768 let curbufnr = bufnr("%")
7769
7770 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007771 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007772 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007773" call Dret("s:NetrwMarkFileMove")
7774 return
7775 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007776" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007777
Bram Moolenaar446cb832008-06-24 21:56:24 +00007778 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007779 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007780" call Dret("s:NetrwMarkFileCopy 0")
7781 return 0
7782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007783" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784
7785 if a:islocal && s:netrwmftgt_islocal
7786 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007787" call Decho("move from local to local",'~'.expand("<slnum>"))
7788" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007789 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007790 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7791" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7792 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007793 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007794 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007795" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007796 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007797 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007798" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007799 if g:netrw_localmovecmd =~ '\s'
7800 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7801 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7802 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007803" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007804 else
7805 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007806" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007807 endif
7808 else
7809 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007810" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007811 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007812 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007813 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7814 let fname= substitute(fname,'/','\\','g')
7815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007816" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007817 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007818 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007819 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007820 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 +01007821 else
7822 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7823 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007824 break
7825 endif
7826 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007827
7828 elseif a:islocal && !s:netrwmftgt_islocal
7829 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007830" call Decho("move from local to remote",'~'.expand("<slnum>"))
7831" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007832 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007833 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007834" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007835 for fname in mflist
7836 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7837 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7838 endfor
7839 unlet mflist
7840
7841 elseif !a:islocal && s:netrwmftgt_islocal
7842 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843" call Decho("move from remote to local",'~'.expand("<slnum>"))
7844" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007845 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007846 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007847" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007848 for fname in mflist
7849 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7850 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7851 endfor
7852 unlet mflist
7853
7854 elseif !a:islocal && !s:netrwmftgt_islocal
7855 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7857" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007858 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007859 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007861 for fname in mflist
7862 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7863 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7864 endfor
7865 unlet mflist
7866 endif
7867
7868 " -------
7869 " cleanup
7870 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007871" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007872
7873 " remove markings from local buffer
7874 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7875
7876 " refresh buffers
7877 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007878" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007879 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880 endif
7881 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007882" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007883 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007884 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007885 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007886" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007887 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007889
Bram Moolenaar446cb832008-06-24 21:56:24 +00007890" call Dret("s:NetrwMarkFileMove")
7891endfun
7892
7893" ---------------------------------------------------------------------
7894" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7895" using the hardcopy command. Local marked-file list only.
7896fun! s:NetrwMarkFilePrint(islocal)
7897" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7898 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007899
7900 " sanity check
7901 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007902 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007903" call Dret("s:NetrwMarkFilePrint")
7904 return
7905 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007906" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7907 let curdir= s:NetrwGetCurdir(a:islocal)
7908
Bram Moolenaar446cb832008-06-24 21:56:24 +00007909 if exists("s:netrwmarkfilelist_{curbufnr}")
7910 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007911 call s:NetrwUnmarkList(curbufnr,curdir)
7912 for fname in netrwmarkfilelist
7913 if a:islocal
7914 if g:netrw_keepdir
7915 let fname= s:ComposePath(curdir,fname)
7916 endif
7917 else
7918 let fname= curdir.fname
7919 endif
7920 1split
7921 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007922" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007923 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007924" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007925 hardcopy
7926 q
7927 endfor
7928 2match none
7929 endif
7930" call Dret("s:NetrwMarkFilePrint")
7931endfun
7932
7933" ---------------------------------------------------------------------
7934" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7935" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007936" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007937fun! s:NetrwMarkFileRegexp(islocal)
7938" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7939
7940 " get the regular expression
7941 call inputsave()
7942 let regexp= input("Enter regexp: ","","file")
7943 call inputrestore()
7944
7945 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007946 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007947" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007949" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007950 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007951 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007952 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007953 else
7954 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007955 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007956 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007957" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007958
7959 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007960 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007961 if fname =~ '^'.fnameescape(curdir)
7962" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7963 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7964 else
7965" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7966 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7967 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007968 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007969
7970 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007971" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007972
7973 " convert displayed listing into a filelist
7974 let eikeep = &ei
7975 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007976 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007977 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007978" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007979 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007980 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007981 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007982 sil NetrwKeepj norm! "ap
7983 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007984 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007985 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007986 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007987 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007988 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007989 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007990 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007991 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007992 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007993 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007994 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7995 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007996 call histdel("/",-1)
7997 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007998 endif
7999 " convert regexp into the more usual glob-style format
8000 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008001" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008002 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008003 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008004 let filelist= getline(1,line("$"))
8005 q!
8006 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008007 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008008 endfor
8009 unlet filelist
8010 let @a = areg
8011 let &ei = eikeep
8012 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008013 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008014
8015" call Dret("s:NetrwMarkFileRegexp")
8016endfun
8017
8018" ---------------------------------------------------------------------
8019" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8020" Uses the local marked file list.
8021fun! s:NetrwMarkFileSource(islocal)
8022" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8023 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008024
8025 " sanity check
8026 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008027 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008028" call Dret("s:NetrwMarkFileSource")
8029 return
8030 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008031" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8032 let curdir= s:NetrwGetCurdir(a:islocal)
8033
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 if exists("s:netrwmarkfilelist_{curbufnr}")
8035 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008036 call s:NetrwUnmarkList(curbufnr,curdir)
8037 for fname in netrwmarkfilelist
8038 if a:islocal
8039 if g:netrw_keepdir
8040 let fname= s:ComposePath(curdir,fname)
8041 endif
8042 else
8043 let fname= curdir.fname
8044 endif
8045 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008046" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008047 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 endfor
8049 2match none
8050 endif
8051" call Dret("s:NetrwMarkFileSource")
8052endfun
8053
8054" ---------------------------------------------------------------------
8055" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8056" Uses the global markfilelist
8057fun! s:NetrwMarkFileTag(islocal)
8058" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008059 let svpos = winsaveview()
8060" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008061 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008062 let curbufnr = bufnr("%")
8063
Bram Moolenaarff034192013-04-24 18:51:19 +02008064 " sanity check
8065 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008066 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008067" call Dret("s:NetrwMarkFileTag")
8068 return
8069 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008070" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008071
Bram Moolenaar446cb832008-06-24 21:56:24 +00008072 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008073" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8074 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008075 call s:NetrwUnmarkAll()
8076
8077 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008078
8079" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8080 call system(g:netrw_ctags." ".netrwmarkfilelist)
8081 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008082 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8083 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008084
Bram Moolenaar446cb832008-06-24 21:56:24 +00008085 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008086 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008087 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008088 let curdir= b:netrw_curdir
8089 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008090 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008091 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008092" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008093 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008094 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008095 wq!
8096 endif
8097 2match none
8098 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008099" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8100 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008101 endif
8102
8103" call Dret("s:NetrwMarkFileTag")
8104endfun
8105
8106" ---------------------------------------------------------------------
8107" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008108" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008109" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008110" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008111" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008113" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8114 let svpos = winsaveview()
8115" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008116 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008117 let hadtgt = exists("s:netrwmftgt")
8118 if !exists("w:netrw_bannercnt")
8119 let w:netrw_bannercnt= b:netrw_bannercnt
8120 endif
8121
8122 " set up target
8123 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008124" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008125 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8126 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008127" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008128 unlet s:netrwmftgt s:netrwmftgt_islocal
8129 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008130 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008131 endif
8132 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008133" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8134 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008135" call Dret("s:NetrwMarkFileTgt : removed target")
8136 return
8137 else
8138 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008139" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008140 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008141
8142 else
8143 " get word under cursor.
8144 " * If directory, use it for the target.
8145 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008146" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008147 let curword= s:NetrwGetWord()
8148 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008149 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008150 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008151" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008152 elseif !a:islocal && tgtdir =~ '/$'
8153 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008154" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008155 else
8156 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008157" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158 endif
8159 endif
8160 if a:islocal
8161 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8162 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008163" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008164 endif
8165 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008166 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008167 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8168 endif
8169 let s:netrwmftgt_islocal= a:islocal
8170
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008171 " need to do refresh so that the banner will be updated
8172 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008173 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008174" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008175 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008176 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008177" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008178 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008179 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8180 else
8181 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8182 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008183" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8184 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008185 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008186 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008187 endif
8188
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008189" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8190" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008191" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8192endfun
8193
8194" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008195" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8196fun! s:NetrwGetCurdir(islocal)
8197" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8198
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008199 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008200 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8201" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8202 elseif !exists("b:netrw_curdir")
8203 let b:netrw_curdir= getcwd()
8204" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8205 endif
8206
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008207" 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 +01008208 if b:netrw_curdir !~ '\<\a\{3,}://'
8209 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008210" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008211 if g:netrw_keepdir == 0
8212 call s:NetrwLcd(curdir)
8213 endif
8214 endif
8215
8216" call Dret("s:NetrwGetCurdir <".curdir.">")
8217 return b:netrw_curdir
8218endfun
8219
8220" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008221" s:NetrwOpenFile: query user for a filename and open it {{{2
8222fun! s:NetrwOpenFile(islocal)
8223" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008224 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008225 call inputsave()
8226 let fname= input("Enter filename: ")
8227 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008228" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8229
8230 " determine if Lexplore is in use
8231 if exists("t:netrw_lexbufnr")
8232 " check if t:netrw_lexbufnr refers to a netrw window
8233" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8234 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8235 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8236" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8237 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8238 exe "NetrwKeepj e ".fnameescape(fname)
8239 let @@= ykeep
8240" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8241 endif
8242 endif
8243
8244 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008245 if fname !~ '[/\\]'
8246 if exists("b:netrw_curdir")
8247 if exists("g:netrw_quiet")
8248 let netrw_quiet_keep = g:netrw_quiet
8249 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008250 let g:netrw_quiet = 1
8251 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008252 let s:rexposn_{bufnr("%")}= winsaveview()
8253" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008254 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008255 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008256 else
8257 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8258 endif
8259 if exists("netrw_quiet_keep")
8260 let g:netrw_quiet= netrw_quiet_keep
8261 else
8262 unlet g:netrw_quiet
8263 endif
8264 endif
8265 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008266 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008267 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008268 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008269" call Dret("s:NetrwOpenFile")
8270endfun
8271
8272" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008273" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8274" For the mapping to this function be made via
8275" netrwPlugin, you'll need to have had
8276" g:netrw_usetab set to non-zero.
8277fun! netrw#Shrink()
8278" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8279 let curwin = winnr()
8280 let wiwkeep = &wiw
8281 set wiw=1
8282
8283 if &ft == "netrw"
8284 if winwidth(0) > g:netrw_wiw
8285 let t:netrw_winwidth= winwidth(0)
8286 exe "vert resize ".g:netrw_wiw
8287 wincmd l
8288 if winnr() == curwin
8289 wincmd h
8290 endif
8291" call Decho("vert resize 0",'~'.expand("<slnum>"))
8292 else
8293 exe "vert resize ".t:netrw_winwidth
8294" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8295 endif
8296
8297 elseif exists("t:netrw_lexbufnr")
8298 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8299 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8300 let t:netrw_winwidth= winwidth(0)
8301 exe "vert resize ".g:netrw_wiw
8302 wincmd l
8303 if winnr() == curwin
8304 wincmd h
8305 endif
8306" call Decho("vert resize 0",'~'.expand("<slnum>"))
8307 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8308 exe "vert resize ".t:netrw_winwidth
8309" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8310 else
8311 call netrw#Lexplore(0,0)
8312 endif
8313
8314 else
8315 call netrw#Lexplore(0,0)
8316 endif
8317 let wiw= wiwkeep
8318
8319" call Dret("netrw#Shrink")
8320endfun
8321
8322" ---------------------------------------------------------------------
8323" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8324fun! s:NetSortSequence(islocal)
8325" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8326
8327 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008328 let svpos= winsaveview()
8329" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008330 call inputsave()
8331 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8332 call inputrestore()
8333
8334 " refresh the listing
8335 let g:netrw_sort_sequence= newsortseq
8336 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008337" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8338 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008339 let @@= ykeep
8340
8341" call Dret("NetSortSequence")
8342endfun
8343
8344" ---------------------------------------------------------------------
8345" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8346" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008347" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008348fun! s:NetrwUnmarkList(curbufnr,curdir)
8349" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8350
8351 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008352 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008353 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8354 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8355 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8356 call remove(s:netrwmarkfilelist,idx) " remove from global list
8357 endfor
8358 if s:netrwmarkfilelist == []
8359 unlet s:netrwmarkfilelist
8360 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008361
Bram Moolenaar446cb832008-06-24 21:56:24 +00008362 " getting rid of the local marked-file lists is easy
8363 unlet s:netrwmarkfilelist_{a:curbufnr}
8364 endif
8365 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8366 unlet s:netrwmarkfilemtch_{a:curbufnr}
8367 endif
8368 2match none
8369" call Dret("s:NetrwUnmarkList")
8370endfun
8371
8372" ---------------------------------------------------------------------
8373" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8374fun! s:NetrwUnmarkAll()
8375" call Dfunc("s:NetrwUnmarkAll()")
8376 if exists("s:netrwmarkfilelist")
8377 unlet s:netrwmarkfilelist
8378 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008379 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008380 2match none
8381" call Dret("s:NetrwUnmarkAll")
8382endfun
8383
8384" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008385" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008386fun! s:NetrwUnmarkAll2()
8387" call Dfunc("s:NetrwUnmarkAll2()")
8388 redir => netrwmarkfilelist_let
8389 let
8390 redir END
8391 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008392 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008393 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8394 for flist in netrwmarkfilelist_list
8395 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8396 unlet s:netrwmarkfilelist_{curbufnr}
8397 unlet s:netrwmarkfilemtch_{curbufnr}
8398 endfor
8399" call Dret("s:NetrwUnmarkAll2")
8400endfun
8401
8402" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008403" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8404"
8405" Marked files are in two types of lists:
8406" s:netrwmarkfilelist -- holds complete paths to all marked files
8407" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8408"
8409" Marked files suitable for use with 2match are in:
8410" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008411fun! s:NetrwUnMarkFile(islocal)
8412" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008413 let svpos = winsaveview()
8414" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008415 let curbufnr = bufnr("%")
8416
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008417 " unmark marked file list
8418 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8419 if exists("s:netrwmarkfilelist")
8420" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008422 endif
8423
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008424 let ibuf= 1
8425 while ibuf < bufnr("$")
8426 if exists("s:netrwmarkfilelist_".ibuf)
8427 unlet s:netrwmarkfilelist_{ibuf}
8428 unlet s:netrwmarkfilemtch_{ibuf}
8429 endif
8430 let ibuf = ibuf + 1
8431 endwhile
8432 2match none
8433
Bram Moolenaar446cb832008-06-24 21:56:24 +00008434" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008435"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8436call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008437" call Dret("s:NetrwUnMarkFile")
8438endfun
8439
8440" ---------------------------------------------------------------------
8441" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8442fun! s:NetrwMenu(domenu)
8443
8444 if !exists("g:NetrwMenuPriority")
8445 let g:NetrwMenuPriority= 80
8446 endif
8447
Bram Moolenaaradc21822011-04-01 18:03:16 +02008448 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8450
8451 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008452" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008454 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8455 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8456 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8457 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8458 if g:netrw_dirhistmax > 0
8459 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8460 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8461 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8462 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8463 else
8464 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8465 endif
8466 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8467 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8468 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8469 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8470 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8471 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8472 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8473 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8474 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8475 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8476 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8477 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8478 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8479 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8480 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 +01008481 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 +02008482 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8483 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8484 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8485 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8486 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8488 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8511 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>'
8512 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>'
8513 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>'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8515 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>'
8516 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>'
8517 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 +01008518 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 +02008519 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008521 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008522 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8523 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008524
8525 elseif !a:domenu
8526 let s:netrwcnt = 0
8527 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008528 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008529 exe curwin."wincmd w"
8530
8531 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008532" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008533 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008534" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008535 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008536 endif
8537 endif
8538" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008539 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008540 endif
8541
8542endfun
8543
8544" ---------------------------------------------------------------------
8545" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8546" Used by the O maps (as <SID>NetrwObtain())
8547fun! s:NetrwObtain(islocal)
8548" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8549
Bram Moolenaar97d62492012-11-15 21:28:22 +01008550 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008551 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008552 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008553 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008554 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8555 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008556 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008557 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008558 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008559
8560" call Dret("NetrwObtain")
8561endfun
8562
8563" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008564" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8565" If there's only one window, then the window will first be split.
8566" Returns:
8567" choice = 0 : didn't have to choose
8568" choice = 1 : saved modified file in window first
8569" choice = 2 : didn't save modified file, opened window
8570" choice = 3 : cancel open
8571fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008572" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573
Bram Moolenaar97d62492012-11-15 21:28:22 +01008574 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008575 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008576 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577
8578 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008579 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008580 let lastwinnr = winnr("$")
8581 let curword = s:NetrwGetWord()
8582 let choice = 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008583 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008584 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008585 let curdir = s:treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008586" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587
Bram Moolenaar8d043172014-01-23 14:24:41 +01008588 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008589 if lastwinnr == 1
8590 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008591" 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 +02008592 " g:netrw_preview=0: preview window shown in a horizontally split window
8593 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008595 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008596 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008597" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008598 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008600 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008601 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008602" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008603 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008604 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008605 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008606" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607
8608 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008609 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008610 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008611 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612 wincmd p
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008613" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008614
8615 " prevwinnr: the window number of the "prev" window
8616 " prevbufnr: the buffer number of the buffer in the "prev" window
8617 " bnrcnt : the qty of windows open on the "prev" buffer
8618 let prevwinnr = winnr()
8619 let prevbufnr = bufnr("%")
8620 let prevbufname = bufname("%")
8621 let prevmod = &mod
8622 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008623 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008624" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008625
8626 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008627 " and it doesn't appear in any other extant window, then ask the
8628 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008629 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008630" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008631 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008632" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008633 exe prevwinnr."wincmd w"
8634
8635 if bnrcnt == 1 && &hidden == 0
8636 " only one copy of the modified buffer in a window, and
8637 " hidden not set, so overwriting will lose the modified file. Ask first...
8638 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008639" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008640 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008641
8642 if choice == 1
8643 " Yes -- write file & then browse
8644 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008645 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008646 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008647 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008648 exe origwin."wincmd w"
8649 let &ei = eikeep
8650 let @@ = ykeep
8651" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008652 return choice
8653 endif
8654
8655 elseif choice == 2
8656 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008657" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008658 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008659
8660 else
8661 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008662" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008663 exe origwin."wincmd w"
8664 let &ei= eikeep
8665 let @@ = ykeep
8666" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008667 return choice
8668 endif
8669 endif
8670 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008671 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008672 endif
8673
8674 " restore b:netrw_curdir (window split/enew may have lost it)
8675 let b:netrw_curdir= curdir
8676 if a:islocal < 2
8677 if a:islocal
8678 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8679 else
8680 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8681 endif
8682 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008683 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008684" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008685 return choice
8686endfun
8687
8688" ---------------------------------------------------------------------
8689" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8690" Always assumed to be local -> remote
8691" call s:NetrwUpload(filename, target)
8692" call s:NetrwUpload(filename, target, fromdirectory)
8693fun! s:NetrwUpload(fname,tgt,...)
8694" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8695
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008696 if a:tgt =~ '^\a\{3,}://'
8697 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008698 else
8699 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008701" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008702
8703 if a:0 > 0
8704 let fromdir= a:1
8705 else
8706 let fromdir= getcwd()
8707 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008708" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709
8710 if type(a:fname) == 1
8711 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008712" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008713 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008714" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8715 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8716" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008717 if a:tgt =~ '/$'
8718 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008719" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008720 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008721 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008722" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008723 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008724" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725 endif
8726 q!
8727
8728 elseif type(a:fname) == 3
8729 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008730" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008731 let curdir= getcwd()
8732 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008733 if s:NetrwLcd(fromdir)
8734" call Dret("s:NetrwUpload : lcd failure")
8735 return
8736 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008737 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008738 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008739 if exists("g:netrw_port") && g:netrw_port != ""
8740 let useport= " ".g:netrw_scpport." ".g:netrw_port
8741 else
8742 let useport= ""
8743 endif
8744 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8745 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008746 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 +02008747 if s:NetrwLcd(curdir)
8748" call Dret("s:NetrwUpload : lcd failure")
8749 return
8750 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008751
8752 elseif a:tgt =~ '^ftp:'
8753 call s:NetrwMethod(a:tgt)
8754
8755 if b:netrw_method == 2
8756 " handle uploading a list of files via ftp+.netrc
8757 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008758 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008759" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008760
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008761 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008762" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008763
8764 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008765 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008766" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008767 endif
8768
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008769 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008770" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008771
Bram Moolenaaradc21822011-04-01 18:03:16 +02008772 if tgtdir == ""
8773 let tgtdir= '/'
8774 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008775 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777
8778 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008779 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8780" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781 endfor
8782
8783 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008784 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 +00008785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008786" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8787 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008788 endif
8789 " 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 +01008790 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008791 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8793 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8794 else
8795 bw!|q
8796 endif
8797
8798 elseif b:netrw_method == 3
8799 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8800 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008801 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008803 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008804
8805 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008806 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008809 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008811 endif
8812
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008813 if exists("g:netrw_uid") && g:netrw_uid != ""
8814 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008815 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008816" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008817 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008818 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008820" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008821 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008825 endif
8826
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008827 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008828" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008829
8830 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008831 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008832" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008833 endif
8834
8835 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008836 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008837" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838 endif
8839
8840 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008841 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008842" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843 endfor
8844
8845 " perform ftp:
8846 " -i : turns off interactive prompting from ftp
8847 " -n unix : DON'T use <.netrc>, even though it exists
8848 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008849 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008850 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008851 " 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 +01008852 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008853 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8855 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008856 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008857 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8858 let &debug = debugkeep
8859 let mod = 1
8860 else
8861 bw!|q
8862 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008863 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008864" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008865 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 endif
8867 else
8868 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8869 endif
8870 endif
8871
8872" call Dret("s:NetrwUpload")
8873endfun
8874
8875" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008876" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008877fun! s:NetrwPreview(path) range
8878" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008879" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8880" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008881 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008882 NetrwKeepj call s:NetrwOptionsSave("s:")
8883 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8884 NetrwKeepj call s:NetrwOptionsSafe(1)
8885 else
8886 NetrwKeepj call s:NetrwOptionsSafe(0)
8887 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008888 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008889" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008890 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008891" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8892 if g:netrw_preview
8893 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008894 let pvhkeep = &pvh
8895 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8896 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008897" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8898 else
8899 " horizontal split
8900 let pvhkeep = &pvh
8901 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8902 let &pvh = winheight(0) - winsz
8903" 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 +02008904 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008905 " g:netrw_preview g:netrw_alto
8906 " 1 : vert 1: top -- preview window is vertically split off and on the left
8907 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8908 " 0 : 1: top -- preview window is horizontally split off and on the top
8909 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8910 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008911 " 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 +02008912 " the BufEnter event set up in netrwPlugin.vim
8913" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8914 let eikeep = &ei
8915 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008916 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008917 let &ei= eikeep
8918" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008919 if exists("pvhkeep")
8920 let &pvh= pvhkeep
8921 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008923 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008924 endif
8925 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008926 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 +00008927 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008928 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008929 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930" call Dret("NetrwPreview")
8931endfun
8932
8933" ---------------------------------------------------------------------
8934" s:NetrwRefresh: {{{2
8935fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008936" 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 +00008937 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008938 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008939" call Decho("setl ma noro",'~'.expand("<slnum>"))
8940" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008941 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008942 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8943 if !exists("w:netrw_treetop")
8944 if exists("b:netrw_curdir")
8945 let w:netrw_treetop= b:netrw_curdir
8946 else
8947 let w:netrw_treetop= getcwd()
8948 endif
8949 endif
8950 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8951 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008952
8953 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008954 let screenposn = winsaveview()
8955" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008956
8957" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8958" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8959 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008961 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008963 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008964 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008965
8966 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008967" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8968 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008969
8970 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008971 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8972 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8973" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8974 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8975 else
8976" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8977 2match none
8978 endif
8979 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008980
Bram Moolenaar97d62492012-11-15 21:28:22 +01008981" restore
8982 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008983" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008984endfun
8985
8986" ---------------------------------------------------------------------
8987" s:NetrwRefreshDir: refreshes a directory by name {{{2
8988" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008989" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008990fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008991" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008992 if g:netrw_fastbrowse == 0
8993 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008994" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008995 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008996" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008997
8998 if tgtwin > 0
8999 " tgtwin is being displayed, so refresh it
9000 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009001" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009002 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009003 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009004 exe curwin."wincmd w"
9005
9006 elseif bufnr(a:dirname) > 0
9007 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009008" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9009 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009010 endif
9011
9012 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009013" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009014 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009015 endif
9016" call Dret("s:NetrwRefreshDir")
9017endfun
9018
9019" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009020" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9021" window number to do its editing in.
9022" Supports [count]C where the count, if present, is used to specify
9023" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009024fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009025" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009026 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009027" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009028 if a:1 == "" " :NetrwC win#
9029 let g:netrw_chgwin= winnr()
9030 else " :NetrwC
9031 let g:netrw_chgwin= a:1
9032 endif
9033 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009034 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009035 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009036 let g:netrw_chgwin= winnr()
9037 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009038 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009039" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009040endfun
9041
9042" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009043" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9044" What this function does is to compute a priority for the patterns
9045" in the g:netrw_sort_sequence. It applies a substitute to any
9046" "files" that satisfy each pattern, putting the priority / in
9047" front. An "*" pattern handles the default priority.
9048fun! s:NetrwSetSort()
9049" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009050 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051 if w:netrw_liststyle == s:LONGLIST
9052 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9053 else
9054 let seqlist = g:netrw_sort_sequence
9055 endif
9056 " sanity check -- insure that * appears somewhere
9057 if seqlist == ""
9058 let seqlist= '*'
9059 elseif seqlist !~ '\*'
9060 let seqlist= seqlist.',*'
9061 endif
9062 let priority = 1
9063 while seqlist != ""
9064 if seqlist =~ ','
9065 let seq = substitute(seqlist,',.*$','','e')
9066 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9067 else
9068 let seq = seqlist
9069 let seqlist = ""
9070 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009072 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009073 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009074 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009076 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009078" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079
9080 " sanity check
9081 if w:netrw_bannercnt > line("$")
9082 " apparently no files were left after a Hiding pattern was used
9083" call Dret("SetSort : no files left after hiding")
9084 return
9085 endif
9086 if seq == '*'
9087 let starpriority= spriority
9088 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009089 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009090 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009091 " sometimes multiple sorting patterns will match the same file or directory.
9092 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009093 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9094 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009095 endif
9096 let priority = priority + 1
9097 endwhile
9098 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009099 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9100 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101 endif
9102
9103 " Following line associated with priority -- items that satisfy a priority
9104 " pattern get prefixed by ###/ which permits easy sorting by priority.
9105 " Sometimes files can satisfy multiple priority patterns -- only the latest
9106 " priority pattern needs to be retained. So, at this point, these excess
9107 " priority prefixes need to be removed, but not directories that happen to
9108 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009109 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9110 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009111 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112
9113" call Dret("SetSort")
9114endfun
9115
Bram Moolenaarff034192013-04-24 18:51:19 +02009116" ---------------------------------------------------------------------
9117" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9118" Implements [count]Tb (bookhist<b>)
9119" [count]Th (bookhist<h>)
9120" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009121fun! s:NetrwSetTgt(islocal,bookhist,choice)
9122" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009123
9124 if a:bookhist == 'b'
9125 " supports choosing a bookmark as a target using a qb-generated list
9126 let choice= a:choice - 1
9127 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009128 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009129 else
9130 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9131 endif
9132
9133 elseif a:bookhist == 'h'
9134 " supports choosing a history stack entry as a target using a qb-generated list
9135 let choice= (a:choice % g:netrw_dirhistmax) + 1
9136 if exists("g:netrw_dirhist_".choice)
9137 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009138 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009139 else
9140 echomsg "Sorry, history#".a:choice." not available!"
9141 endif
9142 endif
9143
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009144 " refresh the display
9145 if !exists("b:netrw_curdir")
9146 let b:netrw_curdir= getcwd()
9147 endif
9148 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9149
Bram Moolenaarff034192013-04-24 18:51:19 +02009150" call Dret("s:NetrwSetTgt")
9151endfun
9152
Bram Moolenaar446cb832008-06-24 21:56:24 +00009153" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009154" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009155fun! s:NetrwSortStyle(islocal)
9156" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009157 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009158 let svpos= winsaveview()
9159" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009160
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009161 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 +01009162 NetrwKeepj norm! 0
9163 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009164" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9165 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009166
9167" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9168endfun
9169
9170" ---------------------------------------------------------------------
9171" s:NetrwSplit: mode {{{2
9172" =0 : net and o
9173" =1 : net and t
9174" =2 : net and v
9175" =3 : local and o
9176" =4 : local and t
9177" =5 : local and v
9178fun! s:NetrwSplit(mode)
9179" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9180
Bram Moolenaar97d62492012-11-15 21:28:22 +01009181 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009182 call s:SaveWinVars()
9183
9184 if a:mode == 0
9185 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009186 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009187 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009188" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009189 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009190 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009191 NetrwKeepj call s:RestoreWinVars()
9192 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009193 unlet s:didsplit
9194
9195 elseif a:mode == 1
9196 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009197 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009198" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009199 tabnew
9200 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009201 NetrwKeepj call s:RestoreWinVars()
9202 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203 unlet s:didsplit
9204
9205 elseif a:mode == 2
9206 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009207 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009208 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009209" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009210 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009212 NetrwKeepj call s:RestoreWinVars()
9213 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009214 unlet s:didsplit
9215
9216 elseif a:mode == 3
9217 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009218 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009219 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009220" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009221 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009222 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009223 NetrwKeepj call s:RestoreWinVars()
9224 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009225 unlet s:didsplit
9226
9227 elseif a:mode == 4
9228 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009230 let eikeep = &ei
9231 let netrw_winnr = winnr()
9232 let netrw_line = line(".")
9233 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009234 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009235 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009236 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009237 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9238 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009239 let &ei = eikeep
9240 let netrw_curdir = s:NetrwTreeDir(0)
9241" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009242 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009243 let b:netrw_curdir = netrw_curdir
9244 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009245 NetrwKeepj call s:RestoreWinVars()
9246 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009247 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009248 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009249 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9250 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009251 let &ei= eikeep
9252 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253 unlet s:didsplit
9254
9255 elseif a:mode == 5
9256 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009257 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009258 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009260 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009261 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009262 NetrwKeepj call s:RestoreWinVars()
9263 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 unlet s:didsplit
9265
9266 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009267 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009268 endif
9269
Bram Moolenaar97d62492012-11-15 21:28:22 +01009270 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009271" call Dret("s:NetrwSplit")
9272endfun
9273
9274" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009275" s:NetrwTgtMenu: {{{2
9276fun! s:NetrwTgtMenu()
9277 if !exists("s:netrw_menucnt")
9278 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009279 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009280" call Dfunc("s:NetrwTgtMenu()")
9281
9282 " the following test assures that gvim is running, has menus available, and has menus enabled.
9283 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9284 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009285" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009286 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9287 endif
9288 if !exists("s:netrw_initbookhist")
9289 call s:NetrwBookHistRead()
9290 endif
9291
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009292 " try to cull duplicate entries
9293 let tgtdict={}
9294
Bram Moolenaarff034192013-04-24 18:51:19 +02009295 " target bookmarked places
9296 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009297" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009298 let cnt= 1
9299 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300 if has_key(tgtdict,bmd)
9301 let cnt= cnt + 1
9302 continue
9303 endif
9304 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009305 let ebmd= escape(bmd,g:netrw_menu_escape)
9306 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009307" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009308 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 +02009309 let cnt= cnt + 1
9310 endfor
9311 endif
9312
9313 " target directory browsing history
9314 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009315" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009316 let histcnt = 1
9317 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009318 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009319 if exists("g:netrw_dirhist_{histcnt}")
9320 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009321 if has_key(tgtdict,histentry)
9322 let histcnt = histcnt + 1
9323 continue
9324 endif
9325 let tgtdict[histentry] = histcnt
9326 let ehistentry = escape(histentry,g:netrw_menu_escape)
9327" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009328 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 +02009329 endif
9330 let histcnt = histcnt + 1
9331 endwhile
9332 endif
9333 endif
9334" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009335endfun
9336
9337" ---------------------------------------------------------------------
9338" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9339" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009340fun! s:NetrwTreeDir(islocal)
9341" 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 +02009342" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009343" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9344" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9345" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009346" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009347
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009348 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009349 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009350" 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 +01009351 let treedir= s:treedir
9352 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009353 unlet s:prevwinopen
9354" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009355 return treedir
9356 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009357 if exists("s:prevwinopen")
9358 unlet s:prevwinopen
9359 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360
Bram Moolenaar8d043172014-01-23 14:24:41 +01009361 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9362 let b:netrw_curdir= getcwd()
9363 endif
9364 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009365" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009366
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009367 let s:treecurpos= winsaveview()
9368" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9369
9370 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009371" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9372" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009373
9374 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009375 let curline= substitute(getline('.'),"\t -->.*$",'','')
9376 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009377" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009378 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009379" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9380 elseif curline =~ '@$'
9381" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9382 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9383" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009384 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009386 let treedir= ""
9387 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009388
9389 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009390" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9391" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009392" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009393 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009395 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009396" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9397 sil! NetrwKeepj %d _
9398" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009400" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009401" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009402 endif
9403
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009404" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009405 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9406" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009407
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009408 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9409" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9410" let newdir = w:netrw_treetop.'/'.potentialdir
9411" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9412" let treedir = s:NetrwTreePath(newdir)
9413" let w:netrw_treetop = newdir
9414" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9415" else
9416" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009417 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009418" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009419 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009420
9421 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009422 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009423" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009424
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009426 return treedir
9427endfun
9428
9429" ---------------------------------------------------------------------
9430" s:NetrwTreeDisplay: recursive tree display {{{2
9431fun! s:NetrwTreeDisplay(dir,depth)
9432" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9433
9434 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009435 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009436
9437 " install ../ and shortdir
9438 if a:depth == ""
9439 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009440" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009441 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009442 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009443 if a:dir == w:netrw_treetop
9444 let shortdir= a:dir
9445 else
9446 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9447 endif
9448 call setline(line("$")+1,a:depth.shortdir)
9449 else
9450 let shortdir= substitute(a:dir,'^.*/','','e')
9451 call setline(line("$")+1,a:depth.shortdir.'/')
9452 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009454 " append a / to dir if its missing one
9455 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009456
9457 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009458 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009459" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009460
Bram Moolenaar85850f32019-07-19 22:05:51 +02009461 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9462 if g:netrw_hide == 1
9463 " hide given patterns
9464 let listhide= split(g:netrw_list_hide,',')
9465" call Decho("listhide=".string(listhide))
9466 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009467 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009468 endfor
9469
9470 elseif g:netrw_hide == 2
9471 " show given patterns (only)
9472 let listhide= split(g:netrw_list_hide,',')
9473" call Decho("listhide=".string(listhide))
9474 let entries=[]
9475 for entry in w:netrw_treedict[dir]
9476 for pat in listhide
9477 if entry =~ pat
9478 call add(entries,entry)
9479 break
9480 endif
9481 endfor
9482 endfor
9483 let w:netrw_treedict[dir]= entries
9484 endif
9485 if depth != ""
9486 " always remove "." and ".." entries when there's depth
9487 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9488 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9489 endif
9490
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009491" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009492 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009493 if dir =~ '/$'
9494 let direntry= substitute(dir.entry,'[@/]$','','e')
9495 else
9496 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9497 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009498" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009499 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009500" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009501 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009502 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009503" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9504 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9505 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9506" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009507 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009508 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009509" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009510 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009511 endif
9512 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009513" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009514
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515" call Dret("NetrwTreeDisplay")
9516endfun
9517
9518" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009519" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9520fun! s:NetrwRefreshTreeDict(dir)
9521" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009522 if !exists("w:netrw_treedict")
9523" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9524 return
9525 endif
9526
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009527 for entry in w:netrw_treedict[a:dir]
9528 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9529" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9530
9531 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9532" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9533 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009534 let liststar = s:NetrwGlob(direntry,'*',1)
9535 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009536 let w:netrw_treedict[direntry] = liststar + listdotstar
9537" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9538
9539 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9540" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9541 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009542 let liststar = s:NetrwGlob(direntry.'/','*',1)
9543 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009544 let w:netrw_treedict[direntry]= liststar + listdotstar
9545" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9546
9547 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9548" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9549 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009550 let liststar = s:NetrwGlob(direntry.'/','*',1)
9551 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009552" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9553
9554 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009555" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009556 endif
9557 endfor
9558" call Dret("s:NetrwRefreshTreeDict")
9559endfun
9560
9561" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009562" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009563" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009564fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009565 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009566" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009567" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9568" 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>"))
9569" 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 +00009570
9571 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009572 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009573" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009574 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009575 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009577 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 +02009578" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009579 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009580 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009581" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009582 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009583 if exists("w:netrw_treetop")
9584 let s:netrw_treetop= w:netrw_treetop
9585 else
9586 let w:netrw_treetop= getcwd()
9587 let s:netrw_treetop= w:netrw_treetop
9588 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009589
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009591 " insure that we have a treedict, albeit empty
9592" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009593 let w:netrw_treedict= {}
9594 endif
9595
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009596 " update the dictionary for the current directory
9597" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009598" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009599 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009600 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009601" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009602 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009603
9604 " if past banner, record word
9605 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9606 let fname= expand("<cword>")
9607 else
9608 let fname= ""
9609 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009610" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9611" 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 +00009612
9613 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009614" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009615 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009616" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009617
9618 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9619 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009620" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009621 1d
9622 endwhile
9623
Bram Moolenaar13600302014-05-22 18:26:40 +02009624 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009625
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009626" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009627 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009628 endif
9629endfun
9630
9631" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009632" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009633" Normally, treetop is w:netrw_treetop, but a
9634" user of the function ( netrw#SetTreetop() )
9635" wipes that out prior to calling this function
9636fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009637" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9638 if line(".") < w:netrw_bannercnt + 2
9639 let treedir= a:treetop
9640 if treedir !~ '/$'
9641 let treedir= treedir.'/'
9642 endif
9643" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9644 return treedir
9645 endif
9646
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009647 let svpos = winsaveview()
9648" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009649 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009650" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009651 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009652" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9653 let curline= getline('.')
9654" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9655 if curline =~ '/$'
9656" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9657 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9658" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9659 elseif curline =~ '@\s\+-->'
9660" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9661 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9662 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9663" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009664 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009665" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009666 let treedir= ""
9667 endif
9668 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009669" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9670" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009671 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9672 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9673 let treedir= dirname.treedir
9674 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009675" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009676 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009677" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009678 if a:treetop =~ '/$'
9679 let treedir= a:treetop.treedir
9680 else
9681 let treedir= a:treetop.'/'.treedir
9682 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009683" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009684 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009685" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009686" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9687 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009688" call Dret("s:NetrwTreePath <".treedir.">")
9689 return treedir
9690endfun
9691
9692" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693" s:NetrwWideListing: {{{2
9694fun! s:NetrwWideListing()
9695
9696 if w:netrw_liststyle == s:WIDELIST
9697" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9698 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009699 " cpf: characters per filename
9700 " fpl: filenames per line
9701 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009702 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009703 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009704" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009705 let b:netrw_cpf= 0
9706 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009707 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009708 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9709 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009710 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009711 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009712" call Dret("NetrwWideListing")
9713 return
9714 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009715 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009716 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009717" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009718
9719 " determine qty files per line (fpl)
9720 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9721 if w:netrw_fpl <= 0
9722 let w:netrw_fpl= 1
9723 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009724" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009725
9726 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009727 " fpc: files per column of wide listing
9728 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009729 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009730 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9731 let newcolstart = w:netrw_bannercnt + fpc
9732 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009733" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009734 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009735" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009736 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009737 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009738 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009739 while line("$") >= newcolstart
9740 if newcolend > line("$") | let newcolend= line("$") | endif
9741 let newcolqty= newcolend - newcolstart
9742 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009743 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009744 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009745 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009746 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009747 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009748 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009749 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009750 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009751 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009752 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009753" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009754 if @* != keepregstar | sil! let @* = keepregstar | endif
9755 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009756 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009757 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9758 NetrwKeepj call histdel("/",-1)
9759 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9760 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009761" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009762 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009763 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009764" 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 +00009765" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009766 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009767 else
9768 if hasmapto("w","n")
9769 sil! nunmap <buffer> w
9770 endif
9771 if hasmapto("b","n")
9772 sil! nunmap <buffer> b
9773 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009774 endif
9775
9776endfun
9777
9778" ---------------------------------------------------------------------
9779" s:PerformListing: {{{2
9780fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009781" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9782" 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 +02009783" 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>"))
9784 sil! NetrwKeepj %d _
9785" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009786
Bram Moolenaar15146672011-10-20 22:22:38 +02009787 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009788" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009789 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009790
Bram Moolenaar85850f32019-07-19 22:05:51 +02009791 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009792 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009793" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009794
9795" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009796" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009797" endif " Decho
9798
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009799" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009800 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9801 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009802" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9803 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804 endif
9805
9806 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009807 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808
9809 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009810 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009811" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009812 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009813 if exists("g:netrw_pchk")
9814 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9815 " failure detections.
9816 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009817 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009818 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9819 endif
9820 if exists("g:netrw_pchk")
9821 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9822 else
9823 let curdir= b:netrw_curdir
9824 endif
9825 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9826 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9827 else
9828 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009829 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009830 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009831 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009832 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009833" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009834 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009835 let w:netrw_bannercnt= 1
9836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009837" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9838" 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 +00009839
Bram Moolenaar85850f32019-07-19 22:05:51 +02009840 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009841 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009842 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009843 let sortby= sortby." reversed"
9844 endif
9845
9846 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009847 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009848" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009849 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009850" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009851 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009852 NetrwKeepj put ='\" Sorted by '.sortby
9853 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009854 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9855 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009856" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009857 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009858 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009859 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9860 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009861 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009862" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009863" 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 +00009864 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009865
Bram Moolenaar85850f32019-07-19 22:05:51 +02009866 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009867 if g:netrw_banner
9868 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009869" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009870 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009871 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009872 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009873 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009874 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009875 endif
9876 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009877 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009880 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009881 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009882
9883 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009884 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009885" 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 +01009886 if g:netrw_list_hide != "" && g:netrw_hide
9887 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009888 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009889 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009890 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009891 endif
9892 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009893 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009895
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009896" 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 +01009897 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009898" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009899 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" 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 +01009901 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009902 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009903" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904" 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 +00009905 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009906
9907 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009908 if g:netrw_banner
9909 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009910 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009911" 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 +01009912" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009913" 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 +01009914 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009915
Bram Moolenaar446cb832008-06-24 21:56:24 +00009916 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009918 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009919 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009921 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009922 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009923" 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 +01009924" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9925 return
9926 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009927 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009928
9929 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009930 if !exists("w:netrw_bannercnt")
9931 let w:netrw_bannercnt= 0
9932 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9934" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9935" 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 +01009936
Bram Moolenaar5c736222010-01-06 20:54:52 +01009937 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009938" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009939" 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 +00009940 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009941 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009942 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009943 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009944" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009945
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009946 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009947 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009948" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009949 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950
Bram Moolenaar5c736222010-01-06 20:54:52 +01009951 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009952" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009953 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009954 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009955 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009956 else
9957 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009958 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009959 endif
9960 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009961
Bram Moolenaar446cb832008-06-24 21:56:24 +00009962 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009964 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9965 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009966
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009967 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009968 " exten: sort by extension
9969 " The histdel(...,-1) calls remove the last search from the search history
9970" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009971 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9972 NetrwKeepj call histdel("/",-1)
9973 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9974 NetrwKeepj call histdel("/",-1)
9975 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9976 NetrwKeepj call histdel("/",-1)
9977 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9978" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009979 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009980 " normal direction sorting
9981 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9982 else
9983 " reverse direction sorting
9984 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9985 endif
9986 endif
9987 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9988 NetrwKeepj call histdel("/",-1)
9989
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009991 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009992" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009993 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009994" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009995 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009996 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009997" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009998 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009999 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010000" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010001 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10002 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010004 endif
10005
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010006 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010007" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010008 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010009 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010010 call histdel("/",-1)
10011 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 endif
10013 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010014" 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 +000010015
10016 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010017" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10018" 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 +010010019 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010020" 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 +010010021 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010022" 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 +000010023
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010024 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010025 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010027 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010028 endif
10029
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010030 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010031 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010032" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10033 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010034 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010035" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10036 else
10037" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10038" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10039" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10040" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010041 endif
10042
10043 " record previous current directory
10044 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010045" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010046
10047 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010048" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10049" 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 +010010050 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010051" 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 +020010052 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010053" 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 +000010054
10055 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010056" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010057 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010058" 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 +010010059 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010060" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010061 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10062 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010063" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010064" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010065
Bram Moolenaar8d043172014-01-23 14:24:41 +010010066 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010067" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10068" 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 +010010069" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10070 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010071 unlet s:treecurpos
10072 endif
10073
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010074" 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>"))
10075" 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 +000010076" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10077endfun
10078
10079" ---------------------------------------------------------------------
10080" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010081fun! s:SetupNetrwStatusLine(statline)
10082" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10083
10084 if !exists("s:netrw_setup_statline")
10085 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010086" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010087
10088 if !exists("s:netrw_users_stl")
10089 let s:netrw_users_stl= &stl
10090 endif
10091 if !exists("s:netrw_users_ls")
10092 let s:netrw_users_ls= &laststatus
10093 endif
10094
10095 " set up User9 highlighting as needed
10096 let keepa= @a
10097 redir @a
10098 try
10099 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010100 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010101 if &bg == "dark"
10102 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10103 else
10104 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10105 endif
10106 endtry
10107 redir END
10108 let @a= keepa
10109 endif
10110
10111 " set up status line (may use User9 highlighting)
10112 " insure that windows have a statusline
10113 " make sure statusline is displayed
10114 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010115 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010117 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010118
10119" call Dret("SetupNetrwStatusLine : stl=".&stl)
10120endfun
10121
Bram Moolenaar85850f32019-07-19 22:05:51 +020010122" =========================================
10123" Remote Directory Browsing Support: {{{1
10124" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010125
10126" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010127" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10128" This function assumes that a long listing will be received. Size, time,
10129" and reverse sorts will be requested of the server but not otherwise
10130" enforced here.
10131fun! s:NetrwRemoteFtpCmd(path,listcmd)
10132" 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 +010010133" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010134 " sanity check: {{{3
10135 if !exists("w:netrw_method")
10136 if exists("b:netrw_method")
10137 let w:netrw_method= b:netrw_method
10138 else
10139 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10140" call Dret("NetrwRemoteFtpCmd")
10141 return
10142 endif
10143 endif
10144
10145 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10146 let ffkeep= &ff
10147 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010149
10150 " clear off any older non-banner lines " {{{3
10151 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010152" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10153 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010154
10155 ".........................................
10156 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10157 " ftp + <.netrc>: Method #2
10158 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010159 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010160 endif
10161 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010162 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010163" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010164 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010165 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010166" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010167 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" 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>"))
10169 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 +010010170 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010171" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10172 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 +010010173 endif
10174
10175 ".........................................
10176 elseif w:netrw_method == 3 " {{{3
10177 " ftp + machine,id,passwd,filename: Method #3
10178 setl ff=unix
10179 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010180 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010181 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010182 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010183 endif
10184
10185 " handle userid and password
10186 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010187" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010188 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10189 call NetUserPass("ftp:".host)
10190 endif
10191 if exists("g:netrw_uid") && g:netrw_uid != ""
10192 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010193 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010194 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010195 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010196 endif
10197 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010198 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010199 endif
10200 endif
10201
10202 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010203 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010204 endif
10205 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010206 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010207" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010208 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010209 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010210
10211 " perform ftp:
10212 " -i : turns off interactive prompting from ftp
10213 " -n unix : DON'T use <.netrc>, even though it exists
10214 " -n win32: quit being obnoxious about password
10215 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010216" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010217 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010218" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010219" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10220" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010221 endif
10222
10223 ".........................................
10224 elseif w:netrw_method == 9 " {{{3
10225 " sftp username@machine: Method #9
10226 " s:netrw_sftp_cmd
10227 setl ff=unix
10228
10229 " restore settings
10230 let &ff= ffkeep
10231" call Dret("NetrwRemoteFtpCmd")
10232 return
10233
10234 ".........................................
10235 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010236 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010237 endif
10238
10239 " cleanup for Windows " {{{3
10240 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010241 sil! NetrwKeepj %s/\r$//e
10242 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010243 endif
10244 if a:listcmd == "dir"
10245 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010246 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10247 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10248 NetrwKeepj call histdel("/",-1)
10249 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010250 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 +010010251 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10252 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010253 endif
10254 endif
10255
10256 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10257 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010258 exe 'NetrwKeepj '.w:netrw_bannercnt
10259 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010260 endif
10261 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010262 exe 'NetrwKeepj '.w:netrw_bannercnt
10263 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010264 endif
10265
10266 " restore settings " {{{3
10267 let &ff= ffkeep
10268" call Dret("NetrwRemoteFtpCmd")
10269endfun
10270
10271" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010272" s:NetrwRemoteListing: {{{2
10273fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010274" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010275
Bram Moolenaara6878372014-03-22 21:02:50 +010010276 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10277 let w:netrw_bannercnt= s:bannercnt
10278 endif
10279 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10280 let w:netrw_bannercnt= s:bannercnt
10281 endif
10282
Bram Moolenaar446cb832008-06-24 21:56:24 +000010283 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010284
Bram Moolenaar446cb832008-06-24 21:56:24 +000010285 " sanity check:
10286 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010287" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010288 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010289" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010290 if !exists("g:netrw_quiet")
10291 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10292 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010293 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010294" call Dret("s:NetrwRemoteListing -1")
10295 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010296 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010297
Bram Moolenaar8d043172014-01-23 14:24:41 +010010298 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010299" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010300 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010301 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010302 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 +000010303 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010304 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 +000010305 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010306 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010307
Bram Moolenaar85850f32019-07-19 22:05:51 +020010308 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010309" call Dret("s:NetrwRemoteListing -1")
10310 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010311 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010312" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010313
Bram Moolenaar446cb832008-06-24 21:56:24 +000010314 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010315" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010316 let w:netrw_method= b:netrw_method
10317 endif
10318
Bram Moolenaar13600302014-05-22 18:26:40 +020010319 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010320 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010321" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010322 let s:method = "ftp"
10323 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010324 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010325 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010326 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010327 let listcmd= g:netrw_ftp_sizelist_cmd
10328 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010329" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010330 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010331" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010332
Bram Moolenaara6878372014-03-22 21:02:50 +010010333 " report on missing file or directory messages
10334 if search('[Nn]o such file or directory\|Failed to change directory')
10335 let mesg= getline(".")
10336 if exists("w:netrw_bannercnt")
10337 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010338 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 setl noma
10340 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010341 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010342 call netrw#ErrorMsg(s:WARNING,mesg,96)
10343" call Dret("s:NetrwRemoteListing : -1")
10344 return -1
10345 endif
10346
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010347 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 +000010348 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010349" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010350 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010351
10352 " cleanup
10353 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010354 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10355 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010356 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010357 sil! NetrwKeepj %s/\r$//e
10358 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010359
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010360 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010361 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010362 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010363 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010364" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010365 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010366" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010367 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010368 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010369 exe "sil! NetrwKeepj ".line1
10370 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010372" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010373 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010374" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010375 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10376 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010378" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010379 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10380 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10381 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10382 NetrwKeepj call histdel("/",-1)
10383 NetrwKeepj call histdel("/",-1)
10384 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010385 endif
10386 endif
10387
Bram Moolenaar13600302014-05-22 18:26:40 +020010388 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010389 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010390" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010391 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010392" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010394" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10395 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010396 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010397 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10398 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10399 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10400 NetrwKeepj call histdel("/",-1)
10401 NetrwKeepj call histdel("/",-1)
10402 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010403 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010404 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10405 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010406 endif
10407 else
10408 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010409" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010410 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10413 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10414" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415 endif
10416 endif
10417
10418 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010419 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010420" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010421 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10422 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010423 endif
10424 endif
10425
10426 if w:netrw_liststyle == s:LONGLIST
10427 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010428" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429
10430 if s:method == "ftp"
10431 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010432 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010433 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010434 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010435 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010436 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010438 sil! NetrwKeepj 1
10439 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010440 let line2= line(".")
10441 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010443 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444 endif
10445 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010446 exe "sil! NetrwKeepj ".line1
10447 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 endif
10449
10450 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010451" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010452 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 +000010453 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010454" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010455 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010456 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010457 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10458 NetrwKeepj call histdel("/",-1)
10459 NetrwKeepj call histdel("/",-1)
10460 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010461 endif
10462 endif
10463
10464" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010465" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010466" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010467
10468" call Dret("s:NetrwRemoteListing 0")
10469 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010470endfun
10471
Bram Moolenaar446cb832008-06-24 21:56:24 +000010472" ---------------------------------------------------------------------
10473" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10474fun! s:NetrwRemoteRm(usrhost,path) range
10475" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010477 let svpos= winsaveview()
10478" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479
10480 let all= 0
10481 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10482 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010483" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010484 for fname in s:netrwmarkfilelist_{bufnr("%")}
10485 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010486 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010488 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010489 let all= 1
10490 endif
10491 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010492 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493
10494 else
10495 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010496" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497
10498 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010499 let keepsol = &l:sol
10500 setl nosol
10501 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502
10503 " remove multiple files and directories
10504 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010505 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010506 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010507 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010509 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010510 let all= 1
10511 endif
10512 let ctr= ctr + 1
10513 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010514 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010515 endif
10516
10517 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010518" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010519 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010520" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10521 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010522
10523" call Dret("s:NetrwRemoteRm")
10524endfun
10525
10526" ---------------------------------------------------------------------
10527" s:NetrwRemoteRmFile: {{{2
10528fun! s:NetrwRemoteRmFile(path,rmfile,all)
10529" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10530
10531 let all= a:all
10532 let ok = ""
10533
10534 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10535 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010536" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010537 if !all
10538 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010539" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540 call inputsave()
10541 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10542 call inputrestore()
10543 echohl NONE
10544 if ok == ""
10545 let ok="no"
10546 endif
10547 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010548 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010549 let all= 1
10550 endif
10551 endif
10552
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010553 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010554" 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 +000010555 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010556" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010558 if path =~ '^\a\{3,}://'
10559 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010561 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10563 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010564" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010568 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569 let ok="q"
10570 else
10571 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010572" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10573" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10574" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010576 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010577 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010578 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010580" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582 if v:shell_error != 0
10583 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010584 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 +010010585 else
10586 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10587 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010588 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010589 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010590 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010591" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592 endif
10593 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010594 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010595" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 endif
10597
10598 else
10599 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010600" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 if !all
10602 call inputsave()
10603 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10604 call inputrestore()
10605 if ok == ""
10606 let ok="no"
10607 endif
10608 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010609 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010610 let all= 1
10611 endif
10612 endif
10613
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010614 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010616 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010617 else
10618 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010619 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10620" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010621 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010622" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010623
10624 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010625" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10626 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10627" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010628 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010629" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010630
10631 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010632 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010633 endif
10634 endif
10635 endif
10636
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010637 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010638" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 endif
10640 endif
10641
10642" call Dret("s:NetrwRemoteRmFile ".ok)
10643 return ok
10644endfun
10645
10646" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010647" s:NetrwRemoteRename: rename a remote file or directory {{{2
10648fun! s:NetrwRemoteRename(usrhost,path) range
10649" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10650
10651 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010652 let svpos = winsaveview()
10653" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654 let ctr = a:firstline
10655 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10656
10657 " rename files given by the markfilelist
10658 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10659 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010660" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 if exists("subfrom")
10662 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 else
10665 call inputsave()
10666 let newname= input("Moving ".oldname." to : ",oldname)
10667 call inputrestore()
10668 if newname =~ '^s/'
10669 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10670 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10671 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010673 endif
10674 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675
Bram Moolenaar446cb832008-06-24 21:56:24 +000010676 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010677 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010679 let oldname= s:ShellEscape(a:path.oldname)
10680 let newname= s:ShellEscape(a:path.newname)
10681" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010682 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010683 endif
10684
10685 endfor
10686 call s:NetrwUnMarkFile(1)
10687
10688 else
10689
10690 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010691 let keepsol= &l:sol
10692 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010693 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010694 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010695
10696 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010697" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698
10699 call inputsave()
10700 let newname= input("Moving ".oldname." to : ",oldname)
10701 call inputrestore()
10702
10703 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10704 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10705 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010706 let oldname= s:ShellEscape(a:path.oldname)
10707 let newname= s:ShellEscape(a:path.newname)
10708" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010709 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010710 endif
10711
10712 let ctr= ctr + 1
10713 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010714 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010715 endif
10716
10717 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010718 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010719" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10720 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010721
10722" call Dret("NetrwRemoteRename")
10723endfun
10724
Bram Moolenaar85850f32019-07-19 22:05:51 +020010725" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010726" Local Directory Browsing Support: {{{1
10727" ==========================================
10728
10729" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010730" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010731" Should accept: file://localhost/etc/fstab
10732" file:///etc/fstab
10733" file:///c:/WINDOWS/clock.avi
10734" file:///c|/WINDOWS/clock.avi
10735" file://localhost/c:/WINDOWS/clock.avi
10736" file://localhost/c|/WINDOWS/clock.avi
10737" file://c:/foo.txt
10738" file:///c:/foo.txt
10739" 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 +020010740fun! netrw#FileUrlEdit(fname)
10741" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010742 let fname = a:fname
10743 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010744" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010745 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010747 endif
10748 if (has("win32") || has("win95") || has("win64") || has("win16"))
10749 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010750" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010751 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010752" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010753 endif
10754 endif
10755 let fname2396 = netrw#RFC2396(fname)
10756 let fname2396e= fnameescape(fname2396)
10757 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10758 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010759" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010760 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010761" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010762 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10763 endif
10764 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010765
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010766" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10767" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010768 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010769 exe 'NetrwKeepj keepalt edit '.plainfname
10770 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10771
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772" 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 +020010773" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010774 exe "sil doau BufReadPost ".fname2396e
10775endfun
10776
10777" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010778" netrw#LocalBrowseCheck: {{{2
10779fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010780 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010781 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10782 "
10783 " unfortunate interaction -- split window debugging can't be used here, must use
10784 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10785 " another call to LocalBrowseCheck() when attempts to write
10786 " to the DBG buffer are made.
10787 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010788 " The &ft == "netrw" test was installed because the BufEnter event
10789 " would hit when re-entering netrw windows, creating unexpected
10790 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010791" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010792" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010793" 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 Moolenaar85850f32019-07-19 22:05:51 +020010794" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010795" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10796" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010797
Bram Moolenaar97d62492012-11-15 21:28:22 +010010798 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010799 if isdirectory(s:NetrwFile(a:dirname))
10800" 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 +010010801
Bram Moolenaar97d62492012-11-15 21:28:22 +010010802 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010803" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10804" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010805 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010806
Bram Moolenaar446cb832008-06-24 21:56:24 +000010807 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010808" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010809 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010810
Bram Moolenaar5c736222010-01-06 20:54:52 +010010811 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010812" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010813 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010814 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010815 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010816" 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 +010010817" call Dret("netrw#LocalBrowseCheck")
10818 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010819 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010820
Bram Moolenaar85850f32019-07-19 22:05:51 +020010821 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010822 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10823 " AND IF the listing style is not a tree listing
10824 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010825" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010826 let ibuf = 1
10827 let buflast = bufnr("$")
10828 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10830 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010831 endif
10832 let ibuf= ibuf + 1
10833 endwhile
10834 endif
10835 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836" 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>"))
10837" 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 +000010838 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010839" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010840endfun
10841
10842" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010843" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010844" performed any shell command. The idea is to cause all local-browsing
10845" buffers to be refreshed after a user has executed some shell command,
10846" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010847fun! s:LocalBrowseRefresh()
10848" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010849" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10850" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010851
Bram Moolenaar446cb832008-06-24 21:56:24 +000010852 " determine which buffers currently reside in a tab
10853 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010854" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010855 return
10856 endif
10857 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010858" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010859 return
10860 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010861 if exists("s:netrw_events") && s:netrw_events == 1
10862 " s:LocalFastBrowser gets called (indirectly) from a
10863 let s:netrw_events= 2
10864" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10865 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010866 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010867 let itab = 1
10868 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010869 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010870 while itab <= tabpagenr("$")
10871 let buftablist = buftablist + tabpagebuflist()
10872 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010873 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010874 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010875" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10876" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010877 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10878 " | refresh any netrw window
10879 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010880 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010881 let ibl = 0
10882 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010883" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010884 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10885 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010886 " (ibuf not shown in a current window AND
10887 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010888" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10889 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010890 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010891" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010892 continue
10893 elseif index(tabpagebuflist(),ibuf) != -1
10894 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010895" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010896 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010897 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010898 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10899 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10900 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10901 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010902" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010903 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10904 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10905 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010906 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010907 endif
10908 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010909" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010910 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010911" call Decho("restore window: win_gotoid(".curwinid.")")
10912 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010913 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010914
Bram Moolenaara6878372014-03-22 21:02:50 +010010915" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010916endfun
10917
10918" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010919" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10920"
10921" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010922" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10924" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010925" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010926"
10927" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10928" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010929" (re-using a buffer may not be as accurate)
10930"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010931" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010932" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10933" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10934" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10935" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010936fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010937" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10938" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10939" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10940" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010941
10942 " initialize browselist, a list of buffer numbers that the local browser has used
10943 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010944" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010945 let s:netrw_browselist= []
10946 endif
10947
10948 " append current buffer to fastbrowse list
10949 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010950" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010951 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010952" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010953 endif
10954
10955 " enable autocmd events to handle refreshing/removing local browser buffers
10956 " If local browse buffer is currently showing: refresh it
10957 " If local browse buffer is currently hidden : wipe it
10958 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10959 " =1 : medium speed, re-use directory listing for remote only
10960 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010961 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10962 let s:netrw_events= 1
10963 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010964 au!
10965 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010967 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010968 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010969" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010970 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010971 endif
10972 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010973
10974 " user must have changed fastbrowse to its fast setting, so remove
10975 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010976 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010977" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010978 unlet s:netrw_events
10979 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010980 au!
10981 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010982 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010983 endif
10984
Bram Moolenaar85850f32019-07-19 22:05:51 +020010985" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010986endfun
10987
10988" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010989" s:LocalListing: does the job of "ls" for local directories {{{2
10990fun! s:LocalListing()
10991" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010992" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10993" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10994" 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 +010010995
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010996" 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
10997" 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
10998" 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 +010010999
11000 " get the list of files contained in the current directory
11001 let dirname = b:netrw_curdir
11002 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011003 let filelist = s:NetrwGlob(dirname,"*",0)
11004 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011005" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011006
11007 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011008" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011009 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11010 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011011" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011012 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011014 endif
11015
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011016" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011018" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011019
11020 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11021 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11022 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011023" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11024" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011025 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011026" 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 +010011027
11028 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011029" call Decho(" ",'~'.expand("<slnum>"))
11030" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011031
11032 if getftype(filename) == "link"
11033 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011034" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011035 let pfile= filename."@"
11036
11037 elseif getftype(filename) == "socket"
11038 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011039" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011040 let pfile= filename."="
11041
11042 elseif getftype(filename) == "fifo"
11043 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011044" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011045 let pfile= filename."|"
11046
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011047 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011048 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011049" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011050 let pfile= filename."/"
11051
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011052 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011053 if (has("win32") || has("win95") || has("win64") || has("win16"))
11054 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11055 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011056" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011057 let pfile= filename."*"
11058 else
11059 " normal file
11060 let pfile= filename
11061 endif
11062 elseif executable(filename)
11063 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011064" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011065 let pfile= filename."*"
11066 else
11067 " normal file
11068 let pfile= filename
11069 endif
11070
11071 else
11072 " normal file
11073 let pfile= filename
11074 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011075" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011076
11077 if pfile =~ '//$'
11078 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011079" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011080 endif
11081 let pfile= strpart(pfile,dirnamelen)
11082 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11084" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011085
11086 if w:netrw_liststyle == s:LONGLIST
11087 let sz = getfsize(filename)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011088 let fsz = strpart(" ",1,15-strlen(sz)).sz
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011089 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011090 let sz= s:NetrwHumanReadable(sz)
11091 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011092 let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011093 let pfile = longfile.sz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011094" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011095 endif
11096
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011097 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011098 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011099 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011100" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011102 let t = getftime(filename)
11103 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar91359012019-11-30 17:57:03 +010011104" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011105 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011106 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011107
11108 elseif g:netrw_sort_by =~ "^s"
11109 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011110" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011112 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011113 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011114 let sz= s:NetrwHumanReadable(sz)
11115 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011117" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011118 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011119 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011120
11121 else
11122 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011123" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011125 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011126 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011127" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011128 endfor
11129
11130 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011131 sil! NetrwKeepj g/^$/d
11132 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011133 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011134" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011135 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11136
11137" call Dret("s:LocalListing")
11138endfun
11139
11140" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011141" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11142fun! s:NetrwLocalExecute(cmd)
11143" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11144 let ykeep= @@
11145 " sanity check
11146 if !executable(a:cmd)
11147 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11148 let @@= ykeep
11149" call Dret("s:NetrwLocalExecute")
11150 return
11151 endif
11152
11153 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011154" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011155 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011156" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011157
11158 " strip any ansi escape sequences off
11159 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11160
11161 " show user the result(s)
11162 echomsg result
11163 let @@= ykeep
11164
11165" call Dret("s:NetrwLocalExecute")
11166endfun
11167
11168" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011169" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011170fun! s:NetrwLocalRename(path) range
11171" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11172
11173 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011174 let ykeep = @@
11175 let ctr = a:firstline
11176 let svpos = winsaveview()
11177 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011178" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011179
11180 " rename files given by the markfilelist
11181 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11182 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011183" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011184 if exists("subfrom")
11185 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011186" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011187 else
11188 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011189 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011190 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011191 if newname =~ ''
11192 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11193 let newname = substitute(newname,'^.*','','')
11194 elseif newname =~ ''
11195 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11196 let newname = substitute(newname,'[^/]*','','')
11197 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011198 if newname =~ '^s/'
11199 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11200 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011201" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011202 let newname = substitute(oldname,subfrom,subto,'')
11203 endif
11204 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011205 if !all && filereadable(newname)
11206 call inputsave()
11207 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11208 call inputrestore()
11209 if response == "all"
11210 let all= 1
11211 elseif response != "y" && response != "yes"
11212 " refresh the directory
11213" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11214 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11215" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11216 NetrwKeepj call winrestview(svpos)
11217 let @@= ykeep
11218" call Dret("NetrwLocalRename")
11219 return
11220 endif
11221 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011222 call rename(oldname,newname)
11223 endfor
11224 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011225
Bram Moolenaar97d62492012-11-15 21:28:22 +010011226 else
11227
11228 " attempt to rename files/directories
11229 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011230 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011231
11232 " sanity checks
11233 if line(".") < w:netrw_bannercnt
11234 let ctr= ctr + 1
11235 continue
11236 endif
11237 let curword= s:NetrwGetWord()
11238 if curword == "./" || curword == "../"
11239 let ctr= ctr + 1
11240 continue
11241 endif
11242
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011243 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011244 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011245" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011246
11247 call inputsave()
11248 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11249 call inputrestore()
11250
11251 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011252" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011253
11254 let ctr= ctr + 1
11255 endwhile
11256 endif
11257
11258 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011259" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011260 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011261" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11262 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011263 let @@= ykeep
11264
11265" call Dret("NetrwLocalRename")
11266endfun
11267
11268" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011269" s:NetrwLocalRm: {{{2
11270fun! s:NetrwLocalRm(path) range
11271" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011272" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011273
11274 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011275 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011276 let ret = 0
11277 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011278 let svpos = winsaveview()
11279" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011280
11281 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11282 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011283" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011284 for fname in s:netrwmarkfilelist_{bufnr("%")}
11285 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011286 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011287 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011288 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011289 let all= 1
11290 endif
11291 endfor
11292 call s:NetrwUnMarkFile(1)
11293
11294 else
11295 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011296" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011297
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011298 let keepsol= &l:sol
11299 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011300 let ctr = a:firstline
11301 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011302 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011303
11304 " sanity checks
11305 if line(".") < w:netrw_bannercnt
11306 let ctr= ctr + 1
11307 continue
11308 endif
11309 let curword= s:NetrwGetWord()
11310 if curword == "./" || curword == "../"
11311 let ctr= ctr + 1
11312 continue
11313 endif
11314 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011315 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011316 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011317 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011318 let all= 1
11319 endif
11320 let ctr= ctr + 1
11321 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011322 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011323 endif
11324
11325 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011326" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011327 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011328 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011329" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11330 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011331 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011332 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011333
11334" call Dret("s:NetrwLocalRm")
11335endfun
11336
11337" ---------------------------------------------------------------------
11338" s:NetrwLocalRmFile: remove file fname given the path {{{2
11339" Give confirmation prompt unless all==1
11340fun! s:NetrwLocalRmFile(path,fname,all)
11341" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011342
Bram Moolenaar446cb832008-06-24 21:56:24 +000011343 let all= a:all
11344 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011345 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011346 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11347" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011348
11349 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11350 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011351" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011352 if !all
11353 echohl Statement
11354 call inputsave()
11355 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11356 call inputrestore()
11357 echohl NONE
11358 if ok == ""
11359 let ok="no"
11360 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011361" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011362 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011363" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011364 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011365 let all= 1
11366 endif
11367 endif
11368
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011369 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011370 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011371" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011372 endif
11373
11374 else
11375 " attempt to remove directory
11376 if !all
11377 echohl Statement
11378 call inputsave()
11379 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11380 call inputrestore()
11381 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11382 if ok == ""
11383 let ok="no"
11384 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011385 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386 let all= 1
11387 endif
11388 endif
11389 let rmfile= substitute(rmfile,'[\/]$','','e')
11390
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011391 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +020011392 if v:version < 704 || (v:version == 704 && !has("patch1107"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011393" " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
11394 call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
11395" " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011397 if v:shell_error != 0
11398" " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11399 let errcode= s:NetrwDelete(rmfile)
11400" " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011401
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011402 if errcode != 0
11403 if has("unix")
11404" " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11405 call system("rm ".s:ShellEscape(rmfile))
11406 if v:shell_error != 0 && !exists("g:netrw_quiet")
11407 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
11408 let ok="no"
11409 endif
11410 elseif !exists("g:netrw_quiet")
11411 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412 let ok="no"
11413 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011414 endif
11415 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011416 else
11417 if delete(rmfile,"d")
11418 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
11419 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011420 endif
11421 endif
11422 endif
11423
11424" call Dret("s:NetrwLocalRmFile ".ok)
11425 return ok
11426endfun
11427
Bram Moolenaar85850f32019-07-19 22:05:51 +020011428" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011429" Support Functions: {{{1
11430
Bram Moolenaar488c6512005-08-11 20:09:58 +000011431" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011432" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11433" 0: marked file list of current buffer
11434" 1: marked file target
11435fun! netrw#Access(ilist)
11436 if a:ilist == 0
11437 if exists("s:netrwmarkfilelist_".bufnr('%'))
11438 return s:netrwmarkfilelist_{bufnr('%')}
11439 else
11440 return "no-list-buf#".bufnr('%')
11441 endif
11442 elseif a:ilist == 1
11443 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011444 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011445endfun
11446
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011447" ---------------------------------------------------------------------
11448" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11449fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011450 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011451endfun
11452
Bram Moolenaara6878372014-03-22 21:02:50 +010011453" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011454" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11455" I expect this function to be used in
11456" :PChkAssert netrw#Expose("netrwmarkfilelist")
11457" for example.
11458fun! netrw#Expose(varname)
11459" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011460 if exists("s:".a:varname)
11461 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011462" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011463 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011464" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011465 if type(retval) == 3
11466 let retval = copy(retval)
11467 let i = 0
11468 while i < len(retval)
11469 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11470 let i = i + 1
11471 endwhile
11472 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011473" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011474 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011475 else
11476" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011477 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011478 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011479" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011480 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011481 endif
11482
11483" call Dret("netrw#Expose ".string(retval))
11484 return retval
11485endfun
11486
11487" ---------------------------------------------------------------------
11488" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11489fun! netrw#Modify(varname,newvalue)
11490" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11491 exe "let s:".a:varname."= ".string(a:newvalue)
11492" call Dret("netrw#Modify")
11493endfun
11494
11495" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011496" netrw#RFC2396: converts %xx into characters {{{2
11497fun! netrw#RFC2396(fname)
11498" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11499 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11500" call Dret("netrw#RFC2396 ".fname)
11501 return fname
11502endfun
11503
11504" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011505" netrw#UserMaps: supports user-specified maps {{{2
11506" see :help function()
11507"
11508" g:Netrw_UserMaps is a List with members such as:
11509" [[keymap sequence, function reference],...]
11510"
11511" The referenced function may return a string,
11512" refresh : refresh the display
11513" -other- : this string will be executed
11514" or it may return a List of strings.
11515"
11516" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011517" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011518" Related functions:
11519" netrw#Expose(varname) -- see s:varname variables
11520" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11521" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11522fun! netrw#UserMaps(islocal)
11523" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11524" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11525
11526 " set up usermaplist
11527 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11528" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11529 for umap in g:Netrw_UserMaps
11530" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11531" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11532 " if umap[0] is a string and umap[1] is a string holding a function name
11533 if type(umap[0]) == 1 && type(umap[1]) == 1
11534" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11535 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11536 else
11537 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11538 endif
11539 endfor
11540 endif
11541" call Dret("netrw#UserMaps")
11542endfun
11543
11544" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011545" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11546fun! netrw#WinPath(path)
11547" call Dfunc("netrw#WinPath(path<".a:path.">)")
11548 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11549 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011550 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011551 " remove trailing slash (Win95)
11552 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11553 " remove escaped spaces
11554 let path = substitute(path, '\ ', ' ', 'g')
11555 " convert slashes to backslashes
11556 let path = substitute(path, '/', '\', 'g')
11557 else
11558 let path= a:path
11559 endif
11560" call Dret("netrw#WinPath <".path.">")
11561 return path
11562endfun
11563
11564" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011565" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11566" cb : bl2mf=0 add marked files to buffer list
11567" cB : bl2mf=1 use bufferlist to mark files
11568" (mnemonic: cb = copy (marked files) to buffer list)
11569fun! s:NetrwBadd(islocal,bl2mf)
11570" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11571 if a:bl2mf
11572 " cB: add buffer list to marked files
11573 redir => bufl
11574 ls
11575 redir END
11576 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11577 for fname in bufl
11578 call s:NetrwMarkFile(a:islocal,fname)
11579 endfor
11580 else
11581 " cb: add marked files to buffer list
11582 for fname in s:netrwmarkfilelist_{bufnr("%")}
11583" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11584 exe "badd ".fnameescape(fname)
11585 endfor
11586 let curbufnr = bufnr("%")
11587 let curdir = s:NetrwGetCurdir(a:islocal)
11588 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11589 endif
11590" call Dret("s:NetrwBadd")
11591endfun
11592
11593" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011594" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11595fun! s:ComposePath(base,subdir)
11596" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11597
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011598 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011599" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011600 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011601 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011602 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011603 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011604 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011605 endif
11606
Bram Moolenaar85850f32019-07-19 22:05:51 +020011607 " COMBAK: test on windows with changing to root directory: :e C:/
11608 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011609" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011610 let ret= a:subdir
11611
Bram Moolenaar85850f32019-07-19 22:05:51 +020011612 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011613" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011614 if a:base =~ '[/\\]$'
11615 let ret= a:base.a:subdir
11616 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011617 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011618 endif
11619
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011620 elseif a:base =~ '^\a\{3,}://'
11621" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011622 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11623 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11624 if a:subdir == '../'
11625 if curpath =~ '[^/]/[^/]\+/$'
11626 let curpath= substitute(curpath,'[^/]\+/$','','')
11627 else
11628 let curpath=""
11629 endif
11630 let ret= urlbase.curpath
11631 else
11632 let ret= urlbase.curpath.a:subdir
11633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011634" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11635" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11636" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011637
11638 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011639" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011640 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11641 if a:base =~ '^//'
11642 " keeping initial '//' for the benefit of network share listing support
11643 let ret= '/'.ret
11644 endif
11645 let ret= simplify(ret)
11646 endif
11647
11648" call Dret("s:ComposePath ".ret)
11649 return ret
11650endfun
11651
11652" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011653" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11654" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11655fun! s:DeleteBookmark(fname)
11656" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11657 call s:MergeBookmarks()
11658
11659 if exists("g:netrw_bookmarklist")
11660 let indx= index(g:netrw_bookmarklist,a:fname)
11661 if indx == -1
11662 let indx= 0
11663 while indx < len(g:netrw_bookmarklist)
11664 if g:netrw_bookmarklist[indx] =~ a:fname
11665 call remove(g:netrw_bookmarklist,indx)
11666 let indx= indx - 1
11667 endif
11668 let indx= indx + 1
11669 endwhile
11670 else
11671 " remove exact match
11672 call remove(g:netrw_bookmarklist,indx)
11673 endif
11674 endif
11675
11676" call Dret("s:DeleteBookmark")
11677endfun
11678
11679" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011680" s:FileReadable: o/s independent filereadable {{{2
11681fun! s:FileReadable(fname)
11682" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11683
11684 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011685 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011686 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011687 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011688 endif
11689
11690" call Dret("s:FileReadable ".ret)
11691 return ret
11692endfun
11693
11694" ---------------------------------------------------------------------
11695" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11696" Places correct suffix on end of temporary filename,
11697" using the suffix provided with fname
11698fun! s:GetTempfile(fname)
11699" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11700
11701 if !exists("b:netrw_tmpfile")
11702 " get a brand new temporary filename
11703 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011704" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011705
Bram Moolenaarc236c162008-07-13 17:41:49 +000011706 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011707" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011708
Bram Moolenaar9964e462007-05-05 17:54:07 +000011709 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011710 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11711" 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 +010011712 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011713" call Dret("s:GetTempfile getcwd<".getcwd().">")
11714 return ""
11715 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011716
Bram Moolenaar9964e462007-05-05 17:54:07 +000011717 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011718 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011720
Bram Moolenaar9964e462007-05-05 17:54:07 +000011721 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011722 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011723 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011724 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011725 if !exists("+shellslash") || !&ssl
11726 let tmpfile = substitute(tmpfile,'/','\','g')
11727 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011728 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011729 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011730 endif
11731 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011732" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011733 else
11734 " re-use temporary filename
11735 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011736" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011737 endif
11738
11739 " use fname's suffix for the temporary file
11740 if a:fname != ""
11741 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011742" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011743 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011744 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011745 elseif a:fname =~ '.txz$'
11746 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011747 else
11748 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11749 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011750" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011751 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011752" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011753 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011754" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011755 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11756 endif
11757 endif
11758
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011759" 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 +000011760" call Dret("s:GetTempfile <".tmpfile.">")
11761 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011762endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011763
11764" ---------------------------------------------------------------------
11765" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011766" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011767fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011768" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011769 if s:user == ""
11770 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11771 else
11772 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11773 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011774 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011775 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011776 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011777 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011778 else
11779 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11780 endif
11781" call Dret("s:MakeSshCmd <".sshcmd.">")
11782 return sshcmd
11783endfun
11784
11785" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011786" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11787fun! s:MakeBookmark(fname)
11788" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11789
11790 if !exists("g:netrw_bookmarklist")
11791 let g:netrw_bookmarklist= []
11792 endif
11793
11794 if index(g:netrw_bookmarklist,a:fname) == -1
11795 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011796 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011797 call add(g:netrw_bookmarklist,a:fname.'/')
11798 elseif a:fname !~ '/'
11799 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11800 else
11801 call add(g:netrw_bookmarklist,a:fname)
11802 endif
11803 call sort(g:netrw_bookmarklist)
11804 endif
11805
11806" call Dret("s:MakeBookmark")
11807endfun
11808
11809" ---------------------------------------------------------------------
11810" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11811fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011812" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011813 " get bookmarks from .netrwbook file
11814 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011815 if filereadable(s:NetrwFile(savefile))
11816" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011817 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011818" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011819 NetrwKeepj call delete(savefile)
11820 endif
11821" call Dret("s:MergeBookmarks")
11822endfun
11823
11824" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011825" s:NetrwBMShow: {{{2
11826fun! s:NetrwBMShow()
11827" call Dfunc("s:NetrwBMShow()")
11828 redir => bmshowraw
11829 menu
11830 redir END
11831 let bmshowlist = split(bmshowraw,'\n')
11832 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011833 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011834 if bmshowfuncs != []
11835 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011836 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011837 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011839 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011840 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011841" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11842endfun
11843
11844" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011845" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011846fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011847 if !exists("w:netrw_liststyle")
11848 let w:netrw_liststyle= g:netrw_liststyle
11849 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011850" 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 +020011851
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011852" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11853
Bram Moolenaaradc21822011-04-01 18:03:16 +020011854 if &ft != "netrw"
11855 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11856 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011857" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011858
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011859 elseif g:netrw_cursor == 8
11860 if w:netrw_liststyle == s:WIDELIST
11861 setl cursorline
11862 setl cursorcolumn
11863 else
11864 setl cursorline
11865 endif
11866 elseif g:netrw_cursor == 7
11867 setl cursorline
11868 elseif g:netrw_cursor == 6
11869 if w:netrw_liststyle == s:WIDELIST
11870 setl cursorline
11871 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011872 elseif g:netrw_cursor == 4
11873 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011874" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011875 setl cursorline
11876 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011877
11878 elseif g:netrw_cursor == 3
11879 " thin-long-tree: cursorline, user's cursorcolumn
11880 " wide : cursorline, cursorcolumn
11881 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011882" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011883 setl cursorline
11884 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011885 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011886" 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 +020011887 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011888 endif
11889
11890 elseif g:netrw_cursor == 2
11891 " thin-long-tree: cursorline, user's cursorcolumn
11892 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011893" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011894 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011895
11896 elseif g:netrw_cursor == 1
11897 " thin-long-tree: user's cursorline, user's cursorcolumn
11898 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011899 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011900" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011901 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011903" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011904 endif
11905
11906 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011907 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011908" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011909 let &l:cursorline = s:netrw_usercul
11910 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011911 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011912
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011913" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011914" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011915endfun
11916
11917" ---------------------------------------------------------------------
11918" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11919fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011920" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011921 if exists("s:netrw_usercul")
11922 let &l:cursorline = s:netrw_usercul
11923 endif
11924 if exists("s:netrw_usercuc")
11925 let &l:cursorcolumn = s:netrw_usercuc
11926 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011927" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011928" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11929endfun
11930
11931" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011932" s:NetrwDelete: Deletes a file. {{{2
11933" Uses Steve Hall's idea to insure that Windows paths stay
11934" acceptable. No effect on Unix paths.
11935" Examples of use: let result= s:NetrwDelete(path)
11936fun! s:NetrwDelete(path)
11937" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11938
Bram Moolenaar5c736222010-01-06 20:54:52 +010011939 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011940 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
11941 if exists("+shellslash")
11942 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011943 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011944 let result = delete(path)
11945 let &shellslash = sskeep
11946 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011947" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011948 let result= delete(path)
11949 endif
11950 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011951" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011952 let result= delete(path)
11953 endif
11954 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011955 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011956 endif
11957
11958" call Dret("s:NetrwDelete ".result)
11959 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011960endfun
11961
11962" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011963" s:NetrwBufRemover: removes a buffer that: {{{2s
11964" has buffer-id > 1
11965" is unlisted
11966" is unnamed
11967" does not appear in any window
11968fun! s:NetrwBufRemover(bufid)
11969" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11970" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11971" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11972" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11973" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11974
11975 if a:bufid > 1 && !buflisted(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
11976" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
11977 exe "bd! ".a:bufid
11978 endif
11979
11980" call Dret("s:NetrwBufRemover")
11981endfun
11982
11983" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011984" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011985fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011986" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011987" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011988
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011989 " Clean out the last buffer:
11990 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11991 " If so, delete it.
11992 call s:NetrwBufRemover(bufnr("$"))
11993
Bram Moolenaar446cb832008-06-24 21:56:24 +000011994 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011995" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011996 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11997 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11998 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11999 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12000 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12001 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12002 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12003 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12004 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12005 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12006 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12007 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12008 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12009 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12010 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12011 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12012
Bram Moolenaar85850f32019-07-19 22:05:51 +020012013 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012014" call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012015 " when tree listing uses file TreeListing... a new buffer is made.
12016 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012017 " COMBAK: this causes a problem, see P43
12018" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012019 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012020 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012021 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012022" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012023 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012024
Bram Moolenaar446cb832008-06-24 21:56:24 +000012025 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012026" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012027 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12028 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12029 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12030 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12031 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12032 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12033 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12034 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12035 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12036 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12037 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12038 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12039 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12040 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12041 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12042 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12043
Bram Moolenaar5c736222010-01-06 20:54:52 +010012044 if a:0 > 0
12045 let b:netrw_curdir= a:1
12046 if b:netrw_curdir =~ '/$'
12047 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012048 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012049 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012050 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012051 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12052 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012053 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012054 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012055 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012056 endif
12057 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012058 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12059 let &l:bexpr = "netrw#BalloonHelp()"
12060 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012061
Bram Moolenaar8d043172014-01-23 14:24:41 +010012062" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012063endfun
12064
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012065" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012066" s:NetrwExe: executes a string using "!" {{{2
12067fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012068" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012069 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012070" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012071 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12072 set shell& shellcmdflag& shellxquote& shellxescape&
12073 set shellquote& shellpipe& shellredir& shellslash&
12074 exe a:cmd
12075 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12076 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012077" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012078 exe a:cmd
12079 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012080 if v:shell_error
12081 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12082 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012083" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012084endfun
12085
12086" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012087" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12088fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012089 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012090" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012091 let curbuf = bufnr("%")
12092 let curwin = winnr()
12093 let iwin = 1
12094 while iwin <= winnr("$")
12095 exe iwin."wincmd w"
12096 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12097 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12098 let winvars= w:
12099 break
12100 endif
12101 let iwin= iwin + 1
12102 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012103 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012104 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012105" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012106 for k in keys(winvars)
12107 let w:{k}= winvars[k]
12108 endfor
12109 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012110" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012111 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012112endfun
12113
Bram Moolenaara6878372014-03-22 21:02:50 +010012114" ---------------------------------------------------------------------
12115" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012116" Returns: 0=success
12117" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012118fun! s:NetrwLcd(newdir)
12119" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012120" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012121
Bram Moolenaar85850f32019-07-19 22:05:51 +020012122 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012123 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012124 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012125 catch /^Vim\%((\a\+)\)\=:E344/
12126 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12127 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012128 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012129 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12130 " forward slashes by earlier code; so check for both.
12131 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12132 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12133 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012134 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012135 endif
12136 endif
12137 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012138 let err472= 1
12139 endtry
12140
12141 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012142 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12143 if exists("w:netrw_prvdir")
12144 let a:newdir= w:netrw_prvdir
12145 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012146 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012147" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012148 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012149" 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 +010012150 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012151 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012152" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12153 return -1
12154 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012155
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012156" call Decho("getcwd <".getcwd().">")
12157" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012158" call Dret("s:NetrwLcd 0")
12159 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012160endfun
12161
Bram Moolenaar9964e462007-05-05 17:54:07 +000012162" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012163" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12164" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12165fun! s:NetrwSaveWordPosn()
12166" call Dfunc("NetrwSaveWordPosn()")
12167 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12168" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12169endfun
12170
12171" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012172" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12173" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12174fun! s:NetrwHumanReadable(sz)
12175" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12176
12177 if g:netrw_sizestyle == 'h'
12178 if a:sz >= 1000000000
12179 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12180 elseif a:sz >= 10000000
12181 let sz = printf("%d",a:sz/1000000)."m"
12182 elseif a:sz >= 1000000
12183 let sz = printf("%.1f",a:sz/1000000.0)."m"
12184 elseif a:sz >= 10000
12185 let sz = printf("%d",a:sz/1000)."k"
12186 elseif a:sz >= 1000
12187 let sz = printf("%.1f",a:sz/1000.0)."k"
12188 else
12189 let sz= a:sz
12190 endif
12191
12192 elseif g:netrw_sizestyle == 'H'
12193 if a:sz >= 1073741824
12194 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12195 elseif a:sz >= 10485760
12196 let sz = printf("%d",a:sz/1048576)."M"
12197 elseif a:sz >= 1048576
12198 let sz = printf("%.1f",a:sz/1048576.0)."M"
12199 elseif a:sz >= 10240
12200 let sz = printf("%d",a:sz/1024)."K"
12201 elseif a:sz >= 1024
12202 let sz = printf("%.1f",a:sz/1024.0)."K"
12203 else
12204 let sz= a:sz
12205 endif
12206
12207 else
12208 let sz= a:sz
12209 endif
12210
12211" call Dret("s:NetrwHumanReadable ".sz)
12212 return sz
12213endfun
12214
12215" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012216" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12217" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12218fun! s:NetrwRestoreWordPosn()
12219" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012220 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012221" call Dret("NetrwRestoreWordPosn")
12222endfun
12223
12224" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012225" s:RestoreBufVars: {{{2
12226fun! s:RestoreBufVars()
12227" call Dfunc("s:RestoreBufVars()")
12228
12229 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12230 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12231 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12232 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12233 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12234 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12235
12236" call Dret("s:RestoreBufVars")
12237endfun
12238
12239" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012240" s:RemotePathAnalysis: {{{2
12241fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012242" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012243
Bram Moolenaara6878372014-03-22 21:02:50 +010012244 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012245 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012246 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012247 let s:user = substitute(a:dirname,dirpat,'\3','')
12248 let s:machine = substitute(a:dirname,dirpat,'\4','')
12249 let s:port = substitute(a:dirname,dirpat,'\5','')
12250 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012251 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012252 if s:machine =~ '@'
12253 let dirpat = '^\(.*\)@\(.\{-}\)$'
12254 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12255 let s:machine = substitute(s:machine,dirpat,'\2','')
12256 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012257
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012258" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12259" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12260" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12261" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12262" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12263" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012264
12265" call Dret("s:RemotePathAnalysis")
12266endfun
12267
12268" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012269" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12270" Returns status
12271" Runs system() on
12272" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012273" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012274fun! s:RemoteSystem(cmd)
12275" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12276 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012277 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 +000012278 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012279 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012280 else
12281 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12282 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12283 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012284 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012285 else
12286 let cmd= cmd.' '
12287 endif
12288 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012289" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012290 let ret= system(cmd)
12291 endif
12292" call Dret("s:RemoteSystem ".ret)
12293 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012294endfun
12295
12296" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012297" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012298fun! s:RestoreWinVars()
12299" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012300 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012301 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12302 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12303 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12304 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12305 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12306 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12307 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12308 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12309 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12310 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12311 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12312 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012313 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12314 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012315 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12316 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12317 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12318" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012319endfun
12320
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012321" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012322" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12323"
12324" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12325" is true) and a command, :Rexplore, which call this function.
12326"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012327" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012328"
12329" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012330fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012331 if exists("s:netrwdrag")
12332 return
12333 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012334" 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 +010012335" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12336" 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 +010012337
12338 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012339 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012340" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012341 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012342 unlet w:netrw_rexfile
12343" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012344 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012345" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012346" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12347" 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 +020012348 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012349
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012350 " ---------------------------
12351 " :Rex issued while in a file
12352 " ---------------------------
12353
Bram Moolenaara6878372014-03-22 21:02:50 +010012354 " record current file so :Rex can return to it from netrw
12355 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012356" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012357
12358 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012359" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012360 return
12361 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012362" 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 +020012363 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012364 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012365 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012366 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012367 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012368 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012369 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012370 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012371 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012372" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12373 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012374" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12375 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012376 if exists("s:rexposn_".bufnr('%'))
12377 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012378 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012379 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012380" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012381 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012382
Bram Moolenaar85850f32019-07-19 22:05:51 +020012383 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12384 if exists("s:explore_match")
12385 exe "2match netrwMarkFile /".s:explore_match."/"
12386 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012387 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012388
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012389" 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 +010012390" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012391endfun
12392
12393" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012394" s:SaveBufVars: save selected b: variables to s: variables {{{2
12395" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012396fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012397" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012398
12399 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12400 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12401 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12402 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12403 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12404 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12405
12406" call Dret("s:SaveBufVars")
12407endfun
12408
12409" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012410" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12411fun! s:SavePosn(posndict)
12412" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12413
Bram Moolenaar85850f32019-07-19 22:05:51 +020012414 if !exists("a:posndict[bufnr('%')]")
12415 let a:posndict[bufnr("%")]= []
12416 endif
12417" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12418 call add(a:posndict[bufnr("%")],winsaveview())
12419" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012420
12421" call Dret("s:SavePosn posndict")
12422 return a:posndict
12423endfun
12424
12425" ---------------------------------------------------------------------
12426" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12427fun! s:RestorePosn(posndict)
12428" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012429 if exists("a:posndict")
12430 if has_key(a:posndict,bufnr("%"))
12431" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12432 let posnlen= len(a:posndict[bufnr("%")])
12433 if posnlen > 0
12434 let posnlen= posnlen - 1
12435" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12436 call winrestview(a:posndict[bufnr("%")][posnlen])
12437 call remove(a:posndict[bufnr("%")],posnlen)
12438" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12439 endif
12440 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012441 endif
12442" call Dret("s:RestorePosn")
12443endfun
12444
12445" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012446" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012447fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012448" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012449 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12450 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12451 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12452 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12453 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12454 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12455 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12456 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12457 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12458 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12459 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12460 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12461 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12462 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12463 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12464 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12465 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12466 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12467" call Dret("s:SaveWinVars")
12468endfun
12469
12470" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012471" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012472" To allow separate windows to have their own activities, such as
12473" Explore **/pattern, several variables have been made window-oriented.
12474" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012475" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012476" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012477fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012478" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012479 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12480 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12481 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12482 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12483 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12484 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12485 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12486 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12487 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12488 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12489" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012490endfun
12491
12492" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012493" s:SetRexDir: set directory for :Rexplore {{{2
12494fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012495" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012496 let w:netrw_rexdir = a:dirname
12497 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012498 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012499" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12500" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012501" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012502" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012503" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012504endfun
12505
12506" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012507" s:ShowLink: used to modify thin and tree listings to show links {{{2
12508fun! s:ShowLink()
12509" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012510" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12511" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012512 if exists("b:netrw_curdir")
12513 norm! $?\a
12514 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12515 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012516" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12517" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12518" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12519 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012520 let dirlen = strlen(b:netrw_curdir)
12521 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012522" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012523 endif
12524 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012525" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12526" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012527 setl noro ma
12528 call setline(".",modline)
12529 setl ro noma nomod
12530 endif
12531" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12532endfun
12533
12534" ---------------------------------------------------------------------
12535" s:ShowStyle: {{{2
12536fun! s:ShowStyle()
12537 if !exists("w:netrw_liststyle")
12538 let liststyle= g:netrw_liststyle
12539 else
12540 let liststyle= w:netrw_liststyle
12541 endif
12542 if liststyle == s:THINLIST
12543 return s:THINLIST.":thin"
12544 elseif liststyle == s:LONGLIST
12545 return s:LONGLIST.":long"
12546 elseif liststyle == s:WIDELIST
12547 return s:WIDELIST.":wide"
12548 elseif liststyle == s:TREELIST
12549 return s:TREELIST.":tree"
12550 else
12551 return 'n/a'
12552 endif
12553endfun
12554
12555" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012556" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12557" Solution from Nicolai Weibull, vim docs (:help strlen()),
12558" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012559fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012560" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12561
12562 if v:version >= 703 && exists("*strdisplaywidth")
12563 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012564
Bram Moolenaar8d043172014-01-23 14:24:41 +010012565 elseif type(g:Align_xstrlen) == 1
12566 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12567 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012568
Bram Moolenaar8d043172014-01-23 14:24:41 +010012569 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012570 " number of codepoints (Latin a + combining circumflex is two codepoints)
12571 " (comment from TM, solution from NW)
12572 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012573
Bram Moolenaar8d043172014-01-23 14:24:41 +010012574 elseif g:Align_xstrlen == 2
12575 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012576 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12577 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012578 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012579
Bram Moolenaar8d043172014-01-23 14:24:41 +010012580 elseif g:Align_xstrlen == 3
12581 " virtual length (counting, for instance, tabs as anything between 1 and
12582 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012583 " preceded by lam, one otherwise, etc.)
12584 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012585 let modkeep= &l:mod
12586 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012587 call setline(line("."),a:x)
12588 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012589 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012590 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012591 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012592
Bram Moolenaar446cb832008-06-24 21:56:24 +000012593 else
12594 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012595 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012596 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012597" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012598 return ret
12599endfun
12600
12601" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012602" s:ShellEscape: shellescape(), or special windows handling {{{2
12603fun! s:ShellEscape(s, ...)
12604 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12605 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12606 endif
12607 let f = a:0 > 0 ? a:1 : 0
12608 return shellescape(a:s, f)
12609endfun
12610
12611" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012612" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012613fun! s:TreeListMove(dir)
12614" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012615 let curline = getline('.')
12616 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12617 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12618 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12619 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12620 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12621 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12622" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12623" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12624" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12625" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12626" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12627 " COMBAK : need to handle when on a directory
12628 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012629 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012630 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012631 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012632 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012633" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012634 elseif a:dir == '[]' && nxtline != ''
12635 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012636" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012637 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12638 if nl != 0
12639 NetrwKeepj norm! k
12640 else
12641 NetrwKeepj norm! G
12642 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012643" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012644 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012645 endif
12646
12647" call Dret("s:TreeListMove")
12648endfun
12649
12650" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012651" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12652" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12653" can't be called except via emenu. But due to locale, that menu line may not be called
12654" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12655fun! s:UpdateBuffersMenu()
12656" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012657 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012658 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012659 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012660 catch /^Vim\%((\a\+)\)\=:E/
12661 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012662 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012663 endtry
12664 endif
12665" call Dret("s:UpdateBuffersMenu")
12666endfun
12667
12668" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012669" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012670" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012671fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012672" call Dfunc("s:UseBufWinVars()")
12673 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012674 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12675 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12676 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12677 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12678 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12679 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12680 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12681 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12682 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 +000012683" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012684endfun
12685
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012686" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012687" s:UserMaps: supports user-defined UserMaps {{{2
12688" * calls a user-supplied funcref(islocal,curdir)
12689" * interprets result
12690" See netrw#UserMaps()
12691fun! s:UserMaps(islocal,funcname)
12692" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12693
12694 if !exists("b:netrw_curdir")
12695 let b:netrw_curdir= getcwd()
12696 endif
12697 let Funcref = function(a:funcname)
12698 let result = Funcref(a:islocal)
12699
12700 if type(result) == 1
12701 " if result from user's funcref is a string...
12702" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12703 if result == "refresh"
12704" call Decho("refreshing display",'~'.expand("<slnum>"))
12705 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12706 elseif result != ""
12707" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12708 exe result
12709 endif
12710
12711 elseif type(result) == 3
12712 " if result from user's funcref is a List...
12713" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12714 for action in result
12715 if action == "refresh"
12716" call Decho("refreshing display",'~'.expand("<slnum>"))
12717 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12718 elseif action != ""
12719" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12720 exe action
12721 endif
12722 endfor
12723 endif
12724
12725" call Dret("s:UserMaps")
12726endfun
12727
Bram Moolenaar85850f32019-07-19 22:05:51 +020012728" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012729" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012730" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012731let &cpo= s:keepcpo
12732unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012733
Bram Moolenaar85850f32019-07-19 22:05:51 +020012734" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012735" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012736" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012737" vim:ts=8 fdm=marker