blob: 29310aabd41d31b56d0ca7f2893f111442601a27 [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 Moolenaar3c053a12022-10-16 13:11:12 +01001794 if !isdirectory(expand('%'))
1795" call Decho("..doing filetype detect anyway")
1796 filetype detect
1797 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001798" 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>"))
1799" 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 +02001800" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001801 return
1802 endif
1803 unlet {a:vt}netrw_optionsave
1804
1805 if exists("+acd")
1806 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001807" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001808 let curdir = getcwd()
1809 let &l:acd = {a:vt}netrw_acdkeep
1810 unlet {a:vt}netrw_acdkeep
1811 if &l:acd
1812 call s:NetrwLcd(curdir)
1813 endif
1814 endif
1815 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001816" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001817 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1818 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1819 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1820 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1821 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001822" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001823 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1824 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1825 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1826 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1827 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001828" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001829 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1830 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1831 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1832 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1833 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001834 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001835" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1836 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1837 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
1838 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&l:go")
1839 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1840" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1841 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1842 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1843" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1844 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1845" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1846 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1847 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001848 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001849 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1850 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1851" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1852 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1853 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1854 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1855 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1856" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001857 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1859 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1860 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001862" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001863 call s:NetrwRestoreSetting("s:yykeep","@@")
1864 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1865 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1866 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1867 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1868
Bram Moolenaara6878372014-03-22 21:02:50 +01001869 if exists("{a:vt}netrw_swfkeep")
1870 if &directory == ""
1871 " user hasn't specified a swapfile directory;
1872 " netrw will temporarily set the swapfile directory
1873 " to the current directory as returned by getcwd().
1874 let &l:directory= getcwd()
1875 sil! let &l:swf = {a:vt}netrw_swfkeep
1876 setl directory=
1877 unlet {a:vt}netrw_swfkeep
1878 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001879 if !g:netrw_use_noswf
1880 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1881 sil! let &l:swf= {a:vt}netrw_swfkeep
1882 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001883 unlet {a:vt}netrw_swfkeep
1884 endif
1885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001886 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001887 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1888 if exists("{a:vt}netrw_dirkeep")
1889 call s:NetrwLcd(dirkeep)
1890 unlet {a:vt}netrw_dirkeep
1891 endif
1892 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001893 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001894" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001895 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1896 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001897 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001898 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001899
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001900" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1901" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1902" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1903" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1904" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001905 " Moved the filetype detect here from NetrwGetFile() because remote files
1906 " were having their filetype detect-generated settings overwritten by
1907 " NetrwOptionRestore.
1908 if &ft != "netrw"
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001909 if !isdirectory(expand('%'))
1910" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1911 filetype detect
1912" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1913 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001914 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001915" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001916" 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 +02001917" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001918endfun
1919
1920" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001921" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1922" but only when the options' value and the safe setting differ
1923" Doing this means that netrw will not come up as having changed a
1924" setting last when it really didn't actually change it.
1925"
1926" Called from s:NetrwOptionsSafe
1927" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1928fun! s:NetrwSetSafeSetting(setting,safesetting)
1929" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001930
Bram Moolenaar85850f32019-07-19 22:05:51 +02001931 if a:setting =~ '^&'
1932" call Decho("fyi: a:setting starts with &")
1933 exe "let settingval= ".a:setting
1934" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001935
Bram Moolenaar85850f32019-07-19 22:05:51 +02001936 if settingval != a:safesetting
1937" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1938 if type(a:safesetting) == 0
1939 exe "let ".a:setting."=".a:safesetting
1940 elseif type(a:safesetting) == 1
1941 exe "let ".a:setting."= '".a:safesetting."'"
1942 else
1943 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1944 endif
1945 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001946 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001947
Bram Moolenaar85850f32019-07-19 22:05:51 +02001948" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001949endfun
1950
1951" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001952" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1953" but only if the setting value differs from the associated keepvar.
1954" Doing this means that netrw will not come up as having changed a
1955" setting last when it really didn't actually change it.
1956"
1957" Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
1958" keepvars are set up by s:NetrwOptionsSave
1959fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001960""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001961
Bram Moolenaar85850f32019-07-19 22:05:51 +02001962 " typically called from s:NetrwOptionsRestore
1963 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1964 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001965 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001966 if exists(a:keepvar)
1967 exe "let keepvarval= ".a:keepvar
1968 exe "let setting= ".a:setting
1969
1970"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1971"" call Decho("fyi: keepvarval=".keepvarval)
1972"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1973
1974 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001975"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001976 if type(a:setting) == 0
1977 exe "let ".a:setting."= ".keepvarval
1978 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001979 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001980 else
1981 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1982 endif
1983 endif
1984
1985 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001986 endif
1987
Bram Moolenaar85850f32019-07-19 22:05:51 +02001988"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001989endfun
1990
1991" ---------------------------------------------------------------------
1992" NetrwStatusLine: {{{2
1993fun! NetrwStatusLine()
1994
1995" vvv NetrwStatusLine() debugging vvv
1996" let g:stlmsg=""
1997" if !exists("w:netrw_explore_bufnr")
1998" let g:stlmsg="!X<explore_bufnr>"
1999" elseif w:netrw_explore_bufnr != bufnr("%")
2000" let g:stlmsg="explore_bufnr!=".bufnr("%")
2001" endif
2002" if !exists("w:netrw_explore_line")
2003" let g:stlmsg=" !X<explore_line>"
2004" elseif w:netrw_explore_line != line(".")
2005" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2006" endif
2007" if !exists("w:netrw_explore_list")
2008" let g:stlmsg=" !X<explore_list>"
2009" endif
2010" ^^^ NetrwStatusLine() debugging ^^^
2011
2012 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")
2013 " restore user's status line
2014 let &stl = s:netrw_users_stl
2015 let &laststatus = s:netrw_users_ls
2016 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2017 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2018 return ""
2019 else
2020 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2021 endif
2022endfun
2023
Bram Moolenaar85850f32019-07-19 22:05:51 +02002024" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002025" Netrw Transfer Functions: {{{1
2026" ===============================
2027
Bram Moolenaar071d4272004-06-13 20:20:40 +00002028" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002029" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002030" mode: =0 read remote file and insert before current line
2031" =1 read remote file and insert after current line
2032" =2 replace with remote file
2033" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002034fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002035" 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 +00002036
Bram Moolenaar5c736222010-01-06 20:54:52 +01002037 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002038 call s:NetrwOptionsSave("w:")
2039 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002040 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002041 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2042 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2043 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002044" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045
Bram Moolenaar5c736222010-01-06 20:54:52 +01002046 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002047 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002048 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002049 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002050 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051 elseif a:mode == 2 " replace with remote file
2052 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002053 elseif a:mode == 3 " skip read of file (leave as temporary)
2054 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002055 else
2056 exe a:mode
2057 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002058 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002059 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002060" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002061
Bram Moolenaar5c736222010-01-06 20:54:52 +01002062 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002063 let tmpfile= s:GetTempfile("")
2064 if tmpfile == ""
2065" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002066 return
2067 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002068
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002071 " attempt to repeat with previous host-file-etc
2072 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002073" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002074 let choice = b:netrw_lastfile
2075 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002076
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 else
2078 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002079" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002080
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002082 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002083 echomsg 'NetRead Usage:'
2084 echomsg ':Nread machine:path uses rcp'
2085 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2086 echomsg ':Nread "machine id password path" uses ftp'
2087 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2088 echomsg ':Nread fetch://machine/path uses fetch'
2089 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2090 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002091 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002092 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002093 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2094 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2095 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2096 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002097 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002098 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002099
Bram Moolenaar9964e462007-05-05 17:54:07 +00002100 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002101 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002102" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002103 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002104 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002105 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 else
2107 " case "... ... ..."
2108 let choice = strpart(choice,1,strlen(choice)-1)
2109 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002110
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 let wholechoice = wholechoice . " " . choice
2113 let ichoice = ichoice + 1
2114 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002115 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002116 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002117 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002118" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002119 return
2120 endif
2121 let choice= a:{ichoice}
2122 endwhile
2123 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2124 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 endif
2126 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002128" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002129 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002130
Bram Moolenaar5c736222010-01-06 20:54:52 +01002131 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002132 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002133 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002134" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002135 return
2136 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002137 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002138
Bram Moolenaar8d043172014-01-23 14:24:41 +01002139 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002140" 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 +02002141 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002142" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002143 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002144" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002145 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002147
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002148 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002149 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002150 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002151 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2152 echo "(netrw) Processing your read request..."
2153 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002154
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002156 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002158" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002159 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002161 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 " ER: the tmpfile is full path: rcp sees C:\... as host C
2163 if s:netrw_has_nt_rcp == 1
2164 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2165 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2166 else
2167 " Any way needed it machine contains a '.'
2168 let uid_machine = g:netrw_machine .'.'. $USERNAME
2169 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2172 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2173 else
2174 let uid_machine = g:netrw_machine
2175 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002176 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002177 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 +00002178 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002179 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002180
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002181 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002182 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002184" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002185 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002186 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002187 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002188 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002189 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002190" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002191 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002194 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002195 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002196" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002197 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002198 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 +00002199 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 endif
2202 " 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 +00002203 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002204 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002205 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002206 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002207 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002209 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002210 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002211 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2212 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002213 q!
2214 endif
2215 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002216 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002217 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002218
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002220 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002221 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2222 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002223" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002224 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002225 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002226 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002227 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002229 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002230" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002231 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002232 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002233" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002235
Bram Moolenaar97d62492012-11-15 21:28:22 +01002236 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002237 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002238 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002239" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002240 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002241 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002242 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002243" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002244 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002246" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002249
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002250 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002251 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002252" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002253 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002254 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002255 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002256" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002257 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002258 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002259" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002260
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 " perform ftp:
2262 " -i : turns off interactive prompting from ftp
2263 " -n unix : DON'T use <.netrc>, even though it exists
2264 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002265 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002267 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2268 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002269" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002270 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002271 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002272 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002274 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002275 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002276 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002277
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002279 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002281" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002283 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 else
2285 let useport= ""
2286 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002287 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2288 " This is workaround to avoid mis-handle windows local-path:
2289 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2290 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2291 else
2292 let tmpfile_get = tmpfile
2293 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002294 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 +00002295 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002296 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002297
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002298 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002299 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002300 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002301" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002303 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002304 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002305 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002306" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002307 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002308 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002309
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002310 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2311 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002312" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002313 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002314 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 +00002315 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316 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 +00002317 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002318 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002319
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002320 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002321 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002322" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002323 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2324 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2326" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2327 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 +00002328 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002329" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002330 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 endif
2332 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002334 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002335
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002336 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002337 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002338 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002339" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002340
Bram Moolenaar5c736222010-01-06 20:54:52 +01002341 if !executable(g:netrw_dav_cmd)
2342 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2343" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2344 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002345 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002346 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002347 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 +01002348 else
2349 " Construct execution string (four lines) which will be passed through filter
2350 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2351 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002352 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002354 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002355 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002356 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002358 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002359 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002360 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2362 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002363
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002365 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002366 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002367 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002369 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002370 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002371
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002372 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002373 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002374 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002376 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 +00002377 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002379
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002381 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002382 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002383 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002384" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002385 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002386 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002387 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002388 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002389" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002390 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002392 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 let netrw_option= "http"
2394 else
2395 let netrw_option= "ftp"
2396 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002397" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002398
Bram Moolenaar446cb832008-06-24 21:56:24 +00002399 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002400 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 +00002401 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002402 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 +00002403 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002404
Bram Moolenaar446cb832008-06-24 21:56:24 +00002405 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002407" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002408 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002409
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002410 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002411 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002412 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002413" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2414 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 +00002415 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002417
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002418 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002419 " NetRead: (file) NetRead Method #10 {{{3
2420 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002421" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2422 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002423 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2424 let b:netrw_lastfile = choice
2425
2426 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002427 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002428 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002429 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002430 endif
2431 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002432
Bram Moolenaar5c736222010-01-06 20:54:52 +01002433 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002434 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002435" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002436 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 unlet b:netrw_fname
2438 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002439 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 +01002440" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002441 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002442 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002443 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002444
Bram Moolenaar9964e462007-05-05 17:54:07 +00002445" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002446endfun
2447
2448" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002449" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002450fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002451" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002452
Bram Moolenaar5c736222010-01-06 20:54:52 +01002453 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002454 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002455 call s:NetrwOptionsSave("w:")
2456 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002457
Bram Moolenaar5c736222010-01-06 20:54:52 +01002458 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002459 let tmpfile= s:GetTempfile("")
2460 if tmpfile == ""
2461" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002462 return
2463 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002464
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002465 if a:0 == 0
2466 let ichoice = 0
2467 else
2468 let ichoice = 1
2469 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002470
Bram Moolenaar9964e462007-05-05 17:54:07 +00002471 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002472" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002473 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474 " For binary writes, always write entire file.
2475 " (line numbers don't really make sense for that).
2476 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002477" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002478 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002479 elseif g:netrw_cygwin
2480 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002481 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002482" 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 +01002483 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002484 else
2485 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002486" 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 +01002487 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002488 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002489
Bram Moolenaar9964e462007-05-05 17:54:07 +00002490 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002491 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002492 " on the temporary file's name. Deletion of the temporary file during
2493 " cleanup then causes an error message.
2494 0file!
2495 endif
2496
Bram Moolenaar5c736222010-01-06 20:54:52 +01002497 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002498 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002499
Bram Moolenaar9964e462007-05-05 17:54:07 +00002500 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002501 " attempt to repeat with previous host-file-etc
2502 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002503" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002504 let choice = b:netrw_lastfile
2505 let ichoice= ichoice + 1
2506 else
2507 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002508
Bram Moolenaar8d043172014-01-23 14:24:41 +01002509 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002511 echomsg 'NetWrite Usage:"'
2512 echomsg ':Nwrite machine:path uses rcp'
2513 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2514 echomsg ':Nwrite "machine id password path" uses ftp'
2515 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2516 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2517 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2518 echomsg ':Nwrite rcp://machine/path uses rcp'
2519 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2520 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2521 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002522 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002523 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002524
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002525 elseif match(choice,"^\"") != -1
2526 if match(choice,"\"$") != -1
2527 " case "..."
2528 let choice=strpart(choice,1,strlen(choice)-2)
2529 else
2530 " case "... ... ..."
2531 let choice = strpart(choice,1,strlen(choice)-1)
2532 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002533
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 while match(choice,"\"$") == -1
2535 let wholechoice= wholechoice . " " . choice
2536 let ichoice = ichoice + 1
2537 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002538 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002539 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002540 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002541" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002542 return
2543 endif
2544 let choice= a:{ichoice}
2545 endwhile
2546 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2547 endif
2548 endif
2549 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002550 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002551" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002552
Bram Moolenaar9964e462007-05-05 17:54:07 +00002553 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002554 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002555 if !exists("b:netrw_method") || b:netrw_method < 0
2556" call Dfunc("netrw#NetWrite : unsupported method")
2557 return
2558 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002559
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002560 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002561 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002562 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002563 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2564 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002565" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002566 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002567
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002568 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002569 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002570 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002571" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002572 if s:netrw_has_nt_rcp == 1
2573 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2574 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2575 else
2576 let uid_machine = g:netrw_machine .'.'. $USERNAME
2577 endif
2578 else
2579 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2580 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2581 else
2582 let uid_machine = g:netrw_machine
2583 endif
2584 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002585 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 +00002586 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002587
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002588 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002589 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002590 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002591" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002592 let netrw_fname = b:netrw_fname
2593
2594 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2595 let bhkeep = &l:bh
2596 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002597 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002598 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002599
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002601 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002602 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002604 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002605 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002607 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002608 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611 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 +00002612 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2614 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 endif
2616 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2617 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002618 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002619 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002620 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002621 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002623
2624 " remove enew buffer (quietly)
2625 let filtbuf= bufnr("%")
2626 exe curbuf."b!"
2627 let &l:bh = bhkeep
2628 exe filtbuf."bw!"
2629
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002631
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002632 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002633 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002634 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002635 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002636" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002637 let netrw_fname = b:netrw_fname
2638 let bhkeep = &l:bh
2639
2640 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2641 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002642 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002643 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002644 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002645
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002646 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002647 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002648" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002650 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002653 if exists("g:netrw_uid") && g:netrw_uid != ""
2654 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002655 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002656" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002657 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002661 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002662 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002663" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002665 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002668 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002670" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002671 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002672 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002674 " save choice/id/password for future use
2675 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002676
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002677 " perform ftp:
2678 " -i : turns off interactive prompting from ftp
2679 " -n unix : DON'T use <.netrc>, even though it exists
2680 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002681 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002682 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002683 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2684 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002685 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002686 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002687 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 let mod=1
2689 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002690
2691 " remove enew buffer (quietly)
2692 let filtbuf= bufnr("%")
2693 exe curbuf."b!"
2694 let &l:bh= bhkeep
2695 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002696
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002697 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002698 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002699 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002700" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002701 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002702 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002703 else
2704 let useport= ""
2705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706 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 +00002707 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002708
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002709 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002710 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002711 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002712" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002713 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2714 if executable(curl)
2715 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002716 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 +01002717 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002718 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002719 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002720
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002721 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002722 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002723 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002724" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002725
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002726 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002727 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2728 let bhkeep = &l:bh
2729
2730 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2731 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002732 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002733 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002734
Bram Moolenaarff034192013-04-24 18:51:19 +02002735 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002736 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002737 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002738 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002739 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002740 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002741 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002742 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002743 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002744 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002745
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002746 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002747 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002749
2750 " remove enew buffer (quietly)
2751 let filtbuf= bufnr("%")
2752 exe curbuf."b!"
2753 let &l:bh = bhkeep
2754 exe filtbuf."bw!"
2755
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002756 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002757
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002758 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002759 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002760 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002761" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002762 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 +00002763 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002764
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002765 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002766 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002767 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002768" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002769 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2771 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2772 else
2773 let uid_machine = g:netrw_machine
2774 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002775
2776 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2777 let bhkeep = &l:bh
2778 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002779 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002780 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002781
Bram Moolenaarff034192013-04-24 18:51:19 +02002782 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002783 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002784" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002785 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002787 let filtbuf= bufnr("%")
2788 exe curbuf."b!"
2789 let &l:bh = bhkeep
2790 exe filtbuf."bw!"
2791 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002792
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002793 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002794 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002795 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002796 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002797 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002799 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002800
Bram Moolenaar5c736222010-01-06 20:54:52 +01002801 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002802" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002803 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002804" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002805 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002807 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002808
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002809 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002810 " restore modifiability; usually equivalent to set nomod
2811 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002812" 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 +02002813 elseif !exists("leavemod")
2814 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002816 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" 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 +00002818 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002819
Bram Moolenaar9964e462007-05-05 17:54:07 +00002820" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002821endfun
2822
2823" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002824" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002825" uses NetRead to get a copy of the file into a temporarily file,
2826" then sources that file,
2827" then removes that file.
2828fun! netrw#NetSource(...)
2829" call Dfunc("netrw#NetSource() a:0=".a:0)
2830 if a:0 > 0 && a:1 == '?'
2831 " give help
2832 echomsg 'NetSource Usage:'
2833 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2834 echomsg ':Nsource fetch://machine/path uses fetch'
2835 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002836 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002837 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2838 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2839 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2840 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2841 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002842 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002843 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002844 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002845 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002846" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002848" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002849 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002850" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002851 if delete(s:netrw_tmpfile)
2852 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2853 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 unlet s:netrw_tmpfile
2855 else
2856 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2857 endif
2858 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002859 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002860 endif
2861" call Dret("netrw#NetSource")
2862endfun
2863
Bram Moolenaar8d043172014-01-23 14:24:41 +01002864" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002865" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2866" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002867fun! netrw#SetTreetop(iscmd,...)
2868" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2869" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002870
Bram Moolenaar85850f32019-07-19 22:05:51 +02002871 " iscmd==0: netrw#SetTreetop called using gn mapping
2872 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2873" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002874 " clear out the current tree
2875 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002876" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002877 let inittreetop= w:netrw_treetop
2878 unlet w:netrw_treetop
2879 endif
2880 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002881" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002882 unlet w:netrw_treedict
2883 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002884" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002885
Bram Moolenaar85850f32019-07-19 22:05:51 +02002886 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002887 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002889 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002890 if isdirectory(s:NetrwFile(a:1))
2891" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002892 let treedir = a:1
2893 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002895 let treedir = b:netrw_curdir."/".a:1
2896 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002897" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002898 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899 " normally the cursor is left in the message window.
2900 " However, here this results in the directory being listed in the message window, which is not wanted.
2901 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002902 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002904 let treedir = "."
2905 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002906 endif
2907 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002908" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002909
2910 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911 let islocal= expand("%") !~ '^\a\{3,}://'
2912" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002913
2914 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002915 if islocal
2916 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2917 else
2918 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2919 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002920
Bram Moolenaara6878372014-03-22 21:02:50 +01002921" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002922endfun
2923
Bram Moolenaar9964e462007-05-05 17:54:07 +00002924" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002925" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002926" readcmd == %r : replace buffer with newly read file
2927" == 0r : read file at top of buffer
2928" == r : read file after current line
2929" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002930fun! s:NetrwGetFile(readcmd, tfile, method)
2931" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932
2933 " readcmd=='t': simply do nothing
2934 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002935" 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 +01002936" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002937 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002938 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002939
Bram Moolenaar9964e462007-05-05 17:54:07 +00002940 " get name of remote filename (ie. url and all)
2941 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002942" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002943
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944 if exists("*NetReadFixup")
2945 " for the use of NetReadFixup (not otherwise used internally)
2946 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002947 endif
2948
Bram Moolenaar9964e462007-05-05 17:54:07 +00002949 if a:readcmd[0] == '%'
2950 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002951" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002952
2953 " rename the current buffer to the temp file (ie. tfile)
2954 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002955 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002956 else
2957 let tfile= a:tfile
2958 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002959 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960
2961 " edit temporary file (ie. read the temporary file in)
2962 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002963" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002964 call zip#Browse(tfile)
2965 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002968 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002969" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002970 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002971 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002974 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002976 call tar#Browse(tfile)
2977 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002978" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002980 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002982 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002983 endif
2984
2985 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002986 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002987
Bram Moolenaar97d62492012-11-15 21:28:22 +01002988 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002989 " Note that isk must not include a "/" for scripts.vim
2990 " to process this detection correctly.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002991" call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002992 let iskkeep= &l:isk
2993 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002994 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002995" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002996 let line1 = 1
2997 let line2 = line("$")
2998
Bram Moolenaar8d043172014-01-23 14:24:41 +01002999 elseif !&ma
3000 " 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 +01003001 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003002" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003003 return
3004
Bram Moolenaar9964e462007-05-05 17:54:07 +00003005 elseif s:FileReadable(a:tfile)
3006 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003007" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003008 let curline = line(".")
3009 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003010" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003011 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003012 let line1= curline + 1
3013 let line2= line("$") - lastline + 1
3014
3015 else
3016 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3018" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003019 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003020" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003021 return
3022 endif
3023
3024 " User-provided (ie. optional) fix-it-up command
3025 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003026" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003027 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003028" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003029" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003030 endif
3031
Bram Moolenaaradc21822011-04-01 18:03:16 +02003032 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003033 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003034 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003035 endif
3036
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003037" 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 +00003038
3039 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003040" redraw!
3041
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003042" 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 +00003043" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003044endfun
3045
Bram Moolenaar9964e462007-05-05 17:54:07 +00003046" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003047" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003048" Input:
3049" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3050" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003051" b:netrw_method= 1: rcp
3052" 2: ftp + <.netrc>
3053" 3: ftp + machine, id, password, and [path]filename
3054" 4: scp
3055" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003056" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003057" 7: rsync
3058" 8: fetch
3059" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003060" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003061" g:netrw_machine= hostname
3062" b:netrw_fname = filename
3063" g:netrw_port = optional port number (for ftp)
3064" g:netrw_choice = copy of input url (choice)
3065fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003066" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003067
Bram Moolenaar251e1912011-06-19 05:09:16 +02003068 " sanity check: choice should have at least three slashes in it
3069 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3070 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3071 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003072" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003073 return
3074 endif
3075
Bram Moolenaar5c736222010-01-06 20:54:52 +01003076 " record current g:netrw_machine, if any
3077 " curmachine used if protocol == ftp and no .netrc
3078 if exists("g:netrw_machine")
3079 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003080" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003081 else
3082 let curmachine= "N O T A HOST"
3083 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003084 if exists("g:netrw_port")
3085 let netrw_port= g:netrw_port
3086 endif
3087
3088 " insure that netrw_ftp_cmd starts off every method determination
3089 " with the current g:netrw_ftp_cmd
3090 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003091
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003092 " initialization
3093 let b:netrw_method = 0
3094 let g:netrw_machine = ""
3095 let b:netrw_fname = ""
3096 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003097 let g:netrw_choice = a:choice
3098
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003099 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003100 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003101 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3102 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003103 " rcpurm : rcp://[user@]host/filename Use rcp
3104 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003105 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003106 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003107 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003108 " rsyncurm : rsync://host[:port]/path Use rsync
3109 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3110 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003111 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3113 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003114 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3115 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003117 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003118 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003119 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003120 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003121 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003123 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003124
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003125" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003127 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003128 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003129" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003130 let b:netrw_method = 1
3131 let userid = substitute(a:choice,rcpurm,'\1',"")
3132 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3133 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 if userid != ""
3135 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003137
Bram Moolenaaradc21822011-04-01 18:03:16 +02003138 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003140" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003141 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003142 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3143 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3144 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003145
Bram Moolenaar15146672011-10-20 22:22:38 +02003146 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003148" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003149 let b:netrw_method = 5
3150 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3151 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003152 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003153
Bram Moolenaaradc21822011-04-01 18:03:16 +02003154 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003155 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003156" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003157 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003158 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003159 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3160 else
3161 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3162 endif
3163 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003164
Bram Moolenaaradc21822011-04-01 18:03:16 +02003165 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003166 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003167" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003168 let b:netrw_method = 7
3169 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3170 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003171
Bram Moolenaaradc21822011-04-01 18:03:16 +02003172 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003173 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003174" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003175 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3177 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3178 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003179" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 if userid != ""
3181 let g:netrw_uid= userid
3182 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003183
Bram Moolenaaradc21822011-04-01 18:03:16 +02003184 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003185 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003186 call NetUserPass("ftp:".g:netrw_machine)
3187 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003188 " if there's a change in hostname, require password re-entry
3189 unlet s:netrw_passwd
3190 endif
3191 if exists("netrw_port")
3192 unlet netrw_port
3193 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003194 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003195
Bram Moolenaar446cb832008-06-24 21:56:24 +00003196 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003197 let b:netrw_method = 3
3198 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003199 let host= substitute(g:netrw_machine,'\..*$','','')
3200 if exists("s:netrw_hup[host]")
3201 call NetUserPass("ftp:".host)
3202
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003203 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003204" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3205" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003206 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003207 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003208" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003209 endif
3210 let b:netrw_method= 2
3211 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003212" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003213 let b:netrw_method= 2
3214 else
3215 if !exists("g:netrw_uid") || g:netrw_uid == ""
3216 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003217 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003218 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003219 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003220 endif
3221 let b:netrw_method= 3
3222 endif
3223 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003224
Bram Moolenaaradc21822011-04-01 18:03:16 +02003225 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003227" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003228 let b:netrw_method = 8
3229 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3230 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3231 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3232 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003233
Bram Moolenaaradc21822011-04-01 18:03:16 +02003234 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003236" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003238 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3239 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003240 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003241 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003242 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003243
Bram Moolenaaradc21822011-04-01 18:03:16 +02003244 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003245 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003246" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003247 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 let b:netrw_method = 3
3249 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3250 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003251
Bram Moolenaar9964e462007-05-05 17:54:07 +00003252 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003253 let b:netrw_method = 2
3254 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3255 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3256 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003257
Bram Moolenaaradc21822011-04-01 18:03:16 +02003258 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003259 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003260" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003261 let b:netrw_method = 9
3262 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3263 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003264
Bram Moolenaaradc21822011-04-01 18:03:16 +02003265 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003266 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003267" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003268 let b:netrw_method = 1
3269 let userid = substitute(a:choice,rcphf,'\2',"")
3270 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3271 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003272" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3273" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3274" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3275" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003276 if userid != ""
3277 let g:netrw_uid= userid
3278 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003279
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003280 " Method#10: file://user@hostname/...path-to-file {{{3
3281 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003282" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003283 let b:netrw_method = 10
3284 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003285" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003286
Bram Moolenaaradc21822011-04-01 18:03:16 +02003287 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003288 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003289 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003290 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003291 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003292 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003294 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003295
Bram Moolenaar81695252004-12-29 20:58:21 +00003296 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003297 " remove any leading [:#] from port number
3298 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3299 elseif exists("netrw_port")
3300 " retain port number as implicit for subsequent ftp operations
3301 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003302 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003303
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003304" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3305" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3306" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3307" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003308" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003309" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003310" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003311" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003312" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003313" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003314" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003315" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317
3318" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003319" NetReadFixup: this sort of function is typically written by the user {{{2
3320" to handle extra junk that their system's ftp dumps
3321" into the transfer. This function is provided as an
3322" example and as a fix for a Windows 95 problem: in my
3323" experience, win95's ftp always dumped four blank lines
3324" at the end of the transfer.
3325if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3326 fun! NetReadFixup(method, line1, line2)
3327" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003328
3329 " sanity checks -- attempt to convert inputs to integers
3330 let method = a:method + 0
3331 let line1 = a:line1 + 0
3332 let line2 = a:line2 + 0
3333 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3334" call Dret("NetReadFixup")
3335 return
3336 endif
3337
Bram Moolenaar9964e462007-05-05 17:54:07 +00003338 if method == 3 " ftp (no <.netrc>)
3339 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003340 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003341 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003342 call histdel("/",-1)
3343 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003344 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003345
Bram Moolenaar9964e462007-05-05 17:54:07 +00003346" call Dret("NetReadFixup")
3347 endfun
3348endif
3349
3350" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003351" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003352" Usage: :call NetUserPass() -- will prompt for userid and password
3353" :call NetUserPass("uid") -- will prompt for password
3354" :call NetUserPass("uid","password") -- sets global userid and password
3355" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3356" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357fun! NetUserPass(...)
3358
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003359" call Dfunc("NetUserPass() a:0=".a:0)
3360
3361 if !exists('s:netrw_hup')
3362 let s:netrw_hup= {}
3363 endif
3364
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003366 " case: no input arguments
3367
3368 " change host and username if not previously entered; get new password
3369 if !exists("g:netrw_machine")
3370 let g:netrw_machine= input('Enter hostname: ')
3371 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003373 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 let g:netrw_uid= input('Enter username: ')
3375 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003376 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003377 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003378
3379 " set up hup database
3380 let host = substitute(g:netrw_machine,'\..*$','','')
3381 if !exists('s:netrw_hup[host]')
3382 let s:netrw_hup[host]= {}
3383 endif
3384 let s:netrw_hup[host].uid = g:netrw_uid
3385 let s:netrw_hup[host].passwd = s:netrw_passwd
3386
3387 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003388 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003389
3390 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003391 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003392 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003393" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003394 let host = substitute(a:1,'^ftp:','','')
3395 let host = substitute(host,'\..*','','')
3396 if exists("s:netrw_hup[host]")
3397 let g:netrw_uid = s:netrw_hup[host].uid
3398 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003399" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3400" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003401 else
3402 let g:netrw_uid = input("Enter UserId: ")
3403 let s:netrw_passwd = inputsecret("Enter Password: ")
3404 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003405
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003406 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003407 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003408" 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 +02003409 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003410 if g:netrw_machine =~ '[0-9.]\+'
3411 let host= g:netrw_machine
3412 else
3413 let host= substitute(g:netrw_machine,'\..*$','','')
3414 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003415 else
3416 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003417 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003418 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003419" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003420 if exists("g:netrw_passwd")
3421 " ask for password if one not previously entered
3422 let s:netrw_passwd= g:netrw_passwd
3423 else
3424 let s:netrw_passwd = inputsecret("Enter Password: ")
3425 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003426 endif
3427
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003428" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003429 if exists("host")
3430 if !exists('s:netrw_hup[host]')
3431 let s:netrw_hup[host]= {}
3432 endif
3433 let s:netrw_hup[host].uid = g:netrw_uid
3434 let s:netrw_hup[host].passwd = s:netrw_passwd
3435 endif
3436
3437 elseif a:0 == 2
3438 let g:netrw_uid = a:1
3439 let s:netrw_passwd = a:2
3440
3441 elseif a:0 == 3
3442 " enter hostname, user-id, and password into the hup dictionary
3443 let host = substitute(a:1,'^\a\+:','','')
3444 let host = substitute(host,'\..*$','','')
3445 if !exists('s:netrw_hup[host]')
3446 let s:netrw_hup[host]= {}
3447 endif
3448 let s:netrw_hup[host].uid = a:2
3449 let s:netrw_hup[host].passwd = a:3
3450 let g:netrw_uid = s:netrw_hup[host].uid
3451 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003452" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3453" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003455
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003456" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458
Bram Moolenaar85850f32019-07-19 22:05:51 +02003459" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003460" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003461" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003463" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003464" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3465fun! s:ExplorePatHls(pattern)
3466" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3467 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003468" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003469 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003470" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003471 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3472" call Dret("s:ExplorePatHls repat<".repat.">")
3473 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003474endfun
3475
3476" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003477" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003478" 0: (user: <mb>) bookmark current directory
3479" 1: (user: <gb>) change to the bookmarked directory
3480" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003481" 3: (browsing) records current directory history
3482" 4: (user: <u>) go up (previous) directory, using history
3483" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003484" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003485fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003486" 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 +02003487 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3488" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3489 return
3490 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003491
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003492 let ykeep = @@
3493 let curbufnr = bufnr("%")
3494
Bram Moolenaar9964e462007-05-05 17:54:07 +00003495 if a:chg == 0
3496 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003497" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003498 if exists("s:netrwmarkfilelist_{curbufnr}")
3499 call s:NetrwBookmark(0)
3500 echo "bookmarked marked files"
3501 else
3502 call s:MakeBookmark(a:curdir)
3503 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003505
3506 elseif a:chg == 1
3507 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003508" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003509 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003510" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003511 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003512 else
3513 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3514 endif
3515
3516 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003517" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003518 let didwork= 0
3519 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003520" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003521 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003522" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003523 let cnt= 1
3524 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003525" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003526 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003527 let didwork = 1
3528 let cnt = cnt + 1
3529 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003530 endif
3531
3532 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003533 " Note: history is saved only when PerformListing is done;
3534 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3535 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003536 let first = 1
3537 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003538 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003539 while ( first || cnt != g:netrw_dirhistcnt )
3540" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003541 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003542" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003543 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003544 let didwork= 1
3545 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003546 let histcnt = histcnt + 1
3547 let first = 0
3548 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003549 if cnt < 0
3550 let cnt= cnt + g:netrw_dirhistmax
3551 endif
3552 endwhile
3553 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003554 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003555 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003556 if didwork
3557 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3558 endif
3559
3560 elseif a:chg == 3
3561 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003562" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563 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 +02003564 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003565 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3566 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003567 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003568" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003569 endif
3570
3571 elseif a:chg == 4
3572 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003573" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003574 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003575 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3576 if g:netrw_dirhistcnt < 0
3577 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003578 endif
3579 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003580 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003581 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003582 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3583" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003584 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003585 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003586" call Decho("setl ma noro",'~'.expand("<slnum>"))
3587 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003588 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003589" call Decho("setl nomod",'~'.expand("<slnum>"))
3590" 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 +00003591 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003592" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3593 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003594 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003595 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003596 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003597 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003598 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003599 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003600 echo "Sorry, no predecessor directory exists yet"
3601 endif
3602
3603 elseif a:chg == 5
3604 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003605" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003606 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003607 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3608 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3609" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003610 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003611" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003612 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003613 sil! NetrwKeepj %d _
3614" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3615" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003616 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003617" 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 +02003618 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003619" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3620 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003621 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003622 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3623 if g:netrw_dirhistcnt < 0
3624 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003625 endif
3626 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003627 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003628 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003629 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003630 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003631 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003632
3633 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003634" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003635 if exists("s:netrwmarkfilelist_{curbufnr}")
3636 call s:NetrwBookmark(1)
3637 echo "removed marked files from bookmarks"
3638 else
3639 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003640 let iremove = v:count
3641 let dremove = g:netrw_bookmarklist[iremove - 1]
3642" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003643 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003644" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3645 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3646 echo "removed ".dremove." from g:netrw_bookmarklist"
3647" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003648 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003649" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003650 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003651 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003652 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003653 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003654" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003655endfun
3656
3657" ---------------------------------------------------------------------
3658" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003659" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003660" Sister function: s:NetrwBookHistSave()
3661fun! s:NetrwBookHistRead()
3662" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003663 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003664" 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 +02003665 return
3666 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003667 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003668
3669 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003670 if !exists("s:netrw_initbookhist")
3671 let home = s:NetrwHome()
3672 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003673 if filereadable(s:NetrwFile(savefile))
3674" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003675 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003676 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003677
3678 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003679 if g:netrw_dirhistmax > 0
3680 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003681 if filereadable(s:NetrwFile(savefile))
3682" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003683 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003684 endif
3685 let s:netrw_initbookhist= 1
3686 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003687 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003688 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003689
Bram Moolenaar97d62492012-11-15 21:28:22 +01003690 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3692" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693" call Dret("s:NetrwBookHistRead")
3694endfun
3695
3696" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003697" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698" Sister function: s:NetrwBookHistRead()
3699" I used to do this via viminfo but that appears to
3700" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003701" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3702" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003703" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003704fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003705" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003706 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003707" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003708 return
3709 endif
3710
Bram Moolenaar5c736222010-01-06 20:54:52 +01003711 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003713 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003714
3715 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003716 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003717" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003718 if g:netrw_use_noswf
3719 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3720 else
3721 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3722 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003723 setl nocin noai noci magic nospell nohid wig= noaw
3724 setl ma noro write
3725 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003726 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003727
Bram Moolenaar85850f32019-07-19 22:05:51 +02003728 " rename enew'd file: .netrwhist -- no attempt to merge
3729 " record dirhistmax and current dirhistcnt
3730 " save history
3731" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003732 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003733 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003734 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3735 if g:netrw_dirhistmax > 0
3736 let lastline = line("$")
3737 let cnt = g:netrw_dirhistcnt
3738 let first = 1
3739 while ( first || cnt != g:netrw_dirhistcnt )
3740 let lastline= lastline + 1
3741 if exists("g:netrw_dirhist_{cnt}")
3742 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3743" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3744 endif
3745 let first = 0
3746 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3747 if cnt < 0
3748 let cnt= cnt + g:netrw_dirhistmax
3749 endif
3750 endwhile
3751 exe "sil! w! ".savefile
3752" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3753 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754
Bram Moolenaar85850f32019-07-19 22:05:51 +02003755 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003756 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003757 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003758" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003759 " merge and write .netrwbook
3760 let savefile= s:NetrwHome()."/.netrwbook"
3761
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003762 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003763 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003764 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003765 for bdm in booklist
3766 if index(g:netrw_bookmarklist,bdm) == -1
3767 call add(g:netrw_bookmarklist,bdm)
3768 endif
3769 endfor
3770 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003771 endif
3772
3773 " construct and save .netrwbook
3774 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003775 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003776" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003777 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003778
3779 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003780 let bgone= bufnr("%")
3781 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003782 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003783
3784" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003785endfun
3786
3787" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003788" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3789" list of the contents of a local or remote directory. It is assumed that the
3790" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3791" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003792" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003793fun! s:NetrwBrowse(islocal,dirname)
3794 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003795" 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 +02003796" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3797" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3798" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003799
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003800 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3801 " This is useful when one edits a local file, then :e ., then :Rex
3802 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3803 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003804" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003805 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003806
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003807 " s:NetrwBrowse : initialize history {{{3
3808 if !exists("s:netrw_initbookhist")
3809 NetrwKeepj call s:NetrwBookHistRead()
3810 endif
3811
3812 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003813 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003814 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003815" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003816 else
3817 let dirname= a:dirname
3818 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003819
Bram Moolenaar85850f32019-07-19 22:05:51 +02003820 " repoint t:netrw_lexbufnr if appropriate
3821 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3822" call Decho("set repointlexbufnr to true!")
3823 let repointlexbufnr= 1
3824 endif
3825
3826 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003827 if exists("s:netrw_skipbrowse")
3828 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003829" 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 +01003830" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003831 return
3832 endif
3833 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835" call Dret("s:NetrwBrowse : missing shellescape()")
3836 return
3837 endif
3838 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003839 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003840" call Dret("s:NetrwBrowse : missing fnameescape()")
3841 return
3842 endif
3843
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003844 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003845 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003846
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003847 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003848 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3849 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3850" call Decho("clearing marked files",'~'.expand("<slnum>"))
3851 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3852 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853 endif
3854
3855 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003857" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3858" 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 +02003859 if s:NetrwLcd(dirname)
3860" call Dret("s:NetrwBrowse : lcd failure")
3861 return
3862 endif
3863 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003864" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003865
Bram Moolenaar5c736222010-01-06 20:54:52 +01003866 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003867 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003868" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003869 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003871 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003872 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003873 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003874" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003875
3876 " remove any filetype indicator from end of dirname, except for the
3877 " "this is a directory" indicator (/).
3878 " There shouldn't be one of those here, anyway.
3879 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003880" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 call s:RemotePathAnalysis(dirname)
3882
3883 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3884 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003885 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003886 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003887" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003888 let b:netrw_curdir = dirname
3889 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003890 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003891 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3892 sil call netrw#NetRead(2,url)
3893 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003894" call Decho("url<".url.">",'~'.expand("<slnum>"))
3895" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3896" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003897 if s:path =~ '.bz2'
3898 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3899 elseif s:path =~ '.gz'
3900 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3901 elseif s:path =~ '.gz'
3902 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3903 else
3904 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3905 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003906 endif
3907
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003908 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003909 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003910 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003911" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003912 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003913" 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 +00003914
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915" call Dret("s:NetrwBrowse : file<".s:fname.">")
3916 return
3917 endif
3918
Bram Moolenaaradc21822011-04-01 18:03:16 +02003919 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 call s:UseBufWinVars()
3921
3922 " set up some variables {{{3
3923 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003924 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003925 let s:last_sort_by = g:netrw_sort_by
3926
3927 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003928 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929
Bram Moolenaar97d62492012-11-15 21:28:22 +01003930 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003931" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003932 let svpos = winsaveview()
3933" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935
Bram Moolenaar446cb832008-06-24 21:56:24 +00003936 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003937 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3938 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3939" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3940" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3941 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3942 else
3943" " call Decho("2match none",'~'.expand("<slnum>"))
3944 2match none
3945 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003946 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003947 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003948 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003949" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003950 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003951" 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 +01003952" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 return
3954 endif
3955
3956 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003957" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003958 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003959 if b:netrw_curdir =~ '[/\\]$'
3960 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3961 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003962 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3963 let b:netrw_curdir= b:netrw_curdir."/"
3964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003965 if b:netrw_curdir == ''
3966 if has("amiga")
3967 " On the Amiga, the empty string connotes the current directory
3968 let b:netrw_curdir= getcwd()
3969 else
3970 " under unix, when the root directory is encountered, the result
3971 " from the preceding substitute is an empty string.
3972 let b:netrw_curdir= '/'
3973 endif
3974 endif
3975 if !a:islocal && b:netrw_curdir !~ '/$'
3976 let b:netrw_curdir= b:netrw_curdir.'/'
3977 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003978" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003979
3980 " ------------
3981 " (local only) {{{3
3982 " ------------
3983 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003984" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003985
3986 " Set up ShellCmdPost handling. Append current buffer to browselist
3987 call s:LocalFastBrowser()
3988
3989 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3990 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003991" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3992" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003994 if s:NetrwLcd(b:netrw_curdir)
3995" call Dret("s:NetrwBrowse : lcd failure")
3996 return
3997 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003998 endif
3999 endif
4000
4001 " --------------------------------
4002 " remote handling: {{{3
4003 " --------------------------------
4004 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004006
Bram Moolenaar97d62492012-11-15 21:28:22 +01004007 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004008" 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 +02004009 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004010 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004011" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004012 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4013 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4014 if dirname !~ '/$'
4015 let dirname= dirname.'/'
4016 endif
4017 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004019 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004020 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004021" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004022 endif
4023
4024 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4025 if dirname !~ dirpat
4026 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004027 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004028 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004029 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004030" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004031 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032" 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 +00004033" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4034 return
4035 endif
4036 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004037" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004038 endif " (additional remote handling)
4039
Bram Moolenaar85850f32019-07-19 22:05:51 +02004040 " -------------------------------
4041 " Perform Directory Listing: {{{3
4042 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004043 NetrwKeepj call s:NetrwMaps(a:islocal)
4044 NetrwKeepj call s:NetrwCommands(a:islocal)
4045 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004047 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004048 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004049" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4050
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004051 " If there is a rexposn: restore position with rexposn
4052 " Otherwise : set rexposn
4053 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004054" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4055 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4056 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4057 NetrwKeepj exe w:netrw_bannercnt
4058 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059 else
4060 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4061 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004062 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004063 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004064" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004065 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004066 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004067
Bram Moolenaar85850f32019-07-19 22:05:51 +02004068 " repoint t:netrw_lexbufnr if appropriate
4069 if exists("repointlexbufnr")
4070 let t:netrw_lexbufnr= bufnr("%")
4071" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4072 endif
4073
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004074 " restore position
4075 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004076" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4077 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004078 endif
4079
Bram Moolenaara6878372014-03-22 21:02:50 +01004080 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4082 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004083" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4084" 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 +02004085" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004086 return
4087endfun
4088
4089" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004090" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4091" may not apply correctly; ie. netrw's idea of the current directory may
4092" differ from vim's. This function insures that netrw's idea of the current
4093" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004094" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004095fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004096" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4097" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4098" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4099" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4100" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004101
4102 " clean up any leading treedepthstring
4103 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4104 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004105" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004106 else
4107 let fname= a:fname
4108 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109
4110 if g:netrw_keepdir
4111 " vim's idea of the current directory possibly may differ from netrw's
4112 if !exists("b:netrw_curdir")
4113 let b:netrw_curdir= getcwd()
4114 endif
4115
4116 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004118 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004119 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004120" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004121 else
4122 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004123 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004124" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004125 endif
4126
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004127 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004129 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004130" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131 else
4132 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004133 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004134" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004135 endif
4136 else
4137 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004138 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004139" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4140" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4141" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004142 endif
4143
Bram Moolenaar85850f32019-07-19 22:05:51 +02004144" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004145 return ret
4146endfun
4147
4148" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149" s:NetrwFileInfo: supports qf (query for file information) {{{2
4150fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004151" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004152 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004153 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004154 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004155 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004156 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004157 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004158 let lsopt= "-lsadh --si"
4159 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004160" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004161 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004162
4163 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004164 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004166
Bram Moolenaara6878372014-03-22 21:02:50 +01004167 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004168 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004169" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004170
4171 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004172 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004174
Bram Moolenaar446cb832008-06-24 21:56:24 +00004175 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004176" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004177 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004178" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179 endif
4180 else
4181 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004182" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4183 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004184 let fname= substitute(a:fname,".$","","")
4185 else
4186 let fname= a:fname
4187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004188 let t = getftime(s:NetrwFile(fname))
4189 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004190 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004191 let sz= s:NetrwHumanReadable(sz)
4192 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004193 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4194" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004195 endif
4196 else
4197 echo "sorry, \"qf\" not supported yet for remote files"
4198 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004199 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004200" call Dret("s:NetrwFileInfo")
4201endfun
4202
4203" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004204" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4205fun! s:NetrwFullPath(filename)
4206" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4207 let filename= a:filename
4208 if filename !~ '^/'
4209 let filename= resolve(getcwd().'/'.filename)
4210 endif
4211 if filename != "/" && filename =~ '/$'
4212 let filename= substitute(filename,'/$','','')
4213 endif
4214" " call Dret("s:NetrwFullPath <".filename.">")
4215 return filename
4216endfun
4217
4218" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004219" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004220" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004221" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004222" 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 +00004223fun! s:NetrwGetBuffer(islocal,dirname)
4224" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004225" 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 +02004226" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4227" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004228 let dirname= a:dirname
4229
4230 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004231" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004232 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004233" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004234 let s:netrwbuf= {}
4235 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004236" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4237" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4238
4239 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4240 let bufnum = -1
4241
4242 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4243 if has_key(s:netrwbuf,"NetrwTreeListing")
4244 let bufnum= s:netrwbuf["NetrwTreeListing"]
4245 else
4246 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4247 endif
4248" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4249 if !bufexists(bufnum)
4250 call remove(s:netrwbuf,"NetrwTreeListing"])
4251 let bufnum= -1
4252 endif
4253 elseif bufnr("NetrwTreeListing") != -1
4254 let bufnum= bufnr("NetrwTreeListing")
4255" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4256 else
4257" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4258 let bufnum= -1
4259 endif
4260
4261 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004262 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004263" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004264 if !bufexists(bufnum)
4265 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4266 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004267 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004268
Bram Moolenaar446cb832008-06-24 21:56:24 +00004269 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004270" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004271 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004272 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004273" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4274
Bram Moolenaar6c391a72021-09-09 21:55:11 +02004275 " hijack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004276 " IF the buffer already has the desired name
4277 " AND it is empty
4278 let curbuf = bufname("%")
4279 if curbuf == '.'
4280 let curbuf = getcwd()
4281 endif
4282" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar6c391a72021-09-09 21:55:11 +02004283" call Decho("deciding if netrw may hijack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004284" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4285" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4286" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4287" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4288 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004289" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4290 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004291 else " DEBUG
Bram Moolenaar6c391a72021-09-09 21:55:11 +02004292" call Decho("..did NOT hijack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004293 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004294 " 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 +00004295
4296 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004297 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004298" 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 +00004299 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004300" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004301 " name the buffer
4302 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4303 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004304" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004305 let w:netrw_treebufnr = bufnr("%")
4306 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004307 if g:netrw_use_noswf
4308 setl nobl bt=nofile noswf
4309 else
4310 setl nobl bt=nofile
4311 endif
4312 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4313 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4314 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4315 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004316" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004318 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004319 " enter the new buffer into the s:netrwbuf dictionary
4320 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4321" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4322" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004324" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325
4326 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004327" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004329 setl ei=all
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004330 if getline(2) =~# '^" Netrw Directory Listing'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004331" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
4332 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004334" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
4335 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004336 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004338 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004339 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 endif
4341 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004342
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004343 if line("$") <= 1 && getline(1) == ""
4344 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004345 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004346" 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>"))
4347" 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 +01004348" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4349 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004350
Bram Moolenaar97d62492012-11-15 21:28:22 +01004351 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004352" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004353 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004354 sil NetrwKeepj %d _
4355" 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>"))
4356" 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 +01004357" 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 +00004358 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004359
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004361" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4362" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004363 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004365 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004366" 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>"))
4367" 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 +01004368" 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 +00004369 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004370
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004372" 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>"))
4373" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4374" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 return 1
4376 endif
4377 endif
4378
4379 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4380 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4381 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4382 " med 1 D H
4383 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004384" 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 +00004385 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004386 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004387 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388
4389 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004390" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4391" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4392 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004393
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004394" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4395" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4396" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004397 return 0
4398endfun
4399
4400" ---------------------------------------------------------------------
4401" s:NetrwGetcwd: get the current directory. {{{2
4402" Change backslashes to forward slashes, if any.
4403" If doesc is true, escape certain troublesome characters
4404fun! s:NetrwGetcwd(doesc)
4405" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4406 let curdir= substitute(getcwd(),'\\','/','ge')
4407 if curdir !~ '[\/]$'
4408 let curdir= curdir.'/'
4409 endif
4410 if a:doesc
4411 let curdir= fnameescape(curdir)
4412 endif
4413" call Dret("NetrwGetcwd <".curdir.">")
4414 return curdir
4415endfun
4416
4417" ---------------------------------------------------------------------
4418" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4419fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004420" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4421" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4422 let keepsol= &l:sol
4423 setl nosol
4424
Bram Moolenaar446cb832008-06-24 21:56:24 +00004425 call s:UseBufWinVars()
4426
4427 " insure that w:netrw_liststyle is set up
4428 if !exists("w:netrw_liststyle")
4429 if exists("g:netrw_liststyle")
4430 let w:netrw_liststyle= g:netrw_liststyle
4431 else
4432 let w:netrw_liststyle= s:THINLIST
4433 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004434" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004435 endif
4436
4437 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4438 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004439" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004440 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441 let dirname= "./"
4442 let curline= getline('.')
4443
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004444 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004445 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004446 let s:netrw_skipbrowse= 1
4447 echo 'Pressing "s" also works'
4448
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004449 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450 let s:netrw_skipbrowse= 1
4451 echo 'Press "S" to edit sorting sequence'
4452
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004453 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004454 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004456
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004457 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004458 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004459 let s:netrw_skipbrowse= 1
4460 echo 'Pressing "a" also works'
4461
4462 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004463 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004464 endif
4465
4466 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004467" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004468 NetrwKeepj norm! 0
4469 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004470
4471 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004472" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004473 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004474 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4475
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004476 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004477" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004478 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004479 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004480
4481 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004482" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004483 let dirname= getline('.')
4484
4485 if !exists("b:netrw_cpf")
4486 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004487 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 +01004488 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004489" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 endif
4491
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004492" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004494" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4495" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004497 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004498 else
4499 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004500 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004501 endif
4502 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004503 let eofname= filestart + b:netrw_cpf + 1
4504 if eofname <= col("$")
4505 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004506 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004507 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004508 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004509 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510 let dirname = @a
4511 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004514" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004515 endif
4516
4517 " symlinks are indicated by a trailing "@". Remove it before further processing.
4518 let dirname= substitute(dirname,"@$","","")
4519
4520 " executables are indicated by a trailing "*". Remove it before further processing.
4521 let dirname= substitute(dirname,"\*$","","")
4522
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004523 let &l:sol= keepsol
4524
Bram Moolenaar446cb832008-06-24 21:56:24 +00004525" call Dret("s:NetrwGetWord <".dirname.">")
4526 return dirname
4527endfun
4528
4529" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004530" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4531" g:netrw_bufsettings will be used after the listing is produced.
4532" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004533fun! s:NetrwListSettings(islocal)
4534" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004535" 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 +00004536 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004537" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4538 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4539 setl bt=nofile nobl ma nonu nowrap noro nornu
4540 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004541 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004542 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004544" call Dredir("ls!","s:NetrwListSettings")
4545" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004546 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004547 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004549 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004550 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004551 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004553" 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 +00004554" call Dret("s:NetrwListSettings")
4555endfun
4556
4557" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004558" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559" islocal=0: remote browsing
4560" =1: local browsing
4561fun! s:NetrwListStyle(islocal)
4562" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004563
Bram Moolenaar97d62492012-11-15 21:28:22 +01004564 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004565 let fname = s:NetrwGetWord()
4566 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004567 let svpos = winsaveview()
4568" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004569 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004570" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4571" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4572" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004573
Bram Moolenaar85850f32019-07-19 22:05:51 +02004574 " repoint t:netrw_lexbufnr if appropriate
4575 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4576" call Decho("set repointlexbufnr to true!")
4577 let repointlexbufnr= 1
4578 endif
4579
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 if w:netrw_liststyle == s:THINLIST
4581 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004582" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4584
4585 elseif w:netrw_liststyle == s:LONGLIST
4586 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004587" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004588 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4589
4590 elseif w:netrw_liststyle == s:WIDELIST
4591 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004592" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004593 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4594
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004595 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004596" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004597 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4598
4599 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004600 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004601 let g:netrw_liststyle = s:THINLIST
4602 let w:netrw_liststyle = g:netrw_liststyle
4603 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4604 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004605 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004606" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004607
4608 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004609" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4610 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004611 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004613 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004614" 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 +00004615
4616 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004617" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004618 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004619 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004620
Bram Moolenaar85850f32019-07-19 22:05:51 +02004621 " repoint t:netrw_lexbufnr if appropriate
4622 if exists("repointlexbufnr")
4623 let t:netrw_lexbufnr= bufnr("%")
4624" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4625 endif
4626
Bram Moolenaar13600302014-05-22 18:26:40 +02004627 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004628" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4629 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004630 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004631
4632" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4633endfun
4634
4635" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004636" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4637fun! s:NetrwBannerCtrl(islocal)
4638" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4639
Bram Moolenaar97d62492012-11-15 21:28:22 +01004640 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004641 " toggle the banner (enable/suppress)
4642 let g:netrw_banner= !g:netrw_banner
4643
4644 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004645 let svpos= winsaveview()
4646" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004647 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4648
4649 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004650 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4651 let fname= s:NetrwGetWord()
4652 sil NetrwKeepj $
4653 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4654" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4655 if result <= 0 && exists("w:netrw_bannercnt")
4656 exe "NetrwKeepj ".w:netrw_bannercnt
4657 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004658 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004659 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004660" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4661endfun
4662
4663" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004664" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4665"
4666" No bang: enters files/directories into Netrw's bookmark system
4667" No argument and in netrw buffer:
4668" if there are marked files: bookmark marked files
4669" otherwise : bookmark file/directory under cursor
4670" No argument and not in netrw buffer: bookmarks current open file
4671" Has arguments: globs them individually and bookmarks them
4672"
4673" With bang: deletes files/directories from Netrw's bookmark system
4674fun! s:NetrwBookmark(del,...)
4675" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4676 if a:0 == 0
4677 if &ft == "netrw"
4678 let curbufnr = bufnr("%")
4679
4680 if exists("s:netrwmarkfilelist_{curbufnr}")
4681 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004682" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004683 let svpos = winsaveview()
4684" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004685 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004686 for fname in s:netrwmarkfilelist_{curbufnr}
4687 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4688 endfor
4689 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4690 call s:NetrwUnmarkList(curbufnr,curdir)
4691 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004692" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4693 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004694 else
4695 let fname= s:NetrwGetWord()
4696 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4697 endif
4698
4699 else
4700 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004701" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004702 let fname= expand("%")
4703 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4704 endif
4705
4706 else
4707 " bookmark specified files
4708 " attempts to infer if working remote or local
4709 " by deciding if the current file begins with an url
4710 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004711 let islocal= expand("%") !~ '^\a\{3,}://'
4712" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004713 let i = 1
4714 while i <= a:0
4715 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004716 if v:version > 704 || (v:version == 704 && has("patch656"))
4717 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004718 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004719 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004720 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004721 else
4722 let mbfiles= [a:{i}]
4723 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004724" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004725 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004726" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004727 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4728 endfor
4729 let i= i + 1
4730 endwhile
4731 endif
4732
4733 " update the menu
4734 call s:NetrwBookmarkMenu()
4735
4736" call Dret("s:NetrwBookmark")
4737endfun
4738
4739" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004740" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4741" .2.[cnt] for bookmarks, and
4742" .3.[cnt] for history
4743" (see s:NetrwMenu())
4744fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004745 if !exists("s:netrw_menucnt")
4746 return
4747 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004748" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004749
4750 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004751 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004752 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004753" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004754 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4755 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004756 endif
4757 if !exists("s:netrw_initbookhist")
4758 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004759 endif
4760
4761 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004762 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004763 let cnt= 1
4764 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004765" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004766 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004767
4768 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004769 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004770
4771 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004772 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 +01004773 let cnt= cnt + 1
4774 endfor
4775
4776 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777
4778 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004780 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 let first = 1
4782 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004783 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004785 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004786 if exists("g:netrw_dirhist_{cnt}")
4787 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004788" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004789 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4790 endif
4791 let first = 0
4792 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4793 if cnt < 0
4794 let cnt= cnt + g:netrw_dirhistmax
4795 endif
4796 endwhile
4797 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004798
Bram Moolenaar9964e462007-05-05 17:54:07 +00004799 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004800" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004801endfun
4802
4803" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004804" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4805" directory and a new directory name. Also, if the
4806" "new directory name" is actually a file,
4807" NetrwBrowseChgDir() edits the file.
4808fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004809" 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 +01004810" 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 +00004811
Bram Moolenaar97d62492012-11-15 21:28:22 +01004812 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004813 if !exists("b:netrw_curdir")
4814 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4815 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004816 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004817" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4818" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004819" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004820" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004821 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004822 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004823" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004824
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004825 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004826" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004827 call s:SavePosn(s:netrw_posn)
4828 NetrwKeepj call s:NetrwOptionsSave("s:")
4829 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004830 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004831 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004832 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004833 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004834 endif
4835 let newdir = a:newdir
4836 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004837 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004838" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004839" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004840" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004841
4842 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004843" 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 +01004844 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004845" 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 +01004846 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004847 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004848" 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 +01004849 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" 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 +02004851 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004852 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004853 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004854 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004855" 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 +01004856 endif
4857 endif
4858" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004859" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004860 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004861
Bram Moolenaar446cb832008-06-24 21:56:24 +00004862 " set up o/s-dependent directory recognition pattern
4863 if has("amiga")
4864 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004865 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004866 let dirpat= '[\/]$'
4867 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004868" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004869
4870 if dirname !~ dirpat
4871 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004872 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004874" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004875 endif
4876
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004877" 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 +01004878 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004879 " ------------------------------
4880 " NetrwBrowseChgDir: edit a file {{{3
4881 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004882" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004883
Bram Moolenaar97d62492012-11-15 21:28:22 +01004884 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004885 let s:rexposn_{bufnr("%")}= winsaveview()
4886" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004887" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4888" 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 +01004889
Bram Moolenaar446cb832008-06-24 21:56:24 +00004890 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004891" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4892" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004893" let newdir = s:NetrwTreePath(s:netrw_treetop)
4894" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004895 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004896 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4897" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4898 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004899 if dirname =~ '/$'
4900 let dirname= dirname.newdir
4901 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004902 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004904" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4905" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004907" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004908 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004909 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004911 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004912" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004913 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004915" 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 +02004916 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004917 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004918 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004919" " 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 +01004920 if type(g:netrw_browse_split) == 3
4921 " open file in server
4922 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004923" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004924 call s:NetrwServerEdit(a:islocal,dirname)
4925" call Dret("s:NetrwBrowseChgDir")
4926 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004927
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004928 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004929 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004930" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004931 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4932 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004933 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004934 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004935 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004936 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004937
Bram Moolenaar446cb832008-06-24 21:56:24 +00004938 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004939 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004940" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004941 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4942 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004943 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004944 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004945 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004946 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004947
Bram Moolenaar446cb832008-06-24 21:56:24 +00004948 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004949 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004950" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004951 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004952 if !exists("b:netrw_curdir")
4953 let b:netrw_curdir= getcwd()
4954 endif
4955 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004956
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004958 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004959" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004960 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004961 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004962" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004963 return
4964 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004965 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004966
Bram Moolenaar9964e462007-05-05 17:54:07 +00004967 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004969" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004970 call s:NetrwMenu(0)
4971 " optional change to window
4972 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004973" 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 +02004974 if winnr("$")+1 == g:netrw_chgwin
4975 " if g:netrw_chgwin is set to one more than the last window, then
4976 " vertically split the last window to make that window available.
4977 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004978 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004979 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004980 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004981 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004982 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004983 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004984 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004985 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004986
Bram Moolenaar9964e462007-05-05 17:54:07 +00004987 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004988
Bram Moolenaar446cb832008-06-24 21:56:24 +00004989 " the point where netrw actually edits the (local) file
4990 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004991 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004992 if !&mod
4993 " if e the new file would fail due to &mod, then don't change any of the flags
4994 let dolockout= 1
4995 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004996 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004997" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004998 " some like c-^ to return to the last edited file
4999 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005000 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5001 " so emit error E37 instead.
Bram Moolenaar8d043172014-01-23 14:24:41 +01005002 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005003 exe "NetrwKeepj keepalt e ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01005004 else
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005005 exe "NetrwKeepj e ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01005006 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005007" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005008 " COMBAK -- cuc cul related
5009 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005010 if &hidden || &bufhidden == "hide"
5011 " file came from vim's hidden storage. Don't "restore" options with it.
5012 let dorestore= 0
5013 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005014 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005015" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005016 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005017
5018 " handle g:Netrw_funcref -- call external-to-netrw functions
5019 " This code will handle g:Netrw_funcref as an individual function reference
5020 " or as a list of function references. It will ignore anything that's not
5021 " a function reference. See :help Funcref for information about function references.
5022 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005023" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005026 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005027 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005028" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005029 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005030 if type(Fncref) == 2
5031 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005032 endif
5033 endfor
5034 endif
5035 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005036 endif
5037
5038 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005039 " ----------------------------------------------------
5040 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5041 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005042" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005043 let dirname = newdir
5044 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005045 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005046 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005047
5048 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005049 " ---------------------------------------------
5050 " NetrwBrowseChgDir: refresh the directory list {{{3
5051 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005052" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005053 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005054 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005055
5056 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005057 " --------------------------------------
5058 " NetrwBrowseChgDir: go up one directory {{{3
5059 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005060" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061
5062 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5063 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005064" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5065" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005066 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005067 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068 endif
5069
5070 if has("amiga")
5071 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005072" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005073 if a:islocal
5074 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5075 let dirname= substitute(dirname,'/$','','')
5076 else
5077 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5078 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005079" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080
Bram Moolenaar8d043172014-01-23 14:24:41 +01005081 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5082 " windows
5083 if a:islocal
5084 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5085 if dirname == ""
5086 let dirname= '/'
5087 endif
5088 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005089 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005090 endif
5091 if dirname =~ '^\a:$'
5092 let dirname= dirname.'/'
5093 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005094" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005095
Bram Moolenaar446cb832008-06-24 21:56:24 +00005096 else
5097 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005098" 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 +00005099 if a:islocal
5100 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5101 if dirname == ""
5102 let dirname= '/'
5103 endif
5104 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005107" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005108 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005109 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005110 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005111
5112 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005113 " --------------------------------------
5114 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5115 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005116" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005117 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5118" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005119 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5122 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005123 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005124 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005125" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005126 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005127 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005128" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129
5130 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005131" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005133" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134 let haskey= 1
5135 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005136" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 endif
5138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005139 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005140" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005141 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 if has_key(w:netrw_treedict,treedir."/")
5143 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005144" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005145 let haskey = 1
5146 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005147" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 endif
5149 endif
5150
5151 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005152" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005153 if !haskey && treedir =~ '/$'
5154 let treedir= substitute(treedir,'/$','','')
5155 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005156" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005157 let haskey = 1
5158 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005159" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 endif
5161 endif
5162
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 if haskey
5165 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005166" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005168" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5169" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005170 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 else
5172 " go down one directory
5173 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005174" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5175" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005176 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005177 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005178" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005179 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005180
5181 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005182 " ----------------------------------------
5183 " NetrwBrowseChgDir: Go down one directory {{{3
5184 " ----------------------------------------
5185 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005186" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005187 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005188 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005189 endif
5190
Bram Moolenaar97d62492012-11-15 21:28:22 +01005191 " --------------------------------------
5192 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5193 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005194 if dorestore
5195 " dorestore is zero'd when a local file was hidden or bufhidden;
5196 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005198 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005199" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005201 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005202 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005204 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5206" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005207 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005208" 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 +02005209 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005210" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5211" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005212 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005213" 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 +02005214 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005215 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005216 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005217 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005218
Bram Moolenaar446cb832008-06-24 21:56:24 +00005219" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5220 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005221endfun
5222
5223" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005224" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5225" for thin, long, and wide: cursor placed just after banner
5226" for tree, keeps cursor on current filename
5227fun! s:NetrwBrowseUpDir(islocal)
5228" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005229 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5230 " this test needed because occasionally this function seems to be incorrectly called
5231 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005232 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005233 " directories.
5234" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5235 return
5236 endif
5237
Bram Moolenaara6878372014-03-22 21:02:50 +01005238 norm! 0
5239 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005240" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005241 let curline= getline(".")
5242 let swwline= winline() - 1
5243 if exists("w:netrw_treetop")
5244 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005245 elseif exists("b:netrw_curdir")
5246 let w:netrw_treetop= b:netrw_curdir
5247 else
5248 let w:netrw_treetop= getcwd()
5249 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005250 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005251 let curfile = getline(".")
5252 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005253 if a:islocal
5254 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5255 else
5256 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5257 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005258" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5259" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5260 if w:netrw_treetop == '/'
5261 keepj call search('^\M'.curfile,"w")
5262 elseif curfile == '../'
5263 keepj call search('^\M'.curfile,"wb")
5264 else
5265" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5266 while 1
5267 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5268 let treepath= s:NetrwTreePath(w:netrw_treetop)
5269" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5270 if treepath == curpath
5271 break
5272 endif
5273 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005274 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275
Bram Moolenaara6878372014-03-22 21:02:50 +01005276 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005277" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005278 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005279 if exists("b:netrw_curdir")
5280 let curdir= b:netrw_curdir
5281 else
5282 let curdir= expand(getcwd())
5283 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005284 if a:islocal
5285 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5286 else
5287 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5288 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005289 call s:RestorePosn(s:netrw_posn)
5290 let curdir= substitute(curdir,'^.*[\/]','','')
5291 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005292 endif
5293" call Dret("s:NetrwBrowseUpDir")
5294endfun
5295
5296" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005297" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005298" given filename; typically this means given their extension.
5299" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005300fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005301 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005302" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005303
Bram Moolenaar91359012019-11-30 17:57:03 +01005304 if a:remote == 0 && isdirectory(a:fname)
5305 " if its really just a local directory, then do a "gf" instead
5306" 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 +01005307" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5308 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005309" call Dret("netrw#BrowseX")
5310 return
5311 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5312 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5313" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5314" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5315" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5316" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5317 norm! gf
5318" call Dret("netrw#BrowseX")
5319 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005320 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005321" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005322
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005323 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5324 let remote = a:remote
5325 else
5326 let remote = 0
5327 endif
5328
Bram Moolenaar97d62492012-11-15 21:28:22 +01005329 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005330 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005331" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005332
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005333 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5334 let awkeep = &aw
5335 set noaw
5336
Bram Moolenaar5c736222010-01-06 20:54:52 +01005337 " special core dump handler
5338 if a:fname =~ '/core\(\.\d\+\)\=$'
5339 if exists("g:Netrw_corehandler")
5340 if type(g:Netrw_corehandler) == 2
5341 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005342" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005343 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005344 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005346" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005347 for Fncref in g:Netrw_corehandler
5348 if type(FncRef) == 2
5349 call FncRef(a:fname)
5350 endif
5351 endfor
5352 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005353" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005354 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005355 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005356 let &aw= awkeep
5357" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005358 return
5359 endif
5360 endif
5361
Bram Moolenaar446cb832008-06-24 21:56:24 +00005362 " set up the filename
5363 " (lower case the extension, make a local copy of a remote file)
5364 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5365 if has("win32") || has("win95") || has("win64") || has("win16")
5366 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005367 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005368 if exten =~ "[\\/]"
5369 let exten= ""
5370 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005371" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005372
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005373 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005374 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005375" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005376 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005377 call netrw#NetRead(3,a:fname)
5378 " attempt to rename tempfile
5379 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005380 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005381" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5382" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005383 if s:netrw_tmpfile != newname && newname != ""
5384 if rename(s:netrw_tmpfile,newname) == 0
5385 " renaming succeeded
5386" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5387 let fname= newname
5388 else
5389 " renaming failed
5390" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5391 let fname= s:netrw_tmpfile
5392 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005393 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005394 let fname= s:netrw_tmpfile
5395 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005396 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005397" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005398 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005399 " special ~ handler for local
5400 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005401" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5402 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005403 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005404 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005405" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5406" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005407
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005408 " set up redirection (avoids browser messages)
5409 " by default, g:netrw_suppress_gx_mesg is true
5410 if g:netrw_suppress_gx_mesg
5411 if &srr =~ "%s"
5412 if (has("win32") || has("win95") || has("win64") || has("win16"))
5413 let redir= substitute(&srr,"%s","nul","")
5414 else
5415 let redir= substitute(&srr,"%s","/dev/null","")
5416 endif
5417 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5418 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005420 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005421 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005423" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005425 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005426 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005427" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005428 if g:netrw_browsex_viewer =~ '\s'
5429 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5430 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5431 let oviewer = ''
5432 let cnt = 1
5433 while !executable(viewer) && viewer != oviewer
5434 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5435 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5436 let cnt = cnt + 1
5437 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005438" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005439 endwhile
5440 else
5441 let viewer = g:netrw_browsex_viewer
5442 let viewopt = ""
5443 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005444" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 endif
5446
5447 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005448" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005449 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005450" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 let ret= netrwFileHandlers#Invoke(exten,fname)
5452
5453 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005454" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005455 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 let ret= v:shell_error
5457
5458 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005459" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005460 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005461 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005462 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005463 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005464 else
5465 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5466 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005467 let ret= v:shell_error
5468
Bram Moolenaar97d62492012-11-15 21:28:22 +01005469 elseif has("win32unix")
5470 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005471" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005472 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005473" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005474 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005475 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005476" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005477 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005478 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005479" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005480 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005481 else
5482 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5483 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005484 let ret= v:shell_error
5485
Bram Moolenaar85850f32019-07-19 22:05:51 +02005486 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005487" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5488 if a:fname =~ '^https\=://'
5489 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5490 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005491" call Decho("fname<".fname.">")
5492" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005493 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5494
5495 else
5496 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5497 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005498 let ret= v:shell_error
5499
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005500 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5501" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5502 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5503 let ret= v:shell_error
5504
5505 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5506" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5507 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5508 let ret= v:shell_error
5509
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005510 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005511" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005512 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005513 let ret= v:shell_error
5514
5515 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005516" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005517 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005518 let ret= v:shell_error
5519
5520 else
5521 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005522" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005523 let ret= netrwFileHandlers#Invoke(exten,fname)
5524 endif
5525
5526 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5527 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005528" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005529 let ret= netrwFileHandlers#Invoke(exten,fname)
5530 endif
5531
Bram Moolenaarc236c162008-07-13 17:41:49 +00005532 " restoring redraw! after external file handlers
5533 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005534
5535 " cleanup: remove temporary file,
5536 " delete current buffer if success with handler,
5537 " return to prior buffer (directory listing)
5538 " Feb 12, 2008: had to de-activiate removal of
5539 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005540" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005541"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005542" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543" endif
5544
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005545 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005546 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005547 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005548 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005550 if use_ctrlo
5551 exe "sil! NetrwKeepj norm! \<c-o>"
5552 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005554" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005555 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005556 let @@ = ykeep
5557 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005558
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005559" call Dret("netrw#BrowseX")
5560endfun
5561
5562" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005563" netrw#GX: gets word under cursor for gx support {{{2
5564" See also: netrw#BrowseXVis
5565" netrw#BrowseX
5566fun! netrw#GX()
5567" call Dfunc("netrw#GX()")
5568 if &ft == "netrw"
5569 let fname= s:NetrwGetWord()
5570 else
5571 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5572 endif
5573" call Dret("netrw#GX <".fname.">")
5574 return fname
5575endfun
5576
5577" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005578" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5579fun! netrw#BrowseXVis()
5580" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005581 let akeep = @a
5582 norm! gv"ay
5583 let gxfile= @a
5584 let @a = akeep
5585 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005586" call Dret("netrw#BrowseXVis")
5587endfun
5588
5589" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005590" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5591" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5592" to become an unlisted buffer, so in that case don't bwipe it.
5593fun! s:NetrwBufRename(newname)
5594" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5595" call Dredir("ls!","s:NetrwBufRename (before rename)")
5596 let oldbufname= bufname(bufnr("%"))
5597" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5598
5599 if oldbufname != a:newname
5600" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5601 let b:junk= 1
5602" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5603 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005604" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005605 let oldbufnr= bufnr(oldbufname)
5606" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5607" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5608 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5609" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5610 exe "bwipe! ".oldbufnr
5611" else " Decho
5612" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005613" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5614" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5615" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005616 endif
5617" call Dredir("ls!","s:NetrwBufRename (after rename)")
5618" else " Decho
5619" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5620 endif
5621
5622" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5623endfun
5624
5625" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005626" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005627fun! netrw#CheckIfRemote(...)
5628" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5629 if a:0 > 0
5630 let curfile= a:1
5631 else
5632 let curfile= expand("%")
5633 endif
5634" call Decho("curfile<".curfile.">")
5635 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005636" call Dret("netrw#CheckIfRemote 1")
5637 return 1
5638 else
5639" call Dret("netrw#CheckIfRemote 0")
5640 return 0
5641 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005642endfun
5643
5644" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005645" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5646fun! s:NetrwChgPerm(islocal,curdir)
5647" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005648 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005649 call inputsave()
5650 let newperm= input("Enter new permission: ")
5651 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005652 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5653 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5654" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005655 call system(chgperm)
5656 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005657 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005658 endif
5659 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005660 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005661 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005662 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005663" call Dret("s:NetrwChgPerm")
5664endfun
5665
5666" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005667" s:CheckIfKde: checks if kdeinit is running {{{2
5668" Returns 0: kdeinit not running
5669" 1: kdeinit is running
5670fun! s:CheckIfKde()
5671" call Dfunc("s:CheckIfKde()")
5672 " seems kde systems often have gnome-open due to dependencies, even though
5673 " gnome-open's subsidiary display tools are largely absent. Kde systems
5674 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5675 if !exists("s:haskdeinit")
5676 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005677 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005678 if v:shell_error
5679 let s:haskdeinit = 0
5680 endif
5681 else
5682 let s:haskdeinit= 0
5683 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005684" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005685 endif
5686
5687" call Dret("s:CheckIfKde ".s:haskdeinit)
5688 return s:haskdeinit
5689endfun
5690
5691" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005692" s:NetrwClearExplore: clear explore variables (if any) {{{2
5693fun! s:NetrwClearExplore()
5694" call Dfunc("s:NetrwClearExplore()")
5695 2match none
5696 if exists("s:explore_match") |unlet s:explore_match |endif
5697 if exists("s:explore_indx") |unlet s:explore_indx |endif
5698 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5699 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5700 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5701 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5702 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5703 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5704 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5705" redraw!
5706 echo " "
5707 echo " "
5708" call Dret("s:NetrwClearExplore")
5709endfun
5710
5711" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005712" s:NetrwExploreListUniq: {{{2
5713fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005714" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005715
5716 " this assumes that the list is already sorted
5717 let newexplist= []
5718 for member in a:explist
5719 if !exists("uniqmember") || member != uniqmember
5720 let uniqmember = member
5721 let newexplist = newexplist + [ member ]
5722 endif
5723 endfor
5724
Bram Moolenaar15146672011-10-20 22:22:38 +02005725" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005726 return newexplist
5727endfun
5728
5729" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005730" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5731fun! s:NetrwForceChgDir(islocal,newdir)
5732" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005733 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005734 if a:newdir !~ '/$'
5735 " ok, looks like force is needed to get directory-style treatment
5736 if a:newdir =~ '@$'
5737 let newdir= substitute(a:newdir,'@$','/','')
5738 elseif a:newdir =~ '[*=|\\]$'
5739 let newdir= substitute(a:newdir,'.$','/','')
5740 else
5741 let newdir= a:newdir.'/'
5742 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005743" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005744 else
5745 " should already be getting treatment as a directory
5746 let newdir= a:newdir
5747 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005748 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005749 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005750 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005751" call Dret("s:NetrwForceChgDir")
5752endfun
5753
5754" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005755" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005756" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5757" expr : this is the expression to follow the directory. Will use s:ComposePath()
5758" pare =1: remove the current directory from the resulting glob() filelist
5759" =0: leave the current directory in the resulting glob() filelist
5760fun! s:NetrwGlob(direntry,expr,pare)
5761" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005762 if netrw#CheckIfRemote()
5763 keepalt 1sp
5764 keepalt enew
5765 let keep_liststyle = w:netrw_liststyle
5766 let w:netrw_liststyle = s:THINLIST
5767 if s:NetrwRemoteListing() == 0
5768 keepj keepalt %s@/@@
5769 let filelist= getline(1,$)
5770 q!
5771 else
5772 " remote listing error -- leave treedict unchanged
5773 let filelist= w:netrw_treedict[a:direntry]
5774 endif
5775 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005776 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5777 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5778 if a:pare
5779 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5780 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005781 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005782 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5783 if a:pare
5784 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5785 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005786 endif
5787" call Dret("s:NetrwGlob ".string(filelist))
5788 return filelist
5789endfun
5790
5791" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005792" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5793fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005794" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005795 if a:newfile =~ '[/@*=|\\]$'
5796 let newfile= substitute(a:newfile,'.$','','')
5797 else
5798 let newfile= a:newfile
5799 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005800 if a:islocal
5801 call s:NetrwBrowseChgDir(a:islocal,newfile)
5802 else
5803 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5804 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005805" call Dret("s:NetrwForceFile")
5806endfun
5807
5808" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005809" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5810" and switches the hiding mode. The actual hiding is done by
5811" s:NetrwListHide().
5812" g:netrw_hide= 0: show all
5813" 1: show not-hidden files
5814" 2: show hidden files only
5815fun! s:NetrwHide(islocal)
5816" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005817 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005818 let svpos= winsaveview()
5819" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005820
5821 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005822" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5823" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005824
5825 " hide the files in the markfile list
5826 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005827" 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 +00005828 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5829 " remove fname from hiding list
5830 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5831 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5832 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005833" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005834 else
5835 " append fname to hiding list
5836 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5837 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5838 else
5839 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5840 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005841" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005842 endif
5843 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005844 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005845 let g:netrw_hide= 1
5846
5847 else
5848
5849 " switch between show-all/show-not-hidden/show-hidden
5850 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005851 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005852 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005853 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005854 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005855" call Dret("NetrwHide")
5856 return
5857 endif
5858 endif
5859
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005860 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005861" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5862 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005863 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005865endfun
5866
5867" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005868" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5869fun! s:NetrwHideEdit(islocal)
5870" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5871
5872 let ykeep= @@
5873 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005874 let svpos= winsaveview()
5875" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005876
5877 " get new hiding list from user
5878 call inputsave()
5879 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5880 call inputrestore()
5881 let g:netrw_list_hide= newhide
5882" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5883
5884 " refresh the listing
5885 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5886
5887 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005888" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5889 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005890 let @@= ykeep
5891
5892" call Dret("NetrwHideEdit")
5893endfun
5894
5895" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005896" s:NetrwHidden: invoked by "gh" {{{2
5897fun! s:NetrwHidden(islocal)
5898" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005899 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005900 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005901 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005902" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005903
5904 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005905 " remove .file pattern from hiding list
5906" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005907 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005908 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005909" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005910 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5911 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005912" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005913 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5914 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005915 if g:netrw_list_hide =~ '^,'
5916 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5917 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005918
5919 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005920 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005921" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5922 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005923 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005924" call Dret("s:NetrwHidden")
5925endfun
5926
5927" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005928" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5929fun! s:NetrwHome()
5930 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005931 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005932 else
5933 " go to vim plugin home
5934 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005935 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005936 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005937 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005938 let home= basehome."/.vim"
5939 break
5940 endif
5941 endfor
5942 if home == ""
5943 " just pick the first directory
5944 let home= substitute(&rtp,',.*$','','')
5945 endif
5946 if (has("win32") || has("win95") || has("win64") || has("win16"))
5947 let home= substitute(home,'/','\\','g')
5948 endif
5949 endif
5950 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005951 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005952" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005953 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005954" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005955 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005956 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005957" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005958 call mkdir(home)
5959 endif
5960 endif
5961 let g:netrw_home= home
5962 return home
5963endfun
5964
5965" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005966" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5967fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005968 if exists("s:netrwdrag")
5969 return
5970 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005971 if &ft != "netrw"
5972 return
5973 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005974" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005975
Bram Moolenaar97d62492012-11-15 21:28:22 +01005976 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005977 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005978 while getchar(0) != 0
5979 "clear the input stream
5980 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005981 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005982 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005983 let mouse_lnum = v:mouse_lnum
5984 let wlastline = line('w$')
5985 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005986" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5987" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005988 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5989 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005990 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005991" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5992 return
5993 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005994 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005995 " 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 +01005996 " without this test when its disabled.
5997 " 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 +01005998" 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 +01005999 if v:mouse_col > virtcol('.')
6000 let @@= ykeep
6001" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6002 return
6003 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006004
Bram Moolenaar446cb832008-06-24 21:56:24 +00006005 if a:islocal
6006 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006007 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006008 endif
6009 else
6010 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006011 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006012 endif
6013 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006014 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006015" call Dret("s:NetrwLeftmouse")
6016endfun
6017
6018" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006019" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6020fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006021 if &ft != "netrw"
6022 return
6023 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006024" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6025 call s:NetrwMarkFileTgt(a:islocal)
6026" call Dret("s:NetrwCLeftmouse")
6027endfun
6028
6029" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006030" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6031" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006032" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006033" a:islocal=2 : <c-r> used, remote
6034" a:islocal=3 : <c-r> used, local
6035fun! s:NetrwServerEdit(islocal,fname)
6036" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6037 let islocal = a:islocal%2 " =0: remote =1: local
6038 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006039" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006040
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006041 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006042 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006043 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006044" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006045 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006046 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006047 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6048 unlet s:netrw_browse_split_{winnr()}
6049 endif
6050 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6051" call Dret("s:NetrwServerEdit")
6052 return
6053 endif
6054
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006055" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006056 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006057" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006058
6059 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006060" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006061 let srvrname = g:netrw_browse_split[0]
6062 let tabnum = g:netrw_browse_split[1]
6063 let winnum = g:netrw_browse_split[2]
6064
6065 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006066" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006067
6068 if !ctrlr
6069 " user must have closed the server window and the user did not use <c-r>, but
6070 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006071" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006072 if exists("g:netrw_browse_split")
6073 unlet g:netrw_browse_split
6074 endif
6075 let g:netrw_browse_split= 0
6076 if exists("s:netrw_browse_split_".winnr())
6077 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6078 endif
6079 call s:NetrwBrowseChgDir(islocal,a:fname)
6080" call Dret("s:NetrwServerEdit")
6081 return
6082
6083 elseif has("win32") && executable("start")
6084 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086 call system("start gvim --servername ".srvrname)
6087
6088 else
6089 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091 call system("gvim --servername ".srvrname)
6092 endif
6093 endif
6094
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006095" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006096 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6097 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006098 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099
6100 else
6101
6102 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6103
6104 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006105" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006106 if exists("g:netrw_browse_split")
6107 unlet g:netrw_browse_split
6108 endif
6109 let g:netrw_browse_split= 0
6110 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6111" call Dret("s:NetrwServerEdit")
6112 return
6113
6114 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006115" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 if has("win32") && executable("start")
6117 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006118" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006119 call system("start gvim --servername ".g:netrw_servername)
6120 else
6121 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006122" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006123 call system("gvim --servername ".g:netrw_servername)
6124 endif
6125 endif
6126 endif
6127
6128 while 1
6129 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006130" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6131 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006132 break
6133 catch /^Vim\%((\a\+)\)\=:E241/
6134 sleep 200m
6135 endtry
6136 endwhile
6137
6138 if exists("g:netrw_browse_split")
6139 if type(g:netrw_browse_split) != 3
6140 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6141 endif
6142 unlet g:netrw_browse_split
6143 endif
6144 let g:netrw_browse_split= [g:netrw_servername,1,1]
6145 endif
6146
6147 else
6148 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6149 endif
6150
6151" call Dret("s:NetrwServerEdit")
6152endfun
6153
6154" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006155" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6156fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006157 if &ft != "netrw"
6158 return
6159 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006160" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006161
Bram Moolenaar8d043172014-01-23 14:24:41 +01006162 let s:ngw= s:NetrwGetWord()
6163 call s:NetrwMarkFile(a:islocal,s:ngw)
6164
6165" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006166endfun
6167
6168" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006169" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6170" Used to mark multiple files.
6171fun! s:NetrwSLeftdrag(islocal)
6172" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6173 if !exists("s:netrwdrag")
6174 let s:netrwdrag = winnr()
6175 if a:islocal
6176 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006177 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006178 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006179 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006180 endif
6181 let ngw = s:NetrwGetWord()
6182 if !exists("s:ngw") || s:ngw != ngw
6183 call s:NetrwMarkFile(a:islocal,ngw)
6184 endif
6185 let s:ngw= ngw
6186" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6187endfun
6188
6189" ---------------------------------------------------------------------
6190" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6191fun! s:NetrwSLeftrelease(islocal)
6192" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6193 if exists("s:netrwdrag")
6194 nunmap <s-leftrelease>
6195 let ngw = s:NetrwGetWord()
6196 if !exists("s:ngw") || s:ngw != ngw
6197 call s:NetrwMarkFile(a:islocal,ngw)
6198 endif
6199 if exists("s:ngw")
6200 unlet s:ngw
6201 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006202 unlet s:netrwdrag
6203 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006204" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006205endfun
6206
6207" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006208" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6209" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006210fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006211" 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 +02006212" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006213 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006214
6215 " 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 +02006216 " How-it-works: take the hiding command, convert it into a range.
6217 " Duplicate characters don't matter.
6218 " Remove all such characters from the '/~@#...890' string.
6219 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006220" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006221 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006222 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006223" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006224
6225 while listhide != ""
6226 if listhide =~ ','
6227 let hide = substitute(listhide,',.*$','','e')
6228 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6229 else
6230 let hide = listhide
6231 let listhide = ""
6232 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006233" 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 +01006234 if g:netrw_sort_by =~ '^[ts]'
6235 if hide =~ '^\^'
6236" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6237 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6238 elseif hide =~ '^\\(\^'
6239 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6240 endif
6241" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6242 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006243
6244 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006245" 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 +00006246 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006247" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006248 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006249 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006250" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006251 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006252 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006253" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006254 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006255
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006257 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006258" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006259 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006260" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006261 endif
6262
Bram Moolenaaradc21822011-04-01 18:03:16 +02006263 " remove any blank lines that have somehow remained.
6264 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006265 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006266
Bram Moolenaar97d62492012-11-15 21:28:22 +01006267 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006268" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006269endfun
6270
6271" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006272" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006273" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006274fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006275" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006276
Bram Moolenaar97d62492012-11-15 21:28:22 +01006277 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006278 " get name of new directory from user. A bare <CR> will skip.
6279 " if its currently a directory, also request will be skipped, but with
6280 " a message.
6281 call inputsave()
6282 let newdirname= input("Please give directory name: ")
6283 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006284" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006285
6286 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006287 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006288" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289 return
6290 endif
6291
6292 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006293" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006294
6295 " Local mkdir:
6296 " sanity checks
6297 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006298" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6299 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006301 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006303 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006304" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305 return
6306 endif
6307 if s:FileReadable(fullnewdir)
6308 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006309 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006310 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006311 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006312" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006313 return
6314 endif
6315
6316 " requested new local directory is neither a pre-existing file or
6317 " directory, so make it!
6318 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006319 if has("unix")
6320 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6321 else
6322 call mkdir(fullnewdir,"p")
6323 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006324 else
6325 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006326 if s:NetrwLcd(b:netrw_curdir)
6327" call Dret("s:NetrwMakeDir : lcd failure")
6328 return
6329 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006330" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006331 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006332 if v:shell_error != 0
6333 let @@= ykeep
6334 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 +01006335" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006336 return
6337 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006338 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006339" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006340 if s:NetrwLcd(netrw_origdir)
6341" call Dret("s:NetrwBrowse : lcd failure")
6342 return
6343 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006344 endif
6345 endif
6346
6347 if v:shell_error == 0
6348 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006349" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006350 let svpos= winsaveview()
6351" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006352 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006353" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6354 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006355 elseif !exists("g:netrw_quiet")
6356 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6357 endif
6358" redraw!
6359
6360 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006361 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006362" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006363 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6364 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006365 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006366 if v:shell_error == 0
6367 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006368 let svpos= winsaveview()
6369" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006370 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006371" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6372 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006373 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006374 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006375 endif
6376" redraw!
6377
6378 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006379 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006380 let svpos= winsaveview()
6381" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006382" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006383 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006384" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006385 let remotepath= b:netrw_fname
6386 else
6387 let remotepath= ""
6388 endif
6389 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006390 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006391" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6392 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006393
Bram Moolenaar446cb832008-06-24 21:56:24 +00006394 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006395 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006396 let svpos= winsaveview()
6397" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006398" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006399 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006400" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006401 let remotepath= b:netrw_fname
6402 else
6403 let remotepath= ""
6404 endif
6405 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006406 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006407" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6408 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 endif
6410
Bram Moolenaar97d62492012-11-15 21:28:22 +01006411 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006412" call Dret("s:NetrwMakeDir")
6413endfun
6414
6415" ---------------------------------------------------------------------
6416" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6417fun! s:TreeSqueezeDir(islocal)
6418" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6419 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6420 " its a tree-listing style
6421 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006422 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006423 let depth = strchars(substitute(curdepth,' ','','g'))
6424 let srch = -1
6425" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6426" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006427" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006428" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6429 if depth >= 2
6430 NetrwKeepj norm! 0
6431 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6432 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6433" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6434" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6435 elseif depth == 1
6436 NetrwKeepj norm! 0
6437 let treedepthchr= substitute(s:treedepthstring,' ','','')
6438 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6439" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6440 endif
6441 if srch > 0
6442" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6443 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6444 exe srch
6445 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006446 endif
6447" call Dret("s:TreeSqueezeDir")
6448endfun
6449
6450" ---------------------------------------------------------------------
6451" s:NetrwMaps: {{{2
6452fun! s:NetrwMaps(islocal)
6453" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6454
Bram Moolenaar85850f32019-07-19 22:05:51 +02006455 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006456 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006457" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006458 if !hasmapto("<Plug>NetrwReturn")
6459 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006460" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006461 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6462 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006463" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006464 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6465 endif
6466 endif
6467 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006468" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006469 endif
6470
Bram Moolenaar85850f32019-07-19 22:05:51 +02006471 " generate default <Plug> maps {{{3
6472 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006473 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006474 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6475 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6476 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6477 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6478 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6479 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6480 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6481 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6482 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6483 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6484" ---------------------------------------------------------------------
6485" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6486" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6487" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6488" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6489" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6490" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6491" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6492" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6493" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6494" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6495" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6496" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6497" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6498" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6499" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6500" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6501" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6502" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6503" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6504" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6505" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6506" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6507" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6508" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6509" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6510" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6511" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6512" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6513" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6514" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6515" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6516" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6517" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6518" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6519" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6520" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6521" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6522" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6523" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6524" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6525" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6526" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6527" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6528" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6529" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6530" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6531" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6532
Bram Moolenaara6878372014-03-22 21:02:50 +01006533 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006534" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006535 " local normal-mode maps {{{3
6536 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6537 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6538 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6539 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6540 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6541 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6542 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6543 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6544 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6545 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6546 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6547" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006548 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6549 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6550 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006551 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006552 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006553 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6554 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6555 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6556 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006557 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6558 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6559 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6560 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6561 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6562 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6563 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6564 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6565 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6566 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6567 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6568 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6569 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006570 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006571 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006572 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6573 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6574 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6575 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6576 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006577 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006578 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006579 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6580 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006581 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6582 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6583 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006584 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006585 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006586 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006588 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006589 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006590 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6591 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6592 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006593 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6594 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006595
6596 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 +01006597 if !hasmapto('<Plug>NetrwHideEdit')
6598 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006599 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006600 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006601 if !hasmapto('<Plug>NetrwRefresh')
6602 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006603 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006604 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 +01006605 if s:didstarstar || !mapcheck("<s-down>","n")
6606 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006607 endif
6608 if s:didstarstar || !mapcheck("<s-up>","n")
6609 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006610 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006611 if !hasmapto('<Plug>NetrwTreeSqueeze')
6612 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006613 endif
6614 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006615 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6616 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006617 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6618 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6619 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6620 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6621 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6622 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6623 imap <buffer> <leftmouse> <Plug>ILeftmouse
6624 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006625 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006626 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006627 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006628 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006630 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006631 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6632 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006634 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6635 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6636 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6637 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6638 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6639 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6640 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006641 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6642
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006643 " support user-specified maps
6644 call netrw#UserMaps(1)
6645
Bram Moolenaar85850f32019-07-19 22:05:51 +02006646 else
6647 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006648" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006649 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006650 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6651 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6652 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6653 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6654 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6655 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6656 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6657 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6658 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6659 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6660 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6661" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006662 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6663 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6664 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6665 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6666 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6667 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6668 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6669 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006670 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006671 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006672 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6673 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6674 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6675 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6676 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6677 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6678 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6679 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6680 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6681 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6682 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006683 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006684 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006685 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6686 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6687 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6688 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6689 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006690 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6691 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6692 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6693 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006694 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6696 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006697 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006698 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 +01006699 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6700 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6701 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6702 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6703 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6704 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6705 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6706 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6707 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006708 if !hasmapto('<Plug>NetrwHideEdit')
6709 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006710 endif
6711 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6712 if !hasmapto('<Plug>NetrwRefresh')
6713 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006714 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006715 if !hasmapto('<Plug>NetrwTreeSqueeze')
6716 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006717 endif
6718 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006719
6720 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006721 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006722
6723 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6724 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006725 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6726 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6727 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6728 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6729 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6730 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6731 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6732 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6733 nmap <middlemouse> <Plug>NetrwMiddlemouse
6734 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6735 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6736 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6737 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006738 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006739 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006740 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6741 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006742 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006743 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6744 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6745 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6746 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6747 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6748 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6749 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006750 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006751
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752 " support user-specified maps
6753 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006754 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006755
6756" call Dret("s:NetrwMaps")
6757endfun
6758
6759" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006760" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006761" If -buffer, the command is only available from within netrw buffers
6762" Otherwise, the command is available from any window, so long as netrw
6763" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006764fun! s:NetrwCommands(islocal)
6765" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6766
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006767 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6768 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006769 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 +01006770 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006771 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006772 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006773 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006774 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006775 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006776
6777" call Dret("s:NetrwCommands")
6778endfun
6779
6780" ---------------------------------------------------------------------
6781" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6782" glob()ing only works with local files
6783fun! s:NetrwMarkFiles(islocal,...)
6784" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006785 let curdir = s:NetrwGetCurdir(a:islocal)
6786 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006787 while i <= a:0
6788 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006789 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006790 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006791 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006792 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006793 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006794 else
6795 let mffiles= [a:{i}]
6796 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006797" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006798 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006799" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006800 call s:NetrwMarkFile(a:islocal,mffile)
6801 endfor
6802 let i= i + 1
6803 endwhile
6804" call Dret("s:NetrwMarkFiles")
6805endfun
6806
6807" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006808" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006809fun! s:NetrwMarkTarget(...)
6810" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6811 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006812 let curdir = s:NetrwGetCurdir(1)
6813 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006814 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006815 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6816 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006818" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006819 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006820 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6821 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006822 let svpos = winsaveview()
6823" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006824 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006825" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6826 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006827" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006828endfun
6829
6830" ---------------------------------------------------------------------
6831" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6832" mark and unmark files. If a markfile list exists,
6833" then the rename and delete functions will use it instead
6834" of whatever may happen to be under the cursor at that
6835" moment. When the mouse and gui are available,
6836" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006837"
6838" Creates two lists
6839" s:netrwmarkfilelist -- holds complete paths to all marked files
6840" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6841"
6842" Creates a marked file match string
6843" s:netrwmarfilemtch_# -- used with 2match to display marked files
6844"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006845" Creates a buffer version of islocal
6846" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006847fun! s:NetrwMarkFile(islocal,fname)
6848" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006849" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006850
6851 " sanity check
6852 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006853" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006854 return
6855 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006856 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006857
Bram Moolenaar97d62492012-11-15 21:28:22 +01006858 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006859 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006860 if a:fname =~ '^\a'
6861 let leader= '\<'
6862 else
6863 let leader= ''
6864 endif
6865 if a:fname =~ '\a$'
6866 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6867 else
6868 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6869 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006870
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006871 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006872 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006873" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6874" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6875" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006876 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006877
6878 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006879 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006880" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006881 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006882 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006883
6884 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006885 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006886" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006887 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6888 if s:netrwmarkfilelist_{curbufnr} == []
6889 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006890" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006891 call s:NetrwUnmarkList(curbufnr,curdir)
6892 else
6893 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006894" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006895 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006896 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006897 for fname in s:netrwmarkfilelist_{curbufnr}
6898 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006899 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006900 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006901 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902 endif
6903 let first= 0
6904 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006905" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006906 endif
6907 endif
6908
6909 else
6910 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006911" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006915 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6916" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006917
6918 " build initial markfile matching pattern
6919 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006920 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006921 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006922 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006923 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 endif
6926
6927 " handle global markfilelist
6928 if exists("s:netrwmarkfilelist")
6929 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6930 if index(s:netrwmarkfilelist,dname) == -1
6931 " append new filename to global markfilelist
6932 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006933" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006934 else
6935 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006936" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6937" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006939" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006941" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006942 unlet s:netrwmarkfilelist
6943 endif
6944 endif
6945 else
6946 " initialize new global-directory markfilelist
6947 let s:netrwmarkfilelist= []
6948 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006949" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 endif
6951
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006952 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006953 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6954 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6955" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6956 if exists("g:did_drchip_netrwlist_syntax")
6957 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6958 endif
6959 else
6960" " call Decho("2match none",'~'.expand("<slnum>"))
6961 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006962 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006963 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006964 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006965" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6966" 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 +00006967endfun
6968
6969" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006970" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6971" mA: move the argument list to marked file list (tomflist=1)
6972" Uses the global marked file list
6973fun! s:NetrwMarkFileArgList(islocal,tomflist)
6974" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6975
6976 let svpos = winsaveview()
6977" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6978 let curdir = s:NetrwGetCurdir(a:islocal)
6979 let curbufnr = bufnr("%")
6980
6981 if a:tomflist
6982 " mA: move argument list to marked file list
6983 while argc()
6984 let fname= argv(0)
6985" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6986 exe "argdel ".fnameescape(fname)
6987 call s:NetrwMarkFile(a:islocal,fname)
6988 endwhile
6989
6990 else
6991 " ma: move marked file list to argument list
6992 if exists("s:netrwmarkfilelist")
6993
6994 " for every filename in the marked list
6995 for fname in s:netrwmarkfilelist
6996" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6997 exe "argadd ".fnameescape(fname)
6998 endfor " for every file in the marked list
6999
7000 " unmark list and refresh
7001 call s:NetrwUnmarkList(curbufnr,curdir)
7002 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7003" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7004 NetrwKeepj call winrestview(svpos)
7005 endif
7006 endif
7007
7008" call Dret("s:NetrwMarkFileArgList")
7009endfun
7010
7011" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007012" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7013" compress/decompress files using the programs
7014" in g:netrw_compress and g:netrw_uncompress,
7015" using g:netrw_compress_suffix to know which to
7016" do. By default:
7017" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007018" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007019fun! s:NetrwMarkFileCompress(islocal)
7020" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007021 let svpos = winsaveview()
7022" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007023 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007024 let curbufnr = bufnr("%")
7025
Bram Moolenaarff034192013-04-24 18:51:19 +02007026 " sanity check
7027 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007028 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007029" call Dret("s:NetrwMarkFileCompress")
7030 return
7031 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007032" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007033
Bram Moolenaar446cb832008-06-24 21:56:24 +00007034 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007035
7036 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007037 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007038 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007039" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007040 if exists("g:netrw_decompress['".sfx."']")
7041 " fname has a suffix indicating that its compressed; apply associated decompression routine
7042 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007043" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007044 let exe= netrw#WinPath(exe)
7045 if a:islocal
7046 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007047 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007048 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007049 call system(exe." ".fname)
7050 if v:shell_error
7051 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007052 endif
7053 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007054 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7055 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007056 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007057
Bram Moolenaarff034192013-04-24 18:51:19 +02007058 endif
7059 unlet sfx
7060
Bram Moolenaar446cb832008-06-24 21:56:24 +00007061 if exists("exe")
7062 unlet exe
7063 elseif a:islocal
7064 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007065 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007066 if v:shell_error
7067 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7068 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007069 else
7070 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007071 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007072 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007073 endfor " for every file in the marked list
7074
Bram Moolenaar446cb832008-06-24 21:56:24 +00007075 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007076 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007077" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7078 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007079 endif
7080" call Dret("s:NetrwMarkFileCompress")
7081endfun
7082
7083" ---------------------------------------------------------------------
7084" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7085" If no marked files, then set up directory as the
7086" target. Currently does not support copying entire
7087" directories. Uses the local-buffer marked file list.
7088" Returns 1=success (used by NetrwMarkFileMove())
7089" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007090fun! s:NetrwMarkFileCopy(islocal,...)
7091" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7092
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007093 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007094 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007095 if b:netrw_curdir !~ '/$'
7096 if !exists("b:netrw_curdir")
7097 let b:netrw_curdir= curdir
7098 endif
7099 let b:netrw_curdir= b:netrw_curdir."/"
7100 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007101
Bram Moolenaarff034192013-04-24 18:51:19 +02007102 " sanity check
7103 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007104 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007105" call Dret("s:NetrwMarkFileCopy")
7106 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007107 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007108" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007109
Bram Moolenaar446cb832008-06-24 21:56:24 +00007110 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007111 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007112" call Dret("s:NetrwMarkFileCopy 0")
7113 return 0
7114 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007115" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007116
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007117 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007118 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007119" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007120 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007121 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7122" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7123 return
7124 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007125
7126 " copy marked files while within the same directory (ie. allow renaming)
7127 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7128 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7129 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007130" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007131 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007132 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7133 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007134" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007135 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007136 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007137 let oldname = a:1
7138 else
7139 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007140" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007141 let s:recursive= 1
7142 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7143 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7144 if ret == 0
7145 break
7146 endif
7147 endfor
7148 unlet s:recursive
7149 call s:NetrwUnmarkList(curbufnr,curdir)
7150" call Dret("s:NetrwMarkFileCopy ".ret)
7151 return ret
7152 endif
7153
7154 call inputsave()
7155 let newname= input("Copy ".oldname." to : ",oldname,"file")
7156 call inputrestore()
7157 if newname == ""
7158" call Dret("s:NetrwMarkFileCopy 0")
7159 return 0
7160 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007161 let args= s:ShellEscape(oldname)
7162 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007163 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007164 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7165 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007166 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007167 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7168 let args= substitute(args,'/','\\','g')
7169 let tgt = substitute(tgt, '/','\\','g')
7170 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007171 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7172 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7173 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7174 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7175" call Decho("args <".args.">",'~'.expand("<slnum>"))
7176" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007177 if isdirectory(s:NetrwFile(args))
7178" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007179 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007180" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007181 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7182 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7183 " contents to a target. One must append the source directory name to the target to get xcopy to
7184 " do the right thing.
7185 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007186" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007187 endif
7188 else
7189 let copycmd= g:netrw_localcopycmd
7190 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007191 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007192 let copycmd = substitute(copycmd,'\s.*$','','')
7193 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007194 let copycmd = netrw#WinPath(copycmd).copycmdargs
7195 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007196 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007197 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007198" call Decho("args <".args.">",'~'.expand("<slnum>"))
7199" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7200" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7201" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007202 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007203 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007205 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 +01007206 else
7207 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7208 endif
7209" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007210 return 0
7211 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007212
7213 elseif a:islocal && !s:netrwmftgt_islocal
7214 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007215" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007216 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007217
7218 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007219 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007220" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007221 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007222
7223 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007224 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007225" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007226 let curdir = getcwd()
7227 let tmpdir = s:GetTempfile("")
7228 if tmpdir !~ '/'
7229 let tmpdir= curdir."/".tmpdir
7230 endif
7231 if exists("*mkdir")
7232 call mkdir(tmpdir)
7233 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007234 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007235 if v:shell_error != 0
7236 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 +01007237" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007238 return
7239 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007240 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007241 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007242 if s:NetrwLcd(tmpdir)
7243" call Dret("s:NetrwMarkFileCopy : lcd failure")
7244 return
7245 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007247 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007248 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007249 if getcwd() == tmpdir
7250 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007251 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007252 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007253 if s:NetrwLcd(curdir)
7254" call Dret("s:NetrwMarkFileCopy : lcd failure")
7255 return
7256 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007257 if delete(tmpdir,"d")
7258 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007259 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007260 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007261 if s:NetrwLcd(curdir)
7262" call Dret("s:NetrwMarkFileCopy : lcd failure")
7263 return
7264 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007265 endif
7266 endif
7267 endif
7268
7269 " -------
7270 " cleanup
7271 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007272" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007273 " remove markings from local buffer
7274 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007275" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7276" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7277" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7278" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7279" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7280" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7281 if exists("s:recursive")
7282" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7283 else
7284" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007285 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007286 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007287 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007288 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007289 else
7290 " refresh local and targets for fast browsing
7291 if !exists("s:recursive")
7292 " remove markings from local buffer
7293" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7294 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7295 endif
7296
7297 " refresh buffers
7298 if s:netrwmftgt_islocal
7299" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7300 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7301 endif
7302 if a:islocal && s:netrwmftgt != curdir
7303" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7304 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7305 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007306 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007307
Bram Moolenaar446cb832008-06-24 21:56:24 +00007308" call Dret("s:NetrwMarkFileCopy 1")
7309 return 1
7310endfun
7311
7312" ---------------------------------------------------------------------
7313" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7314" invoke vim's diff mode on the marked files.
7315" Either two or three files can be so handled.
7316" Uses the global marked file list.
7317fun! s:NetrwMarkFileDiff(islocal)
7318" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7319 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007320
Bram Moolenaarff034192013-04-24 18:51:19 +02007321 " sanity check
7322 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007323 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007324" call Dret("s:NetrwMarkFileDiff")
7325 return
7326 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007327 let curdir= s:NetrwGetCurdir(a:islocal)
7328" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007329
Bram Moolenaara6878372014-03-22 21:02:50 +01007330 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007331 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007332 for fname in s:netrwmarkfilelist
7333 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007334 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007335" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007336 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007337 diffthis
7338 elseif cnt == 2 || cnt == 3
7339 vsplit
7340 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007341" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007342 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007343 diffthis
7344 else
7345 break
7346 endif
7347 endfor
7348 call s:NetrwUnmarkList(curbufnr,curdir)
7349 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007350
Bram Moolenaar446cb832008-06-24 21:56:24 +00007351" call Dret("s:NetrwMarkFileDiff")
7352endfun
7353
7354" ---------------------------------------------------------------------
7355" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7356" Uses global markfilelist
7357fun! s:NetrwMarkFileEdit(islocal)
7358" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7359
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007360 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007362
7363 " sanity check
7364 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007365 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007366" call Dret("s:NetrwMarkFileEdit")
7367 return
7368 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007369" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007370
Bram Moolenaar446cb832008-06-24 21:56:24 +00007371 if exists("s:netrwmarkfilelist_{curbufnr}")
7372 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007373 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007374 " unmark markedfile list
7375" call s:NetrwUnmarkList(curbufnr,curdir)
7376 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007377" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007378 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007379 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007380 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007381
Bram Moolenaar446cb832008-06-24 21:56:24 +00007382" call Dret("s:NetrwMarkFileEdit")
7383endfun
7384
7385" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007386" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007387fun! s:NetrwMarkFileQFEL(islocal,qfel)
7388" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7389 call s:NetrwUnmarkAll()
7390 let curbufnr= bufnr("%")
7391
7392 if !empty(a:qfel)
7393 for entry in a:qfel
7394 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007395" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007396 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007397" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007398 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7399 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7400 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7401 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007402" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007403 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7404 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007405" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007406 endif
7407 endfor
7408 echo "(use me to edit marked files)"
7409 else
7410 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7411 endif
7412
7413" call Dret("s:NetrwMarkFileQFEL")
7414endfun
7415
7416" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007417" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7418" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7419" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7420fun! s:NetrwMarkFileExe(islocal,enbloc)
7421" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007422 let svpos = winsaveview()
7423" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007425 let curbufnr = bufnr("%")
7426
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007427 if a:enbloc == 0
7428 " individually apply command to files, one at a time
7429 " sanity check
7430 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7431 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7432" call Dret("s:NetrwMarkFileExe")
7433 return
7434 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007435" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007436
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007437 if exists("s:netrwmarkfilelist_{curbufnr}")
7438 " get the command
7439 call inputsave()
7440 let cmd= input("Enter command: ","","file")
7441 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007442" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007443 if cmd == ""
7444" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7445 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007446 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007447
7448 " apply command to marked files, individually. Substitute: filename -> %
7449 " If no %, then append a space and the filename to the command
7450 for fname in s:netrwmarkfilelist_{curbufnr}
7451 if a:islocal
7452 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007453 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007454 endif
7455 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007456 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007457 endif
7458 if cmd =~ '%'
7459 let xcmd= substitute(cmd,'%',fname,'g')
7460 else
7461 let xcmd= cmd.' '.fname
7462 endif
7463 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007465 let ret= system(xcmd)
7466 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007467" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007468 let ret= s:RemoteSystem(xcmd)
7469 endif
7470 if v:shell_error < 0
7471 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7472 break
7473 else
7474 echo ret
7475 endif
7476 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007477
7478 " unmark marked file list
7479 call s:NetrwUnmarkList(curbufnr,curdir)
7480
7481 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007483" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7484 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007485 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007486 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007487 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007488
7489 else " apply command to global list of files, en bloc
7490
7491 call inputsave()
7492 let cmd= input("Enter command: ","","file")
7493 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007494" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007495 if cmd == ""
7496" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7497 return
7498 endif
7499 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007500 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007501 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007502 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007503 endif
7504 if a:islocal
7505 call system(cmd)
7506 if v:shell_error < 0
7507 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7508 endif
7509 else
7510 let ret= s:RemoteSystem(cmd)
7511 endif
7512 call s:NetrwUnmarkAll()
7513
7514 " refresh the listing
7515 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007516" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7517 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007518
7519 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520
Bram Moolenaar446cb832008-06-24 21:56:24 +00007521" call Dret("s:NetrwMarkFileExe")
7522endfun
7523
7524" ---------------------------------------------------------------------
7525" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7526" as the marked file(s) (toggles suffix presence)
7527" Uses the local marked file list.
7528fun! s:NetrwMarkHideSfx(islocal)
7529" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007530 let svpos = winsaveview()
7531" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007532 let curbufnr = bufnr("%")
7533
7534 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7535 if exists("s:netrwmarkfilelist_{curbufnr}")
7536
7537 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007538" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007539 " construct suffix pattern
7540 if fname =~ '\.'
7541 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7542 else
7543 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7544 endif
7545 " determine if its in the hiding list or not
7546 let inhidelist= 0
7547 if g:netrw_list_hide != ""
7548 let itemnum = 0
7549 let hidelist= split(g:netrw_list_hide,',')
7550 for hidepat in hidelist
7551 if sfxpat == hidepat
7552 let inhidelist= 1
7553 break
7554 endif
7555 let itemnum= itemnum + 1
7556 endfor
7557 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007558" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007559 if inhidelist
7560 " remove sfxpat from list
7561 call remove(hidelist,itemnum)
7562 let g:netrw_list_hide= join(hidelist,",")
7563 elseif g:netrw_list_hide != ""
7564 " append sfxpat to non-empty list
7565 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7566 else
7567 " set hiding list to sfxpat
7568 let g:netrw_list_hide= sfxpat
7569 endif
7570 endfor
7571
7572 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007573 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007574" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7575 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007576 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007577 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007578 endif
7579
7580" call Dret("s:NetrwMarkHideSfx")
7581endfun
7582
7583" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007584" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007585" Uses the local marked-file list.
7586fun! s:NetrwMarkFileVimCmd(islocal)
7587" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007588 let svpos = winsaveview()
7589" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007590 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007591 let curbufnr = bufnr("%")
7592
Bram Moolenaarff034192013-04-24 18:51:19 +02007593 " sanity check
7594 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007595 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007596" call Dret("s:NetrwMarkFileVimCmd")
7597 return
7598 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007599" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007600
Bram Moolenaar15146672011-10-20 22:22:38 +02007601 if exists("s:netrwmarkfilelist_{curbufnr}")
7602 " get the command
7603 call inputsave()
7604 let cmd= input("Enter vim command: ","","file")
7605 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007606" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007607 if cmd == ""
7608" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7609 return
7610 endif
7611
7612 " apply command to marked files. Substitute: filename -> %
7613 " If no %, then append a space and the filename to the command
7614 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007615" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007616 if a:islocal
7617 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007618 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007619" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007620 exe cmd
7621 exe "sil! keepalt wq!"
7622 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007623" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007624 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007625 endif
7626 endfor
7627
7628 " unmark marked file list
7629 call s:NetrwUnmarkList(curbufnr,curdir)
7630
7631 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007632 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007633" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7634 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007635 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007636 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007637 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007638
Bram Moolenaar15146672011-10-20 22:22:38 +02007639" call Dret("s:NetrwMarkFileVimCmd")
7640endfun
7641
7642" ---------------------------------------------------------------------
7643" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7644" as the marked file(s) (toggles suffix presence)
7645" Uses the local marked file list.
7646fun! s:NetrwMarkHideSfx(islocal)
7647" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007648 let svpos = winsaveview()
7649" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007650 let curbufnr = bufnr("%")
7651
7652 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7653 if exists("s:netrwmarkfilelist_{curbufnr}")
7654
7655 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007656" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007657 " construct suffix pattern
7658 if fname =~ '\.'
7659 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7660 else
7661 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7662 endif
7663 " determine if its in the hiding list or not
7664 let inhidelist= 0
7665 if g:netrw_list_hide != ""
7666 let itemnum = 0
7667 let hidelist= split(g:netrw_list_hide,',')
7668 for hidepat in hidelist
7669 if sfxpat == hidepat
7670 let inhidelist= 1
7671 break
7672 endif
7673 let itemnum= itemnum + 1
7674 endfor
7675 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007676" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007677 if inhidelist
7678 " remove sfxpat from list
7679 call remove(hidelist,itemnum)
7680 let g:netrw_list_hide= join(hidelist,",")
7681 elseif g:netrw_list_hide != ""
7682 " append sfxpat to non-empty list
7683 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7684 else
7685 " set hiding list to sfxpat
7686 let g:netrw_list_hide= sfxpat
7687 endif
7688 endfor
7689
7690 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007691 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007692" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7693 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007694 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007695 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007696 endif
7697
7698" call Dret("s:NetrwMarkHideSfx")
7699endfun
7700
7701" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007702" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7703" Uses the global markfilelist
7704fun! s:NetrwMarkFileGrep(islocal)
7705" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007706 let svpos = winsaveview()
7707" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007708 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007709 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007710
7711 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007712" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007713 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007714" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007715 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007716 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007717" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007718 let netrwmarkfilelist= "*"
7719 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007720
Bram Moolenaarff034192013-04-24 18:51:19 +02007721 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007722" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007723 call inputsave()
7724 let pat= input("Enter pattern: ","")
7725 call inputrestore()
7726 let patbang = ""
7727 if pat =~ '^!'
7728 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007729 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007730 endif
7731 if pat =~ '^\i'
7732 let pat = escape(pat,'/')
7733 let pat = '/'.pat.'/'
7734 else
7735 let nonisi = pat[0]
7736 endif
7737
7738 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007739" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007740 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007741 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007742 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007743 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007744" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7745 return
7746 endtry
7747 echo "(use :cn, :cp to navigate, :Rex to return)"
7748
7749 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007750" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7751 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007752
7753 if exists("nonisi")
7754 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007756 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007757 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007758 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007759 endif
7760
7761" call Dret("s:NetrwMarkFileGrep")
7762endfun
7763
7764" ---------------------------------------------------------------------
7765" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7766" uses the global marked file list
7767" s:netrwmfloc= 0: target directory is remote
7768" = 1: target directory is local
7769fun! s:NetrwMarkFileMove(islocal)
7770" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007771 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007772 let curbufnr = bufnr("%")
7773
7774 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007775 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007776 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007777" call Dret("s:NetrwMarkFileMove")
7778 return
7779 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007780" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007781
Bram Moolenaar446cb832008-06-24 21:56:24 +00007782 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007783 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784" call Dret("s:NetrwMarkFileCopy 0")
7785 return 0
7786 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007787" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007788
7789 if a:islocal && s:netrwmftgt_islocal
7790 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007791" call Decho("move from local to local",'~'.expand("<slnum>"))
7792" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007793 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007794 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7795" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7796 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007797 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007798 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007799" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007800 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007801 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007802" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007803 if g:netrw_localmovecmd =~ '\s'
7804 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7805 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7806 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007807" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007808 else
7809 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007810" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007811 endif
7812 else
7813 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007814" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007815 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007816 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007817 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7818 let fname= substitute(fname,'/','\\','g')
7819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007820" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007821 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007822 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007823 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007824 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 +01007825 else
7826 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7827 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007828 break
7829 endif
7830 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831
7832 elseif a:islocal && !s:netrwmftgt_islocal
7833 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007834" call Decho("move from local to remote",'~'.expand("<slnum>"))
7835" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007836 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007837 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007838" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007839 for fname in mflist
7840 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7841 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7842 endfor
7843 unlet mflist
7844
7845 elseif !a:islocal && s:netrwmftgt_islocal
7846 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007847" call Decho("move from remote to local",'~'.expand("<slnum>"))
7848" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007849 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007850 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007851" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007852 for fname in mflist
7853 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7854 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7855 endfor
7856 unlet mflist
7857
7858 elseif !a:islocal && !s:netrwmftgt_islocal
7859 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007860" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7861" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007862 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007863 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007864" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007865 for fname in mflist
7866 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7867 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7868 endfor
7869 unlet mflist
7870 endif
7871
7872 " -------
7873 " cleanup
7874 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007875" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007876
7877 " remove markings from local buffer
7878 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7879
7880 " refresh buffers
7881 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007882" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007883 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007884 endif
7885 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007886" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007887 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007888 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007889 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007890" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007891 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007892 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007893
Bram Moolenaar446cb832008-06-24 21:56:24 +00007894" call Dret("s:NetrwMarkFileMove")
7895endfun
7896
7897" ---------------------------------------------------------------------
7898" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7899" using the hardcopy command. Local marked-file list only.
7900fun! s:NetrwMarkFilePrint(islocal)
7901" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7902 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007903
7904 " sanity check
7905 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007906 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007907" call Dret("s:NetrwMarkFilePrint")
7908 return
7909 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007910" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7911 let curdir= s:NetrwGetCurdir(a:islocal)
7912
Bram Moolenaar446cb832008-06-24 21:56:24 +00007913 if exists("s:netrwmarkfilelist_{curbufnr}")
7914 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915 call s:NetrwUnmarkList(curbufnr,curdir)
7916 for fname in netrwmarkfilelist
7917 if a:islocal
7918 if g:netrw_keepdir
7919 let fname= s:ComposePath(curdir,fname)
7920 endif
7921 else
7922 let fname= curdir.fname
7923 endif
7924 1split
7925 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007926" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007927 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007928" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007929 hardcopy
7930 q
7931 endfor
7932 2match none
7933 endif
7934" call Dret("s:NetrwMarkFilePrint")
7935endfun
7936
7937" ---------------------------------------------------------------------
7938" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7939" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007940" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007941fun! s:NetrwMarkFileRegexp(islocal)
7942" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7943
7944 " get the regular expression
7945 call inputsave()
7946 let regexp= input("Enter regexp: ","","file")
7947 call inputrestore()
7948
7949 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007950 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007951" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007952 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007953" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007954 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007955 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007956 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007957 else
7958 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007959 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007960 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007961" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962
7963 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007964 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007965 if fname =~ '^'.fnameescape(curdir)
7966" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7967 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7968 else
7969" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7970 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7971 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007972 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007973
7974 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007975" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007976
7977 " convert displayed listing into a filelist
7978 let eikeep = &ei
7979 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007980 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007981 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007982" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007983 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007984 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007985 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007986 sil NetrwKeepj norm! "ap
7987 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007988 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007989 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007990 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007992 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007993 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007994 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007995 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007996 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007997 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007998 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7999 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008000 call histdel("/",-1)
8001 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008002 endif
8003 " convert regexp into the more usual glob-style format
8004 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008005" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008006 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008007 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008008 let filelist= getline(1,line("$"))
8009 q!
8010 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008011 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008012 endfor
8013 unlet filelist
8014 let @a = areg
8015 let &ei = eikeep
8016 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008017 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018
8019" call Dret("s:NetrwMarkFileRegexp")
8020endfun
8021
8022" ---------------------------------------------------------------------
8023" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8024" Uses the local marked file list.
8025fun! s:NetrwMarkFileSource(islocal)
8026" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8027 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008028
8029 " sanity check
8030 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008031 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008032" call Dret("s:NetrwMarkFileSource")
8033 return
8034 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008035" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8036 let curdir= s:NetrwGetCurdir(a:islocal)
8037
Bram Moolenaar446cb832008-06-24 21:56:24 +00008038 if exists("s:netrwmarkfilelist_{curbufnr}")
8039 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040 call s:NetrwUnmarkList(curbufnr,curdir)
8041 for fname in netrwmarkfilelist
8042 if a:islocal
8043 if g:netrw_keepdir
8044 let fname= s:ComposePath(curdir,fname)
8045 endif
8046 else
8047 let fname= curdir.fname
8048 endif
8049 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008050" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008051 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008052 endfor
8053 2match none
8054 endif
8055" call Dret("s:NetrwMarkFileSource")
8056endfun
8057
8058" ---------------------------------------------------------------------
8059" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8060" Uses the global markfilelist
8061fun! s:NetrwMarkFileTag(islocal)
8062" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008063 let svpos = winsaveview()
8064" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008065 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008066 let curbufnr = bufnr("%")
8067
Bram Moolenaarff034192013-04-24 18:51:19 +02008068 " sanity check
8069 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008070 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008071" call Dret("s:NetrwMarkFileTag")
8072 return
8073 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008074" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008075
Bram Moolenaar446cb832008-06-24 21:56:24 +00008076 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008077" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8078 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008079 call s:NetrwUnmarkAll()
8080
8081 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008082
8083" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8084 call system(g:netrw_ctags." ".netrwmarkfilelist)
8085 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008086 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8087 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008088
Bram Moolenaar446cb832008-06-24 21:56:24 +00008089 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008090 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008091 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008092 let curdir= b:netrw_curdir
8093 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008094 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008095 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008096" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008097 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008098 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008099 wq!
8100 endif
8101 2match none
8102 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008103" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8104 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008105 endif
8106
8107" call Dret("s:NetrwMarkFileTag")
8108endfun
8109
8110" ---------------------------------------------------------------------
8111" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008112" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008113" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008114" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008115" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008117" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8118 let svpos = winsaveview()
8119" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008120 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008121 let hadtgt = exists("s:netrwmftgt")
8122 if !exists("w:netrw_bannercnt")
8123 let w:netrw_bannercnt= b:netrw_bannercnt
8124 endif
8125
8126 " set up target
8127 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008128" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008129 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8130 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008131" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008132 unlet s:netrwmftgt s:netrwmftgt_islocal
8133 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008134 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008135 endif
8136 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008137" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8138 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008139" call Dret("s:NetrwMarkFileTgt : removed target")
8140 return
8141 else
8142 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008143" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008144 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008145
8146 else
8147 " get word under cursor.
8148 " * If directory, use it for the target.
8149 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008151 let curword= s:NetrwGetWord()
8152 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008155" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008156 elseif !a:islocal && tgtdir =~ '/$'
8157 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008158" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 else
8160 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008161" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008162 endif
8163 endif
8164 if a:islocal
8165 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8166 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008167" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008168 endif
8169 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008170 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008171 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8172 endif
8173 let s:netrwmftgt_islocal= a:islocal
8174
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008175 " need to do refresh so that the banner will be updated
8176 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008177 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008178" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008179 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008180 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008181" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008182 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8184 else
8185 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8186 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008187" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8188 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008190 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008191 endif
8192
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008193" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8194" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8196endfun
8197
8198" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008199" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8200fun! s:NetrwGetCurdir(islocal)
8201" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8202
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008203 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008204 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8205" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8206 elseif !exists("b:netrw_curdir")
8207 let b:netrw_curdir= getcwd()
8208" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8209 endif
8210
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008211" 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 +01008212 if b:netrw_curdir !~ '\<\a\{3,}://'
8213 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008214" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008215 if g:netrw_keepdir == 0
8216 call s:NetrwLcd(curdir)
8217 endif
8218 endif
8219
8220" call Dret("s:NetrwGetCurdir <".curdir.">")
8221 return b:netrw_curdir
8222endfun
8223
8224" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008225" s:NetrwOpenFile: query user for a filename and open it {{{2
8226fun! s:NetrwOpenFile(islocal)
8227" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008228 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008229 call inputsave()
8230 let fname= input("Enter filename: ")
8231 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008232" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8233
8234 " determine if Lexplore is in use
8235 if exists("t:netrw_lexbufnr")
8236 " check if t:netrw_lexbufnr refers to a netrw window
8237" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8238 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8239 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8240" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8241 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8242 exe "NetrwKeepj e ".fnameescape(fname)
8243 let @@= ykeep
8244" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8245 endif
8246 endif
8247
8248 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008249 if fname !~ '[/\\]'
8250 if exists("b:netrw_curdir")
8251 if exists("g:netrw_quiet")
8252 let netrw_quiet_keep = g:netrw_quiet
8253 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008254 let g:netrw_quiet = 1
8255 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008256 let s:rexposn_{bufnr("%")}= winsaveview()
8257" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008258 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008259 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008260 else
8261 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8262 endif
8263 if exists("netrw_quiet_keep")
8264 let g:netrw_quiet= netrw_quiet_keep
8265 else
8266 unlet g:netrw_quiet
8267 endif
8268 endif
8269 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008270 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008271 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008272 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008273" call Dret("s:NetrwOpenFile")
8274endfun
8275
8276" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008277" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8278" For the mapping to this function be made via
8279" netrwPlugin, you'll need to have had
8280" g:netrw_usetab set to non-zero.
8281fun! netrw#Shrink()
8282" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8283 let curwin = winnr()
8284 let wiwkeep = &wiw
8285 set wiw=1
8286
8287 if &ft == "netrw"
8288 if winwidth(0) > g:netrw_wiw
8289 let t:netrw_winwidth= winwidth(0)
8290 exe "vert resize ".g:netrw_wiw
8291 wincmd l
8292 if winnr() == curwin
8293 wincmd h
8294 endif
8295" call Decho("vert resize 0",'~'.expand("<slnum>"))
8296 else
8297 exe "vert resize ".t:netrw_winwidth
8298" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8299 endif
8300
8301 elseif exists("t:netrw_lexbufnr")
8302 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8303 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8304 let t:netrw_winwidth= winwidth(0)
8305 exe "vert resize ".g:netrw_wiw
8306 wincmd l
8307 if winnr() == curwin
8308 wincmd h
8309 endif
8310" call Decho("vert resize 0",'~'.expand("<slnum>"))
8311 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8312 exe "vert resize ".t:netrw_winwidth
8313" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8314 else
8315 call netrw#Lexplore(0,0)
8316 endif
8317
8318 else
8319 call netrw#Lexplore(0,0)
8320 endif
8321 let wiw= wiwkeep
8322
8323" call Dret("netrw#Shrink")
8324endfun
8325
8326" ---------------------------------------------------------------------
8327" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8328fun! s:NetSortSequence(islocal)
8329" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8330
8331 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008332 let svpos= winsaveview()
8333" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008334 call inputsave()
8335 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8336 call inputrestore()
8337
8338 " refresh the listing
8339 let g:netrw_sort_sequence= newsortseq
8340 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008341" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8342 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008343 let @@= ykeep
8344
8345" call Dret("NetSortSequence")
8346endfun
8347
8348" ---------------------------------------------------------------------
8349" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8350" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008351" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008352fun! s:NetrwUnmarkList(curbufnr,curdir)
8353" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8354
8355 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008356 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008357 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8358 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8359 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8360 call remove(s:netrwmarkfilelist,idx) " remove from global list
8361 endfor
8362 if s:netrwmarkfilelist == []
8363 unlet s:netrwmarkfilelist
8364 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008365
Bram Moolenaar446cb832008-06-24 21:56:24 +00008366 " getting rid of the local marked-file lists is easy
8367 unlet s:netrwmarkfilelist_{a:curbufnr}
8368 endif
8369 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8370 unlet s:netrwmarkfilemtch_{a:curbufnr}
8371 endif
8372 2match none
8373" call Dret("s:NetrwUnmarkList")
8374endfun
8375
8376" ---------------------------------------------------------------------
8377" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8378fun! s:NetrwUnmarkAll()
8379" call Dfunc("s:NetrwUnmarkAll()")
8380 if exists("s:netrwmarkfilelist")
8381 unlet s:netrwmarkfilelist
8382 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008383 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008384 2match none
8385" call Dret("s:NetrwUnmarkAll")
8386endfun
8387
8388" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008389" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008390fun! s:NetrwUnmarkAll2()
8391" call Dfunc("s:NetrwUnmarkAll2()")
8392 redir => netrwmarkfilelist_let
8393 let
8394 redir END
8395 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008396 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008397 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8398 for flist in netrwmarkfilelist_list
8399 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8400 unlet s:netrwmarkfilelist_{curbufnr}
8401 unlet s:netrwmarkfilemtch_{curbufnr}
8402 endfor
8403" call Dret("s:NetrwUnmarkAll2")
8404endfun
8405
8406" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008407" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8408"
8409" Marked files are in two types of lists:
8410" s:netrwmarkfilelist -- holds complete paths to all marked files
8411" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8412"
8413" Marked files suitable for use with 2match are in:
8414" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008415fun! s:NetrwUnMarkFile(islocal)
8416" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008417 let svpos = winsaveview()
8418" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008419 let curbufnr = bufnr("%")
8420
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008421 " unmark marked file list
8422 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8423 if exists("s:netrwmarkfilelist")
8424" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008425 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008426 endif
8427
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008428 let ibuf= 1
8429 while ibuf < bufnr("$")
8430 if exists("s:netrwmarkfilelist_".ibuf)
8431 unlet s:netrwmarkfilelist_{ibuf}
8432 unlet s:netrwmarkfilemtch_{ibuf}
8433 endif
8434 let ibuf = ibuf + 1
8435 endwhile
8436 2match none
8437
Bram Moolenaar446cb832008-06-24 21:56:24 +00008438" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008439"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8440call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008441" call Dret("s:NetrwUnMarkFile")
8442endfun
8443
8444" ---------------------------------------------------------------------
8445" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8446fun! s:NetrwMenu(domenu)
8447
8448 if !exists("g:NetrwMenuPriority")
8449 let g:NetrwMenuPriority= 80
8450 endif
8451
Bram Moolenaaradc21822011-04-01 18:03:16 +02008452 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8454
8455 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008456" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008457 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008458 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8459 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8460 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8461 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8462 if g:netrw_dirhistmax > 0
8463 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8464 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8465 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8466 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8467 else
8468 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8469 endif
8470 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8471 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8472 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8473 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8474 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8475 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8476 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8477 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8478 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8479 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8480 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8481 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8482 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8483 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8484 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 +01008485 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 +02008486 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8488 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8515 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>'
8516 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>'
8517 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>'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8519 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>'
8520 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>'
8521 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 +01008522 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 +02008523 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008525 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008526 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8527 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008528
8529 elseif !a:domenu
8530 let s:netrwcnt = 0
8531 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008532 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008533 exe curwin."wincmd w"
8534
8535 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008536" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008537 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008538" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008539 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008540 endif
8541 endif
8542" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008543 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008544 endif
8545
8546endfun
8547
8548" ---------------------------------------------------------------------
8549" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8550" Used by the O maps (as <SID>NetrwObtain())
8551fun! s:NetrwObtain(islocal)
8552" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8553
Bram Moolenaar97d62492012-11-15 21:28:22 +01008554 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008555 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008556 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008557 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8559 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008560 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008562 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008563
8564" call Dret("NetrwObtain")
8565endfun
8566
8567" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008568" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8569" If there's only one window, then the window will first be split.
8570" Returns:
8571" choice = 0 : didn't have to choose
8572" choice = 1 : saved modified file in window first
8573" choice = 2 : didn't save modified file, opened window
8574" choice = 3 : cancel open
8575fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008576" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008577
Bram Moolenaar97d62492012-11-15 21:28:22 +01008578 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008580 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008581
8582 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008583 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008584 let lastwinnr = winnr("$")
8585 let curword = s:NetrwGetWord()
8586 let choice = 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008587 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008588 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008589 let curdir = s:treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008590" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008591
Bram Moolenaar8d043172014-01-23 14:24:41 +01008592 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593 if lastwinnr == 1
8594 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008595" 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 +02008596 " g:netrw_preview=0: preview window shown in a horizontally split window
8597 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008599 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008600 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008601" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008602 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008604 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008605 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008606" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008607 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008608 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008609 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008610" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008611
8612 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008613 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008614 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008615 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008616 wincmd p
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008617" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008618
8619 " prevwinnr: the window number of the "prev" window
8620 " prevbufnr: the buffer number of the buffer in the "prev" window
8621 " bnrcnt : the qty of windows open on the "prev" buffer
8622 let prevwinnr = winnr()
8623 let prevbufnr = bufnr("%")
8624 let prevbufname = bufname("%")
8625 let prevmod = &mod
8626 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008627 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008628" 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 +01008629
8630 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631 " and it doesn't appear in any other extant window, then ask the
8632 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008633 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008634" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008635 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008636" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008637 exe prevwinnr."wincmd w"
8638
8639 if bnrcnt == 1 && &hidden == 0
8640 " only one copy of the modified buffer in a window, and
8641 " hidden not set, so overwriting will lose the modified file. Ask first...
8642 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008643" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008644 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645
8646 if choice == 1
8647 " Yes -- write file & then browse
8648 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008649 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008650 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008651 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008652 exe origwin."wincmd w"
8653 let &ei = eikeep
8654 let @@ = ykeep
8655" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008656 return choice
8657 endif
8658
8659 elseif choice == 2
8660 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008661" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008662 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008663
8664 else
8665 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008666" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008667 exe origwin."wincmd w"
8668 let &ei= eikeep
8669 let @@ = ykeep
8670" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008671 return choice
8672 endif
8673 endif
8674 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008675 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008676 endif
8677
8678 " restore b:netrw_curdir (window split/enew may have lost it)
8679 let b:netrw_curdir= curdir
8680 if a:islocal < 2
8681 if a:islocal
8682 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8683 else
8684 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8685 endif
8686 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008687 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008688" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008689 return choice
8690endfun
8691
8692" ---------------------------------------------------------------------
8693" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8694" Always assumed to be local -> remote
8695" call s:NetrwUpload(filename, target)
8696" call s:NetrwUpload(filename, target, fromdirectory)
8697fun! s:NetrwUpload(fname,tgt,...)
8698" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8699
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008700 if a:tgt =~ '^\a\{3,}://'
8701 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008702 else
8703 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8704 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008705" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008706
8707 if a:0 > 0
8708 let fromdir= a:1
8709 else
8710 let fromdir= getcwd()
8711 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008712" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008713
8714 if type(a:fname) == 1
8715 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008716" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008717 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8719 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8720" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008721 if a:tgt =~ '/$'
8722 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008723" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008724 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008726" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008727 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008728" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008729 endif
8730 q!
8731
8732 elseif type(a:fname) == 3
8733 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008734" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008735 let curdir= getcwd()
8736 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008737 if s:NetrwLcd(fromdir)
8738" call Dret("s:NetrwUpload : lcd failure")
8739 return
8740 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008741 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008742 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008743 if exists("g:netrw_port") && g:netrw_port != ""
8744 let useport= " ".g:netrw_scpport." ".g:netrw_port
8745 else
8746 let useport= ""
8747 endif
8748 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8749 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008750 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 +02008751 if s:NetrwLcd(curdir)
8752" call Dret("s:NetrwUpload : lcd failure")
8753 return
8754 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008755
8756 elseif a:tgt =~ '^ftp:'
8757 call s:NetrwMethod(a:tgt)
8758
8759 if b:netrw_method == 2
8760 " handle uploading a list of files via ftp+.netrc
8761 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008762 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008763" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008764
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008765 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008766" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008767
8768 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008769 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008770" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008771 endif
8772
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008773 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008774" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008775
Bram Moolenaaradc21822011-04-01 18:03:16 +02008776 if tgtdir == ""
8777 let tgtdir= '/'
8778 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008779 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008780" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008781
8782 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8784" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008785 endfor
8786
8787 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008788 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 +00008789 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008790" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8791 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 endif
8793 " 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 +01008794 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008795 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008796 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8797 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8798 else
8799 bw!|q
8800 endif
8801
8802 elseif b:netrw_method == 3
8803 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8804 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008805 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008807 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808
8809 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008810 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008811" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008813 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008814" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008815 endif
8816
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008817 if exists("g:netrw_uid") && g:netrw_uid != ""
8818 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008819 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008820" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008821 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008822 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008823 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008824" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008825 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008826 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008828 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008829 endif
8830
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008831 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008832" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008833
8834 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008835 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008836" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008837 endif
8838
8839 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008840 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endif
8843
8844 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008845 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008846" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008847 endfor
8848
8849 " perform ftp:
8850 " -i : turns off interactive prompting from ftp
8851 " -n unix : DON'T use <.netrc>, even though it exists
8852 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008853 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008854 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008855 " 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 +01008856 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008857 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8859 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008860 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8862 let &debug = debugkeep
8863 let mod = 1
8864 else
8865 bw!|q
8866 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008867 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008868" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008869 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008870 endif
8871 else
8872 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8873 endif
8874 endif
8875
8876" call Dret("s:NetrwUpload")
8877endfun
8878
8879" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008880" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008881fun! s:NetrwPreview(path) range
8882" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008883" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8884" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008885 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008886 NetrwKeepj call s:NetrwOptionsSave("s:")
8887 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8888 NetrwKeepj call s:NetrwOptionsSafe(1)
8889 else
8890 NetrwKeepj call s:NetrwOptionsSafe(0)
8891 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008892 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008893" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008894 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008895" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8896 if g:netrw_preview
8897 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008898 let pvhkeep = &pvh
8899 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8900 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008901" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8902 else
8903 " horizontal split
8904 let pvhkeep = &pvh
8905 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8906 let &pvh = winheight(0) - winsz
8907" 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 +02008908 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008909 " g:netrw_preview g:netrw_alto
8910 " 1 : vert 1: top -- preview window is vertically split off and on the left
8911 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8912 " 0 : 1: top -- preview window is horizontally split off and on the top
8913 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8914 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008915 " 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 +02008916 " the BufEnter event set up in netrwPlugin.vim
8917" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8918 let eikeep = &ei
8919 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008920 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008921 let &ei= eikeep
8922" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008923 if exists("pvhkeep")
8924 let &pvh= pvhkeep
8925 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008926 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008927 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008928 endif
8929 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008930 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 +00008931 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008932 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008933 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008934" call Dret("NetrwPreview")
8935endfun
8936
8937" ---------------------------------------------------------------------
8938" s:NetrwRefresh: {{{2
8939fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008940" 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 +00008941 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008942 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008943" call Decho("setl ma noro",'~'.expand("<slnum>"))
8944" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008945 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008946 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8947 if !exists("w:netrw_treetop")
8948 if exists("b:netrw_curdir")
8949 let w:netrw_treetop= b:netrw_curdir
8950 else
8951 let w:netrw_treetop= getcwd()
8952 endif
8953 endif
8954 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8955 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008956
8957 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008958 let screenposn = winsaveview()
8959" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008960
8961" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8962" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8963 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008964 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008965 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008966 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008967 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008968 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008969
8970 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008971" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8972 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008973
8974 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008975 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8976 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8977" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8978 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8979 else
8980" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8981 2match none
8982 endif
8983 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008984
Bram Moolenaar97d62492012-11-15 21:28:22 +01008985" restore
8986 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008987" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008988endfun
8989
8990" ---------------------------------------------------------------------
8991" s:NetrwRefreshDir: refreshes a directory by name {{{2
8992" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008993" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008995" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008996 if g:netrw_fastbrowse == 0
8997 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008998" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008999 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009000" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009001
9002 if tgtwin > 0
9003 " tgtwin is being displayed, so refresh it
9004 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009005" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009006 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009007 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009008 exe curwin."wincmd w"
9009
9010 elseif bufnr(a:dirname) > 0
9011 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009012" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9013 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009014 endif
9015
9016 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009017" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009018 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009019 endif
9020" call Dret("s:NetrwRefreshDir")
9021endfun
9022
9023" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009024" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9025" window number to do its editing in.
9026" Supports [count]C where the count, if present, is used to specify
9027" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009028fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009029" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009030 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009031" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009032 if a:1 == "" " :NetrwC win#
9033 let g:netrw_chgwin= winnr()
9034 else " :NetrwC
9035 let g:netrw_chgwin= a:1
9036 endif
9037 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009038 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009039 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009040 let g:netrw_chgwin= winnr()
9041 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009042 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009043" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009044endfun
9045
9046" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009047" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9048" What this function does is to compute a priority for the patterns
9049" in the g:netrw_sort_sequence. It applies a substitute to any
9050" "files" that satisfy each pattern, putting the priority / in
9051" front. An "*" pattern handles the default priority.
9052fun! s:NetrwSetSort()
9053" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009054 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055 if w:netrw_liststyle == s:LONGLIST
9056 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9057 else
9058 let seqlist = g:netrw_sort_sequence
9059 endif
9060 " sanity check -- insure that * appears somewhere
9061 if seqlist == ""
9062 let seqlist= '*'
9063 elseif seqlist !~ '\*'
9064 let seqlist= seqlist.',*'
9065 endif
9066 let priority = 1
9067 while seqlist != ""
9068 if seqlist =~ ','
9069 let seq = substitute(seqlist,',.*$','','e')
9070 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9071 else
9072 let seq = seqlist
9073 let seqlist = ""
9074 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009076 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009078 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009080 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009082" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083
9084 " sanity check
9085 if w:netrw_bannercnt > line("$")
9086 " apparently no files were left after a Hiding pattern was used
9087" call Dret("SetSort : no files left after hiding")
9088 return
9089 endif
9090 if seq == '*'
9091 let starpriority= spriority
9092 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009093 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009094 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009095 " sometimes multiple sorting patterns will match the same file or directory.
9096 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009097 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9098 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009099 endif
9100 let priority = priority + 1
9101 endwhile
9102 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009103 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9104 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009105 endif
9106
9107 " Following line associated with priority -- items that satisfy a priority
9108 " pattern get prefixed by ###/ which permits easy sorting by priority.
9109 " Sometimes files can satisfy multiple priority patterns -- only the latest
9110 " priority pattern needs to be retained. So, at this point, these excess
9111 " priority prefixes need to be removed, but not directories that happen to
9112 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009113 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9114 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009115 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009116
9117" call Dret("SetSort")
9118endfun
9119
Bram Moolenaarff034192013-04-24 18:51:19 +02009120" ---------------------------------------------------------------------
9121" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9122" Implements [count]Tb (bookhist<b>)
9123" [count]Th (bookhist<h>)
9124" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009125fun! s:NetrwSetTgt(islocal,bookhist,choice)
9126" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009127
9128 if a:bookhist == 'b'
9129 " supports choosing a bookmark as a target using a qb-generated list
9130 let choice= a:choice - 1
9131 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009132 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009133 else
9134 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9135 endif
9136
9137 elseif a:bookhist == 'h'
9138 " supports choosing a history stack entry as a target using a qb-generated list
9139 let choice= (a:choice % g:netrw_dirhistmax) + 1
9140 if exists("g:netrw_dirhist_".choice)
9141 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009142 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009143 else
9144 echomsg "Sorry, history#".a:choice." not available!"
9145 endif
9146 endif
9147
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009148 " refresh the display
9149 if !exists("b:netrw_curdir")
9150 let b:netrw_curdir= getcwd()
9151 endif
9152 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9153
Bram Moolenaarff034192013-04-24 18:51:19 +02009154" call Dret("s:NetrwSetTgt")
9155endfun
9156
Bram Moolenaar446cb832008-06-24 21:56:24 +00009157" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009158" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159fun! s:NetrwSortStyle(islocal)
9160" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009161 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009162 let svpos= winsaveview()
9163" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009165 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 +01009166 NetrwKeepj norm! 0
9167 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009168" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9169 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170
9171" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9172endfun
9173
9174" ---------------------------------------------------------------------
9175" s:NetrwSplit: mode {{{2
9176" =0 : net and o
9177" =1 : net and t
9178" =2 : net and v
9179" =3 : local and o
9180" =4 : local and t
9181" =5 : local and v
9182fun! s:NetrwSplit(mode)
9183" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9184
Bram Moolenaar97d62492012-11-15 21:28:22 +01009185 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009186 call s:SaveWinVars()
9187
9188 if a:mode == 0
9189 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009190 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009191 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009192" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009193 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009194 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009195 NetrwKeepj call s:RestoreWinVars()
9196 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009197 unlet s:didsplit
9198
9199 elseif a:mode == 1
9200 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009201 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009202" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203 tabnew
9204 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009205 NetrwKeepj call s:RestoreWinVars()
9206 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009207 unlet s:didsplit
9208
9209 elseif a:mode == 2
9210 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009211 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009212 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009213" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009214 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009215 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009216 NetrwKeepj call s:RestoreWinVars()
9217 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009218 unlet s:didsplit
9219
9220 elseif a:mode == 3
9221 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009222 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009223 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009224" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009225 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009226 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009227 NetrwKeepj call s:RestoreWinVars()
9228 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229 unlet s:didsplit
9230
9231 elseif a:mode == 4
9232 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009233 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009234 let eikeep = &ei
9235 let netrw_winnr = winnr()
9236 let netrw_line = line(".")
9237 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009238 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009239 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009240 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009241 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9242 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009243 let &ei = eikeep
9244 let netrw_curdir = s:NetrwTreeDir(0)
9245" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009247 let b:netrw_curdir = netrw_curdir
9248 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009249 NetrwKeepj call s:RestoreWinVars()
9250 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009251 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009252 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009253 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9254 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009255 let &ei= eikeep
9256 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257 unlet s:didsplit
9258
9259 elseif a:mode == 5
9260 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009261 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009262 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009263" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009264 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009265 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009266 NetrwKeepj call s:RestoreWinVars()
9267 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009268 unlet s:didsplit
9269
9270 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009271 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009272 endif
9273
Bram Moolenaar97d62492012-11-15 21:28:22 +01009274 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009275" call Dret("s:NetrwSplit")
9276endfun
9277
9278" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009279" s:NetrwTgtMenu: {{{2
9280fun! s:NetrwTgtMenu()
9281 if !exists("s:netrw_menucnt")
9282 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009284" call Dfunc("s:NetrwTgtMenu()")
9285
9286 " the following test assures that gvim is running, has menus available, and has menus enabled.
9287 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9288 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009289" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009290 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9291 endif
9292 if !exists("s:netrw_initbookhist")
9293 call s:NetrwBookHistRead()
9294 endif
9295
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009296 " try to cull duplicate entries
9297 let tgtdict={}
9298
Bram Moolenaarff034192013-04-24 18:51:19 +02009299 " target bookmarked places
9300 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009301" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009302 let cnt= 1
9303 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009304 if has_key(tgtdict,bmd)
9305 let cnt= cnt + 1
9306 continue
9307 endif
9308 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009309 let ebmd= escape(bmd,g:netrw_menu_escape)
9310 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009311" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009312 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 +02009313 let cnt= cnt + 1
9314 endfor
9315 endif
9316
9317 " target directory browsing history
9318 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009319" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009320 let histcnt = 1
9321 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009322 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009323 if exists("g:netrw_dirhist_{histcnt}")
9324 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009325 if has_key(tgtdict,histentry)
9326 let histcnt = histcnt + 1
9327 continue
9328 endif
9329 let tgtdict[histentry] = histcnt
9330 let ehistentry = escape(histentry,g:netrw_menu_escape)
9331" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009332 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 +02009333 endif
9334 let histcnt = histcnt + 1
9335 endwhile
9336 endif
9337 endif
9338" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009339endfun
9340
9341" ---------------------------------------------------------------------
9342" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9343" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009344fun! s:NetrwTreeDir(islocal)
9345" 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 +02009346" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009347" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9348" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9349" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009350" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009351
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009352 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009353 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009354" 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 +01009355 let treedir= s:treedir
9356 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009357 unlet s:prevwinopen
9358" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009359 return treedir
9360 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009361 if exists("s:prevwinopen")
9362 unlet s:prevwinopen
9363 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364
Bram Moolenaar8d043172014-01-23 14:24:41 +01009365 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9366 let b:netrw_curdir= getcwd()
9367 endif
9368 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009369" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009370
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009371 let s:treecurpos= winsaveview()
9372" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9373
9374 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009375" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9376" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009377
9378 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009379 let curline= substitute(getline('.'),"\t -->.*$",'','')
9380 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009381" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009382 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009383" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9384 elseif curline =~ '@$'
9385" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9386 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9387" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009388 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009390 let treedir= ""
9391 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009392
9393 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009394" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9395" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009396" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009397 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009400" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9401 sil! NetrwKeepj %d _
9402" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009403 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009404" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009405" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009406 endif
9407
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009408" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009409 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9410" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009411
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009412 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9413" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9414" let newdir = w:netrw_treetop.'/'.potentialdir
9415" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9416" let treedir = s:NetrwTreePath(newdir)
9417" let w:netrw_treetop = newdir
9418" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9419" else
9420" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009421 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009422" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009423 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009424
9425 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009426 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009427" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009428
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009429" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009430 return treedir
9431endfun
9432
9433" ---------------------------------------------------------------------
9434" s:NetrwTreeDisplay: recursive tree display {{{2
9435fun! s:NetrwTreeDisplay(dir,depth)
9436" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9437
9438 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009439 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009440
9441 " install ../ and shortdir
9442 if a:depth == ""
9443 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009444" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009445 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009446 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009447 if a:dir == w:netrw_treetop
9448 let shortdir= a:dir
9449 else
9450 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9451 endif
9452 call setline(line("$")+1,a:depth.shortdir)
9453 else
9454 let shortdir= substitute(a:dir,'^.*/','','e')
9455 call setline(line("$")+1,a:depth.shortdir.'/')
9456 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009457" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009458 " append a / to dir if its missing one
9459 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009460
9461 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009462 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009464
Bram Moolenaar85850f32019-07-19 22:05:51 +02009465 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9466 if g:netrw_hide == 1
9467 " hide given patterns
9468 let listhide= split(g:netrw_list_hide,',')
9469" call Decho("listhide=".string(listhide))
9470 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009471 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009472 endfor
9473
9474 elseif g:netrw_hide == 2
9475 " show given patterns (only)
9476 let listhide= split(g:netrw_list_hide,',')
9477" call Decho("listhide=".string(listhide))
9478 let entries=[]
9479 for entry in w:netrw_treedict[dir]
9480 for pat in listhide
9481 if entry =~ pat
9482 call add(entries,entry)
9483 break
9484 endif
9485 endfor
9486 endfor
9487 let w:netrw_treedict[dir]= entries
9488 endif
9489 if depth != ""
9490 " always remove "." and ".." entries when there's depth
9491 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9492 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9493 endif
9494
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009495" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009496 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009497 if dir =~ '/$'
9498 let direntry= substitute(dir.entry,'[@/]$','','e')
9499 else
9500 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9501 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009502" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009503 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009504" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009505 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009506 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009507" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9508 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9509 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9510" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009511 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009512 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009513" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009514 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009515 endif
9516 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009517" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009518
Bram Moolenaar446cb832008-06-24 21:56:24 +00009519" call Dret("NetrwTreeDisplay")
9520endfun
9521
9522" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009523" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9524fun! s:NetrwRefreshTreeDict(dir)
9525" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009526 if !exists("w:netrw_treedict")
9527" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9528 return
9529 endif
9530
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009531 for entry in w:netrw_treedict[a:dir]
9532 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9533" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9534
9535 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9536" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9537 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009538 let liststar = s:NetrwGlob(direntry,'*',1)
9539 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009540 let w:netrw_treedict[direntry] = liststar + listdotstar
9541" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9542
9543 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9544" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9545 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009546 let liststar = s:NetrwGlob(direntry.'/','*',1)
9547 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009548 let w:netrw_treedict[direntry]= liststar + listdotstar
9549" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9550
9551 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9552" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9553 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009554 let liststar = s:NetrwGlob(direntry.'/','*',1)
9555 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009556" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9557
9558 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009559" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009560 endif
9561 endfor
9562" call Dret("s:NetrwRefreshTreeDict")
9563endfun
9564
9565" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009566" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009567" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009568fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009569 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009570" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009571" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9572" 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>"))
9573" 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 +00009574
9575 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009576 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009577" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009578 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009579 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009580" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581 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 +02009582" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009583 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009584 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009585" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009586 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009587 if exists("w:netrw_treetop")
9588 let s:netrw_treetop= w:netrw_treetop
9589 else
9590 let w:netrw_treetop= getcwd()
9591 let s:netrw_treetop= w:netrw_treetop
9592 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009593
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009595 " insure that we have a treedict, albeit empty
9596" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009597 let w:netrw_treedict= {}
9598 endif
9599
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009600 " update the dictionary for the current directory
9601" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009602" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009603 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009604 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009605" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009606 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009607
9608 " if past banner, record word
9609 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9610 let fname= expand("<cword>")
9611 else
9612 let fname= ""
9613 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009614" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9615" 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 +00009616
9617 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009618" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009619 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009620" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009621
9622 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9623 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009624" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009625 1d
9626 endwhile
9627
Bram Moolenaar13600302014-05-22 18:26:40 +02009628 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009629
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009630" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009631 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009632 endif
9633endfun
9634
9635" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009636" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009637" Normally, treetop is w:netrw_treetop, but a
9638" user of the function ( netrw#SetTreetop() )
9639" wipes that out prior to calling this function
9640fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009641" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9642 if line(".") < w:netrw_bannercnt + 2
9643 let treedir= a:treetop
9644 if treedir !~ '/$'
9645 let treedir= treedir.'/'
9646 endif
9647" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9648 return treedir
9649 endif
9650
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009651 let svpos = winsaveview()
9652" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009653 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009654" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009655 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009656" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9657 let curline= getline('.')
9658" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9659 if curline =~ '/$'
9660" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9661 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9662" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9663 elseif curline =~ '@\s\+-->'
9664" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9665 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9666 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9667" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009668 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009669" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009670 let treedir= ""
9671 endif
9672 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009673" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9674" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009675 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9676 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9677 let treedir= dirname.treedir
9678 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009679" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009680 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009681" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009682 if a:treetop =~ '/$'
9683 let treedir= a:treetop.treedir
9684 else
9685 let treedir= a:treetop.'/'.treedir
9686 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009687" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009688 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009689" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009690" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9691 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009692" call Dret("s:NetrwTreePath <".treedir.">")
9693 return treedir
9694endfun
9695
9696" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009697" s:NetrwWideListing: {{{2
9698fun! s:NetrwWideListing()
9699
9700 if w:netrw_liststyle == s:WIDELIST
9701" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9702 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009703 " cpf: characters per filename
9704 " fpl: filenames per line
9705 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009706 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009707 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009708" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009709 let b:netrw_cpf= 0
9710 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009711 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009712 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9713 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009714 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009715 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009716" call Dret("NetrwWideListing")
9717 return
9718 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009719 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009720 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009721" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009722
9723 " determine qty files per line (fpl)
9724 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9725 if w:netrw_fpl <= 0
9726 let w:netrw_fpl= 1
9727 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009729
9730 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009731 " fpc: files per column of wide listing
9732 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009733 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009734 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9735 let newcolstart = w:netrw_bannercnt + fpc
9736 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009737" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009738 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009739" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009740 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009741 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009742 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009743 while line("$") >= newcolstart
9744 if newcolend > line("$") | let newcolend= line("$") | endif
9745 let newcolqty= newcolend - newcolstart
9746 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009747 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009748 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009749 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009750 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009751 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009752 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009753 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009754 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009755 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009756 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009757" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009758 if @* != keepregstar | sil! let @* = keepregstar | endif
9759 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009760 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009761 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9762 NetrwKeepj call histdel("/",-1)
9763 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9764 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009765" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009766 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009767 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009768" 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 +00009769" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009770 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009771 else
9772 if hasmapto("w","n")
9773 sil! nunmap <buffer> w
9774 endif
9775 if hasmapto("b","n")
9776 sil! nunmap <buffer> b
9777 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009778 endif
9779
9780endfun
9781
9782" ---------------------------------------------------------------------
9783" s:PerformListing: {{{2
9784fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009785" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9786" 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 +02009787" 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>"))
9788 sil! NetrwKeepj %d _
9789" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009790
Bram Moolenaar15146672011-10-20 22:22:38 +02009791 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009792" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009793 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009794
Bram Moolenaar85850f32019-07-19 22:05:51 +02009795 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009796 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009797" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009798
9799" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009800" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009801" endif " Decho
9802
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009804 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9805 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009806" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9807 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808 endif
9809
9810 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009811 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812
9813 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009814 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009815" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009816 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009817 if exists("g:netrw_pchk")
9818 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9819 " failure detections.
9820 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009821 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009822 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9823 endif
9824 if exists("g:netrw_pchk")
9825 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9826 else
9827 let curdir= b:netrw_curdir
9828 endif
9829 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9830 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9831 else
9832 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009833 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009834 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009835 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009836 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009837" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009838 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009839 let w:netrw_bannercnt= 1
9840 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009841" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9842" 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 +00009843
Bram Moolenaar85850f32019-07-19 22:05:51 +02009844 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009846 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009847 let sortby= sortby." reversed"
9848 endif
9849
9850 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009851 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009852" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009853 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009854" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009855 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009856 NetrwKeepj put ='\" Sorted by '.sortby
9857 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009858 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9859 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009860" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009861 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009862 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009863 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9864 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009865 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009866" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" 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 +00009868 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009869
Bram Moolenaar85850f32019-07-19 22:05:51 +02009870 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009871 if g:netrw_banner
9872 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009874 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009875 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009876 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009877 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009878 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009879 endif
9880 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009881 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009884 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009885 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886
9887 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009888 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009889" 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 +01009890 if g:netrw_list_hide != "" && g:netrw_hide
9891 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009892 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009893 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009894 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009895 endif
9896 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009897 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009898 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009899
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 Moolenaara6878372014-03-22 21:02:50 +01009901 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009902" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009903 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904" 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 +01009905 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009906 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009907" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908" 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 +00009909 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009910
9911 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009912 if g:netrw_banner
9913 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009914 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915" 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 +01009916" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917" 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 +01009918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009919
Bram Moolenaar446cb832008-06-24 21:56:24 +00009920 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009921" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009922 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009923 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009924 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009925 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009926 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009927" 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 +01009928" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9929 return
9930 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009932
9933 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009934 if !exists("w:netrw_bannercnt")
9935 let w:netrw_bannercnt= 0
9936 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9938" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9939" 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 +01009940
Bram Moolenaar5c736222010-01-06 20:54:52 +01009941 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009942" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" 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 +00009944 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009945 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009946 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009947 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009950 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009951 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009952" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009953 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009954
Bram Moolenaar5c736222010-01-06 20:54:52 +01009955 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009956" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009957 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009958 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009959 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009960 else
9961 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009963 endif
9964 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009965
Bram Moolenaar446cb832008-06-24 21:56:24 +00009966 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009967" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009968 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9969 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009970
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009971 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009972 " exten: sort by extension
9973 " The histdel(...,-1) calls remove the last search from the search history
9974" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009975 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9976 NetrwKeepj call histdel("/",-1)
9977 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9978 NetrwKeepj call histdel("/",-1)
9979 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9980 NetrwKeepj call histdel("/",-1)
9981 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9982" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009983 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009984 " normal direction sorting
9985 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9986 else
9987 " reverse direction sorting
9988 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9989 endif
9990 endif
9991 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9992 NetrwKeepj call histdel("/",-1)
9993
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009995 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009997 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009999 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010000 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010001" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010002 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010004" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010005 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10006 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010007 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010008 endif
10009
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010010 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010012 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010013 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010014 call histdel("/",-1)
10015 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 endif
10017 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" 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 +000010019
10020 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10022" 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 +010010023 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010024" 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 +010010025 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010026" 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 +000010027
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010028 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010029 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010030" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010031 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010032 endif
10033
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010036" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10037 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010038 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10040 else
10041" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10042" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10043" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10044" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045 endif
10046
10047 " record previous current directory
10048 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010049" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010050
10051 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010052" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10053" 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 +010010054 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010055" 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 +020010056 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010057" 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 +000010058
10059 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010060" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010061 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010062" 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 +010010063 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010064" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010065 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10066 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010067" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010068" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010069
Bram Moolenaar8d043172014-01-23 14:24:41 +010010070 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010071" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10072" 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 +010010073" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10074 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075 unlet s:treecurpos
10076 endif
10077
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010078" 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>"))
10079" 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 +000010080" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10081endfun
10082
10083" ---------------------------------------------------------------------
10084" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010085fun! s:SetupNetrwStatusLine(statline)
10086" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10087
10088 if !exists("s:netrw_setup_statline")
10089 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010090" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010091
10092 if !exists("s:netrw_users_stl")
10093 let s:netrw_users_stl= &stl
10094 endif
10095 if !exists("s:netrw_users_ls")
10096 let s:netrw_users_ls= &laststatus
10097 endif
10098
10099 " set up User9 highlighting as needed
10100 let keepa= @a
10101 redir @a
10102 try
10103 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010104 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010105 if &bg == "dark"
10106 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10107 else
10108 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10109 endif
10110 endtry
10111 redir END
10112 let @a= keepa
10113 endif
10114
10115 " set up status line (may use User9 highlighting)
10116 " insure that windows have a statusline
10117 " make sure statusline is displayed
10118 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010119 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010121 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010122
10123" call Dret("SetupNetrwStatusLine : stl=".&stl)
10124endfun
10125
Bram Moolenaar85850f32019-07-19 22:05:51 +020010126" =========================================
10127" Remote Directory Browsing Support: {{{1
10128" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010129
10130" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010131" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10132" This function assumes that a long listing will be received. Size, time,
10133" and reverse sorts will be requested of the server but not otherwise
10134" enforced here.
10135fun! s:NetrwRemoteFtpCmd(path,listcmd)
10136" 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 +010010137" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010138 " sanity check: {{{3
10139 if !exists("w:netrw_method")
10140 if exists("b:netrw_method")
10141 let w:netrw_method= b:netrw_method
10142 else
10143 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10144" call Dret("NetrwRemoteFtpCmd")
10145 return
10146 endif
10147 endif
10148
10149 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10150 let ffkeep= &ff
10151 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010153
10154 " clear off any older non-banner lines " {{{3
10155 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010156" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10157 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010158
10159 ".........................................
10160 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10161 " ftp + <.netrc>: Method #2
10162 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010163 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010164 endif
10165 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010166 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010168 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010169 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010170" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010171 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010172" 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>"))
10173 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 +010010174 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010175" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10176 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 +010010177 endif
10178
10179 ".........................................
10180 elseif w:netrw_method == 3 " {{{3
10181 " ftp + machine,id,passwd,filename: Method #3
10182 setl ff=unix
10183 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010184 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010185 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010186 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010187 endif
10188
10189 " handle userid and password
10190 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010191" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010192 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10193 call NetUserPass("ftp:".host)
10194 endif
10195 if exists("g:netrw_uid") && g:netrw_uid != ""
10196 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010197 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010198 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010199 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010200 endif
10201 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010202 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010203 endif
10204 endif
10205
10206 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010207 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010208 endif
10209 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010210 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010211" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010212 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010213 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010214
10215 " perform ftp:
10216 " -i : turns off interactive prompting from ftp
10217 " -n unix : DON'T use <.netrc>, even though it exists
10218 " -n win32: quit being obnoxious about password
10219 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010220" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010221 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010222" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010223" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10224" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010225 endif
10226
10227 ".........................................
10228 elseif w:netrw_method == 9 " {{{3
10229 " sftp username@machine: Method #9
10230 " s:netrw_sftp_cmd
10231 setl ff=unix
10232
10233 " restore settings
10234 let &ff= ffkeep
10235" call Dret("NetrwRemoteFtpCmd")
10236 return
10237
10238 ".........................................
10239 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010240 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010241 endif
10242
10243 " cleanup for Windows " {{{3
10244 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010245 sil! NetrwKeepj %s/\r$//e
10246 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010247 endif
10248 if a:listcmd == "dir"
10249 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010250 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10251 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10252 NetrwKeepj call histdel("/",-1)
10253 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010254 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 +010010255 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10256 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 endif
10258 endif
10259
10260 " ftp's listing doesn't seem to include ./ or ../ " {{{3
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 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010266 exe 'NetrwKeepj '.w:netrw_bannercnt
10267 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010268 endif
10269
10270 " restore settings " {{{3
10271 let &ff= ffkeep
10272" call Dret("NetrwRemoteFtpCmd")
10273endfun
10274
10275" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010276" s:NetrwRemoteListing: {{{2
10277fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010278" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010279
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10281 let w:netrw_bannercnt= s:bannercnt
10282 endif
10283 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10284 let w:netrw_bannercnt= s:bannercnt
10285 endif
10286
Bram Moolenaar446cb832008-06-24 21:56:24 +000010287 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010288
Bram Moolenaar446cb832008-06-24 21:56:24 +000010289 " sanity check:
10290 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010291" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010292 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010293" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010294 if !exists("g:netrw_quiet")
10295 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10296 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010297 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010298" call Dret("s:NetrwRemoteListing -1")
10299 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010300 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010301
Bram Moolenaar8d043172014-01-23 14:24:41 +010010302 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010303" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010304 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010305 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010306 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 +000010307 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010308 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 +000010309 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010310 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010311
Bram Moolenaar85850f32019-07-19 22:05:51 +020010312 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010313" call Dret("s:NetrwRemoteListing -1")
10314 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010315 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010316" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010317
Bram Moolenaar446cb832008-06-24 21:56:24 +000010318 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010319" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010320 let w:netrw_method= b:netrw_method
10321 endif
10322
Bram Moolenaar13600302014-05-22 18:26:40 +020010323 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010324 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010325" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010326 let s:method = "ftp"
10327 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010328 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010329 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010330 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010331 let listcmd= g:netrw_ftp_sizelist_cmd
10332 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010333" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010334 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010335" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010336
Bram Moolenaara6878372014-03-22 21:02:50 +010010337 " report on missing file or directory messages
10338 if search('[Nn]o such file or directory\|Failed to change directory')
10339 let mesg= getline(".")
10340 if exists("w:netrw_bannercnt")
10341 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010342 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 setl noma
10344 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010345 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 call netrw#ErrorMsg(s:WARNING,mesg,96)
10347" call Dret("s:NetrwRemoteListing : -1")
10348 return -1
10349 endif
10350
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010351 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 +000010352 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010353" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010354 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010355
10356 " cleanup
10357 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010358 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10359 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010360 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010361 sil! NetrwKeepj %s/\r$//e
10362 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010363
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010364 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010365 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010366 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010367 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010368" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010370" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010371 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010372 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010373 exe "sil! NetrwKeepj ".line1
10374 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010375
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010376" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010378" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010379 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10380 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010382" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010383 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10384 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10385 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10386 NetrwKeepj call histdel("/",-1)
10387 NetrwKeepj call histdel("/",-1)
10388 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010389 endif
10390 endif
10391
Bram Moolenaar13600302014-05-22 18:26:40 +020010392 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010394" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010396" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010397 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10399 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010401 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10402 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10403 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10404 NetrwKeepj call histdel("/",-1)
10405 NetrwKeepj call histdel("/",-1)
10406 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010407 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010408 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10409 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010410 endif
10411 else
10412 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010413" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010414 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010416" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10417 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10418" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010419 endif
10420 endif
10421
10422 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010423 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010424" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010425 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10426 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010427 endif
10428 endif
10429
10430 if w:netrw_liststyle == s:LONGLIST
10431 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010432" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010433
10434 if s:method == "ftp"
10435 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010436 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010437 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010438 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010440 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010442 sil! NetrwKeepj 1
10443 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444 let line2= line(".")
10445 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010446 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010447 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 endif
10449 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010450 exe "sil! NetrwKeepj ".line1
10451 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010452 endif
10453
10454 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010455" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010456 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 +000010457 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010458" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010460 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010461 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10462 NetrwKeepj call histdel("/",-1)
10463 NetrwKeepj call histdel("/",-1)
10464 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465 endif
10466 endif
10467
10468" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010469" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010471
10472" call Dret("s:NetrwRemoteListing 0")
10473 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010474endfun
10475
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476" ---------------------------------------------------------------------
10477" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10478fun! s:NetrwRemoteRm(usrhost,path) range
10479" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010481 let svpos= winsaveview()
10482" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483
10484 let all= 0
10485 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10486 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010487" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010488 for fname in s:netrwmarkfilelist_{bufnr("%")}
10489 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010490 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010491 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010492 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010493 let all= 1
10494 endif
10495 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010496 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497
10498 else
10499 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010500" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501
10502 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010503 let keepsol = &l:sol
10504 setl nosol
10505 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010506
10507 " remove multiple files and directories
10508 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010509 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010510 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010511 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010512 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010513 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 let all= 1
10515 endif
10516 let ctr= ctr + 1
10517 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010518 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519 endif
10520
10521 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010522" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010523 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010524" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10525 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010526
10527" call Dret("s:NetrwRemoteRm")
10528endfun
10529
10530" ---------------------------------------------------------------------
10531" s:NetrwRemoteRmFile: {{{2
10532fun! s:NetrwRemoteRmFile(path,rmfile,all)
10533" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10534
10535 let all= a:all
10536 let ok = ""
10537
10538 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10539 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010540" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541 if !all
10542 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010543" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010544 call inputsave()
10545 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10546 call inputrestore()
10547 echohl NONE
10548 if ok == ""
10549 let ok="no"
10550 endif
10551 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010552 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010553 let all= 1
10554 endif
10555 endif
10556
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010557 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010558" 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 +000010559 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010560" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010562 if path =~ '^\a\{3,}://'
10563 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010564 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010565 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10567 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010568" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010569 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010570" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010572 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573 let ok="q"
10574 else
10575 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010576" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10577" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10578" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010579 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010580 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010581 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010584" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010585 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010586 if v:shell_error != 0
10587 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010588 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 +010010589 else
10590 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10591 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010592 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010593 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010594 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010595" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596 endif
10597 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010598 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010599" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 endif
10601
10602 else
10603 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010604" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605 if !all
10606 call inputsave()
10607 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10608 call inputrestore()
10609 if ok == ""
10610 let ok="no"
10611 endif
10612 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010613 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010614 let all= 1
10615 endif
10616 endif
10617
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010618 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010619 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010620 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010621 else
10622 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010623 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10624" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010625 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010626" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010627
10628 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010629" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10630 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10631" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010632 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010634
10635 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010636 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010637 endif
10638 endif
10639 endif
10640
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010641 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010642" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010643 endif
10644 endif
10645
10646" call Dret("s:NetrwRemoteRmFile ".ok)
10647 return ok
10648endfun
10649
10650" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651" s:NetrwRemoteRename: rename a remote file or directory {{{2
10652fun! s:NetrwRemoteRename(usrhost,path) range
10653" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10654
10655 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010656 let svpos = winsaveview()
10657" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 let ctr = a:firstline
10659 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10660
10661 " rename files given by the markfilelist
10662 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10663 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010664" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665 if exists("subfrom")
10666 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010667" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 else
10669 call inputsave()
10670 let newname= input("Moving ".oldname." to : ",oldname)
10671 call inputrestore()
10672 if newname =~ '^s/'
10673 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10674 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10675 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 endif
10678 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010679
Bram Moolenaar446cb832008-06-24 21:56:24 +000010680 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010681 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683 let oldname= s:ShellEscape(a:path.oldname)
10684 let newname= s:ShellEscape(a:path.newname)
10685" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010686 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 endif
10688
10689 endfor
10690 call s:NetrwUnMarkFile(1)
10691
10692 else
10693
10694 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010695 let keepsol= &l:sol
10696 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010697 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010698 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010699
10700 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010701" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010702
10703 call inputsave()
10704 let newname= input("Moving ".oldname." to : ",oldname)
10705 call inputrestore()
10706
10707 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10708 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10709 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010710 let oldname= s:ShellEscape(a:path.oldname)
10711 let newname= s:ShellEscape(a:path.newname)
10712" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010713 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010714 endif
10715
10716 let ctr= ctr + 1
10717 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010718 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010719 endif
10720
10721 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010722 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010723" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10724 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010725
10726" call Dret("NetrwRemoteRename")
10727endfun
10728
Bram Moolenaar85850f32019-07-19 22:05:51 +020010729" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730" Local Directory Browsing Support: {{{1
10731" ==========================================
10732
10733" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010734" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010735" Should accept: file://localhost/etc/fstab
10736" file:///etc/fstab
10737" file:///c:/WINDOWS/clock.avi
10738" file:///c|/WINDOWS/clock.avi
10739" file://localhost/c:/WINDOWS/clock.avi
10740" file://localhost/c|/WINDOWS/clock.avi
10741" file://c:/foo.txt
10742" file:///c:/foo.txt
10743" 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 +020010744fun! netrw#FileUrlEdit(fname)
10745" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010746 let fname = a:fname
10747 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010748" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010749 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010750" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010751 endif
10752 if (has("win32") || has("win95") || has("win64") || has("win16"))
10753 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010754" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010755 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010756" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010757 endif
10758 endif
10759 let fname2396 = netrw#RFC2396(fname)
10760 let fname2396e= fnameescape(fname2396)
10761 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10762 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010763" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010764 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010766 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10767 endif
10768 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010769
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010770" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10771" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010772 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010773 exe 'NetrwKeepj keepalt edit '.plainfname
10774 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10775
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010776" 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 +020010777" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010778 exe "sil doau BufReadPost ".fname2396e
10779endfun
10780
10781" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010782" netrw#LocalBrowseCheck: {{{2
10783fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010784 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010785 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10786 "
10787 " unfortunate interaction -- split window debugging can't be used here, must use
10788 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10789 " another call to LocalBrowseCheck() when attempts to write
10790 " to the DBG buffer are made.
10791 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010792 " The &ft == "netrw" test was installed because the BufEnter event
10793 " would hit when re-entering netrw windows, creating unexpected
10794 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010795" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010796" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010797" 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 +020010798" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010799" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10800" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010801
Bram Moolenaar97d62492012-11-15 21:28:22 +010010802 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010803 if isdirectory(s:NetrwFile(a:dirname))
10804" 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 +010010805
Bram Moolenaar97d62492012-11-15 21:28:22 +010010806 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010807" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10808" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.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 Moolenaar446cb832008-06-24 21:56:24 +000010811 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010812" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010813 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010814
Bram Moolenaar5c736222010-01-06 20:54:52 +010010815 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010816" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010817 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010818 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010819 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010820" 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 +010010821" call Dret("netrw#LocalBrowseCheck")
10822 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010823 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010824
Bram Moolenaar85850f32019-07-19 22:05:51 +020010825 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010826 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10827 " AND IF the listing style is not a tree listing
10828 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830 let ibuf = 1
10831 let buflast = bufnr("$")
10832 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010833 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10834 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010835 endif
10836 let ibuf= ibuf + 1
10837 endwhile
10838 endif
10839 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840" 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>"))
10841" 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 +000010842 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010843" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010844endfun
10845
10846" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010847" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010848" performed any shell command. The idea is to cause all local-browsing
10849" buffers to be refreshed after a user has executed some shell command,
10850" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010851fun! s:LocalBrowseRefresh()
10852" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010853" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10854" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010855
Bram Moolenaar446cb832008-06-24 21:56:24 +000010856 " determine which buffers currently reside in a tab
10857 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010858" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010859 return
10860 endif
10861 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010862" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010863 return
10864 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010865 if exists("s:netrw_events") && s:netrw_events == 1
10866 " s:LocalFastBrowser gets called (indirectly) from a
10867 let s:netrw_events= 2
10868" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10869 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010870 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010871 let itab = 1
10872 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010873 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010874 while itab <= tabpagenr("$")
10875 let buftablist = buftablist + tabpagebuflist()
10876 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010877 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010878 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010879" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10880" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010881 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10882 " | refresh any netrw window
10883 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010884 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010885 let ibl = 0
10886 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010888 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10889 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010890 " (ibuf not shown in a current window AND
10891 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10893 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010894 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010895" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010896 continue
10897 elseif index(tabpagebuflist(),ibuf) != -1
10898 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010900 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010901 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010902 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10903 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10904 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10905 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010906" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010907 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10908 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10909 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010910 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010911 endif
10912 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010913" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010914 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010915" call Decho("restore window: win_gotoid(".curwinid.")")
10916 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010917 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010918
Bram Moolenaara6878372014-03-22 21:02:50 +010010919" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010920endfun
10921
10922" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10924"
10925" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010926" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010927" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10928" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010929" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010930"
10931" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10932" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010933" (re-using a buffer may not be as accurate)
10934"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010935" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010936" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10937" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10938" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10939" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010940fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010941" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10942" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10943" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10944" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010945
10946 " initialize browselist, a list of buffer numbers that the local browser has used
10947 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010948" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010949 let s:netrw_browselist= []
10950 endif
10951
10952 " append current buffer to fastbrowse list
10953 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010954" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010955 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010956" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010957 endif
10958
10959 " enable autocmd events to handle refreshing/removing local browser buffers
10960 " If local browse buffer is currently showing: refresh it
10961 " If local browse buffer is currently hidden : wipe it
10962 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10963 " =1 : medium speed, re-use directory listing for remote only
10964 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010965 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10966 let s:netrw_events= 1
10967 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010968 au!
10969 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010970" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010971 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010972 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010973" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010974 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010975 endif
10976 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010977
10978 " user must have changed fastbrowse to its fast setting, so remove
10979 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010980 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010981" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010982 unlet s:netrw_events
10983 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010984 au!
10985 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010986 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010987 endif
10988
Bram Moolenaar85850f32019-07-19 22:05:51 +020010989" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010990endfun
10991
10992" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010993" s:LocalListing: does the job of "ls" for local directories {{{2
10994fun! s:LocalListing()
10995" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010996" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10997" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10998" 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 +010010999
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" 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
11001" 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
11002" 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 +010011003
11004 " get the list of files contained in the current directory
11005 let dirname = b:netrw_curdir
11006 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011007 let filelist = s:NetrwGlob(dirname,"*",0)
11008 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011009" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011010
11011 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011012" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011013 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11014 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011015" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011016 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011018 endif
11019
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011020" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011021" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011022" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011023
11024 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11025 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11026 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011027" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11028" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011029 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011030" 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 +010011031
11032 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011033" call Decho(" ",'~'.expand("<slnum>"))
11034" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011035
11036 if getftype(filename) == "link"
11037 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011039 let pfile= filename."@"
11040
11041 elseif getftype(filename) == "socket"
11042 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011043" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011044 let pfile= filename."="
11045
11046 elseif getftype(filename) == "fifo"
11047 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011048" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011049 let pfile= filename."|"
11050
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011051 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011052 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011053" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011054 let pfile= filename."/"
11055
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011056 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011057 if (has("win32") || has("win95") || has("win64") || has("win16"))
11058 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11059 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011060" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011061 let pfile= filename."*"
11062 else
11063 " normal file
11064 let pfile= filename
11065 endif
11066 elseif executable(filename)
11067 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011068" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011069 let pfile= filename."*"
11070 else
11071 " normal file
11072 let pfile= filename
11073 endif
11074
11075 else
11076 " normal file
11077 let pfile= filename
11078 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011079" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011080
11081 if pfile =~ '//$'
11082 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011084 endif
11085 let pfile= strpart(pfile,dirnamelen)
11086 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011087" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11088" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011089
11090 if w:netrw_liststyle == s:LONGLIST
11091 let sz = getfsize(filename)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011092 let fsz = strpart(" ",1,15-strlen(sz)).sz
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011093 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011094 let sz= s:NetrwHumanReadable(sz)
11095 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011096 let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011097 let pfile = longfile.sz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011098" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011099 endif
11100
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011101 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011102 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011103 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011104" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011105" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011106 let t = getftime(filename)
11107 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar91359012019-11-30 17:57:03 +010011108" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011109 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011110 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011111
11112 elseif g:netrw_sort_by =~ "^s"
11113 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011114" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011115" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011117 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011118 let sz= s:NetrwHumanReadable(sz)
11119 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011120 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011122 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011123 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011124
11125 else
11126 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011127" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011129 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011130 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011131" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011132 endfor
11133
11134 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011135 sil! NetrwKeepj g/^$/d
11136 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011137 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011138" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011139 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11140
11141" call Dret("s:LocalListing")
11142endfun
11143
11144" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011145" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11146fun! s:NetrwLocalExecute(cmd)
11147" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11148 let ykeep= @@
11149 " sanity check
11150 if !executable(a:cmd)
11151 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11152 let @@= ykeep
11153" call Dret("s:NetrwLocalExecute")
11154 return
11155 endif
11156
11157 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011158" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011159 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011160" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011161
11162 " strip any ansi escape sequences off
11163 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11164
11165 " show user the result(s)
11166 echomsg result
11167 let @@= ykeep
11168
11169" call Dret("s:NetrwLocalExecute")
11170endfun
11171
11172" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011173" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011174fun! s:NetrwLocalRename(path) range
11175" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11176
11177 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011178 let ykeep = @@
11179 let ctr = a:firstline
11180 let svpos = winsaveview()
11181 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011182" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011183
11184 " rename files given by the markfilelist
11185 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11186 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011187" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011188 if exists("subfrom")
11189 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011190" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011191 else
11192 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011193 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011194 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011195 if newname =~ ''
11196 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11197 let newname = substitute(newname,'^.*','','')
11198 elseif newname =~ ''
11199 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11200 let newname = substitute(newname,'[^/]*','','')
11201 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011202 if newname =~ '^s/'
11203 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11204 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011205" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011206 let newname = substitute(oldname,subfrom,subto,'')
11207 endif
11208 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011209 if !all && filereadable(newname)
11210 call inputsave()
11211 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11212 call inputrestore()
11213 if response == "all"
11214 let all= 1
11215 elseif response != "y" && response != "yes"
11216 " refresh the directory
11217" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11218 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11219" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11220 NetrwKeepj call winrestview(svpos)
11221 let @@= ykeep
11222" call Dret("NetrwLocalRename")
11223 return
11224 endif
11225 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011226 call rename(oldname,newname)
11227 endfor
11228 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011229
Bram Moolenaar97d62492012-11-15 21:28:22 +010011230 else
11231
11232 " attempt to rename files/directories
11233 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011234 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011235
11236 " sanity checks
11237 if line(".") < w:netrw_bannercnt
11238 let ctr= ctr + 1
11239 continue
11240 endif
11241 let curword= s:NetrwGetWord()
11242 if curword == "./" || curword == "../"
11243 let ctr= ctr + 1
11244 continue
11245 endif
11246
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011247 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011248 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011249" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011250
11251 call inputsave()
11252 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11253 call inputrestore()
11254
11255 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011256" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011257
11258 let ctr= ctr + 1
11259 endwhile
11260 endif
11261
11262 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011263" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011264 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011265" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11266 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011267 let @@= ykeep
11268
11269" call Dret("NetrwLocalRename")
11270endfun
11271
11272" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011273" s:NetrwLocalRm: {{{2
11274fun! s:NetrwLocalRm(path) range
11275" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011276" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011277
11278 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011280 let ret = 0
11281 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011282 let svpos = winsaveview()
11283" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011284
11285 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11286 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011287" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011288 for fname in s:netrwmarkfilelist_{bufnr("%")}
11289 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011290 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011291 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011292 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011293 let all= 1
11294 endif
11295 endfor
11296 call s:NetrwUnMarkFile(1)
11297
11298 else
11299 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011300" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011301
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011302 let keepsol= &l:sol
11303 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011304 let ctr = a:firstline
11305 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011306 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011307
11308 " sanity checks
11309 if line(".") < w:netrw_bannercnt
11310 let ctr= ctr + 1
11311 continue
11312 endif
11313 let curword= s:NetrwGetWord()
11314 if curword == "./" || curword == "../"
11315 let ctr= ctr + 1
11316 continue
11317 endif
11318 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011319 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011320 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011321 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011322 let all= 1
11323 endif
11324 let ctr= ctr + 1
11325 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011326 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011327 endif
11328
11329 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011330" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011331 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011332 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011333" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11334 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011335 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011336 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011337
11338" call Dret("s:NetrwLocalRm")
11339endfun
11340
11341" ---------------------------------------------------------------------
11342" s:NetrwLocalRmFile: remove file fname given the path {{{2
11343" Give confirmation prompt unless all==1
11344fun! s:NetrwLocalRmFile(path,fname,all)
11345" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011346
Bram Moolenaar446cb832008-06-24 21:56:24 +000011347 let all= a:all
11348 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011349 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011350 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11351" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011352
11353 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11354 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011355" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011356 if !all
11357 echohl Statement
11358 call inputsave()
11359 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11360 call inputrestore()
11361 echohl NONE
11362 if ok == ""
11363 let ok="no"
11364 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011365" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011366 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011367" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011368 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011369 let all= 1
11370 endif
11371 endif
11372
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011373 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011374 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011375" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011376 endif
11377
11378 else
11379 " attempt to remove directory
11380 if !all
11381 echohl Statement
11382 call inputsave()
11383 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11384 call inputrestore()
11385 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11386 if ok == ""
11387 let ok="no"
11388 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011389 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011390 let all= 1
11391 endif
11392 endif
11393 let rmfile= substitute(rmfile,'[\/]$','','e')
11394
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011395 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +020011396 if v:version < 704 || (v:version == 704 && !has("patch1107"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011397" " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
11398 call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
11399" " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011400
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011401 if v:shell_error != 0
11402" " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11403 let errcode= s:NetrwDelete(rmfile)
11404" " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011405
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011406 if errcode != 0
11407 if has("unix")
11408" " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11409 call system("rm ".s:ShellEscape(rmfile))
11410 if v:shell_error != 0 && !exists("g:netrw_quiet")
11411 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
11412 let ok="no"
11413 endif
11414 elseif !exists("g:netrw_quiet")
11415 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011416 let ok="no"
11417 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011418 endif
11419 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011420 else
11421 if delete(rmfile,"d")
11422 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
11423 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011424 endif
11425 endif
11426 endif
11427
11428" call Dret("s:NetrwLocalRmFile ".ok)
11429 return ok
11430endfun
11431
Bram Moolenaar85850f32019-07-19 22:05:51 +020011432" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011433" Support Functions: {{{1
11434
Bram Moolenaar488c6512005-08-11 20:09:58 +000011435" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011436" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11437" 0: marked file list of current buffer
11438" 1: marked file target
11439fun! netrw#Access(ilist)
11440 if a:ilist == 0
11441 if exists("s:netrwmarkfilelist_".bufnr('%'))
11442 return s:netrwmarkfilelist_{bufnr('%')}
11443 else
11444 return "no-list-buf#".bufnr('%')
11445 endif
11446 elseif a:ilist == 1
11447 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011448 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011449endfun
11450
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011451" ---------------------------------------------------------------------
11452" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11453fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011454 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011455endfun
11456
Bram Moolenaara6878372014-03-22 21:02:50 +010011457" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011458" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11459" I expect this function to be used in
11460" :PChkAssert netrw#Expose("netrwmarkfilelist")
11461" for example.
11462fun! netrw#Expose(varname)
11463" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011464 if exists("s:".a:varname)
11465 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011466" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011467 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011468" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011469 if type(retval) == 3
11470 let retval = copy(retval)
11471 let i = 0
11472 while i < len(retval)
11473 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11474 let i = i + 1
11475 endwhile
11476 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011477" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011478 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011479 else
11480" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011481 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011482 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011483" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011484 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011485 endif
11486
11487" call Dret("netrw#Expose ".string(retval))
11488 return retval
11489endfun
11490
11491" ---------------------------------------------------------------------
11492" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11493fun! netrw#Modify(varname,newvalue)
11494" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11495 exe "let s:".a:varname."= ".string(a:newvalue)
11496" call Dret("netrw#Modify")
11497endfun
11498
11499" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011500" netrw#RFC2396: converts %xx into characters {{{2
11501fun! netrw#RFC2396(fname)
11502" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11503 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11504" call Dret("netrw#RFC2396 ".fname)
11505 return fname
11506endfun
11507
11508" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011509" netrw#UserMaps: supports user-specified maps {{{2
11510" see :help function()
11511"
11512" g:Netrw_UserMaps is a List with members such as:
11513" [[keymap sequence, function reference],...]
11514"
11515" The referenced function may return a string,
11516" refresh : refresh the display
11517" -other- : this string will be executed
11518" or it may return a List of strings.
11519"
11520" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011521" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011522" Related functions:
11523" netrw#Expose(varname) -- see s:varname variables
11524" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11525" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11526fun! netrw#UserMaps(islocal)
11527" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11528" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11529
11530 " set up usermaplist
11531 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11532" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11533 for umap in g:Netrw_UserMaps
11534" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11535" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11536 " if umap[0] is a string and umap[1] is a string holding a function name
11537 if type(umap[0]) == 1 && type(umap[1]) == 1
11538" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11539 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11540 else
11541 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11542 endif
11543 endfor
11544 endif
11545" call Dret("netrw#UserMaps")
11546endfun
11547
11548" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011549" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11550fun! netrw#WinPath(path)
11551" call Dfunc("netrw#WinPath(path<".a:path.">)")
11552 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11553 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011554 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011555 " remove trailing slash (Win95)
11556 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11557 " remove escaped spaces
11558 let path = substitute(path, '\ ', ' ', 'g')
11559 " convert slashes to backslashes
11560 let path = substitute(path, '/', '\', 'g')
11561 else
11562 let path= a:path
11563 endif
11564" call Dret("netrw#WinPath <".path.">")
11565 return path
11566endfun
11567
11568" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011569" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11570" cb : bl2mf=0 add marked files to buffer list
11571" cB : bl2mf=1 use bufferlist to mark files
11572" (mnemonic: cb = copy (marked files) to buffer list)
11573fun! s:NetrwBadd(islocal,bl2mf)
11574" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11575 if a:bl2mf
11576 " cB: add buffer list to marked files
11577 redir => bufl
11578 ls
11579 redir END
11580 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11581 for fname in bufl
11582 call s:NetrwMarkFile(a:islocal,fname)
11583 endfor
11584 else
11585 " cb: add marked files to buffer list
11586 for fname in s:netrwmarkfilelist_{bufnr("%")}
11587" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11588 exe "badd ".fnameescape(fname)
11589 endfor
11590 let curbufnr = bufnr("%")
11591 let curdir = s:NetrwGetCurdir(a:islocal)
11592 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11593 endif
11594" call Dret("s:NetrwBadd")
11595endfun
11596
11597" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011598" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11599fun! s:ComposePath(base,subdir)
11600" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11601
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011602 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011603" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011604 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011605 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011606 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011607 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011608 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011609 endif
11610
Bram Moolenaar85850f32019-07-19 22:05:51 +020011611 " COMBAK: test on windows with changing to root directory: :e C:/
11612 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011613" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011614 let ret= a:subdir
11615
Bram Moolenaar85850f32019-07-19 22:05:51 +020011616 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011617" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011618 if a:base =~ '[/\\]$'
11619 let ret= a:base.a:subdir
11620 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011621 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011622 endif
11623
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011624 elseif a:base =~ '^\a\{3,}://'
11625" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011626 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11627 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11628 if a:subdir == '../'
11629 if curpath =~ '[^/]/[^/]\+/$'
11630 let curpath= substitute(curpath,'[^/]\+/$','','')
11631 else
11632 let curpath=""
11633 endif
11634 let ret= urlbase.curpath
11635 else
11636 let ret= urlbase.curpath.a:subdir
11637 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011638" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11639" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11640" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011641
11642 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011643" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011644 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11645 if a:base =~ '^//'
11646 " keeping initial '//' for the benefit of network share listing support
11647 let ret= '/'.ret
11648 endif
11649 let ret= simplify(ret)
11650 endif
11651
11652" call Dret("s:ComposePath ".ret)
11653 return ret
11654endfun
11655
11656" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011657" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11658" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11659fun! s:DeleteBookmark(fname)
11660" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11661 call s:MergeBookmarks()
11662
11663 if exists("g:netrw_bookmarklist")
11664 let indx= index(g:netrw_bookmarklist,a:fname)
11665 if indx == -1
11666 let indx= 0
11667 while indx < len(g:netrw_bookmarklist)
11668 if g:netrw_bookmarklist[indx] =~ a:fname
11669 call remove(g:netrw_bookmarklist,indx)
11670 let indx= indx - 1
11671 endif
11672 let indx= indx + 1
11673 endwhile
11674 else
11675 " remove exact match
11676 call remove(g:netrw_bookmarklist,indx)
11677 endif
11678 endif
11679
11680" call Dret("s:DeleteBookmark")
11681endfun
11682
11683" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011684" s:FileReadable: o/s independent filereadable {{{2
11685fun! s:FileReadable(fname)
11686" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11687
11688 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011689 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011690 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011691 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011692 endif
11693
11694" call Dret("s:FileReadable ".ret)
11695 return ret
11696endfun
11697
11698" ---------------------------------------------------------------------
11699" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11700" Places correct suffix on end of temporary filename,
11701" using the suffix provided with fname
11702fun! s:GetTempfile(fname)
11703" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11704
11705 if !exists("b:netrw_tmpfile")
11706 " get a brand new temporary filename
11707 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011708" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011709
Bram Moolenaarc236c162008-07-13 17:41:49 +000011710 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011711" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011712
Bram Moolenaar9964e462007-05-05 17:54:07 +000011713 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011714 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11715" 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 +010011716 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011717" call Dret("s:GetTempfile getcwd<".getcwd().">")
11718 return ""
11719 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011720
Bram Moolenaar9964e462007-05-05 17:54:07 +000011721 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011722 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011723" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011724
Bram Moolenaar9964e462007-05-05 17:54:07 +000011725 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011726 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011727 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011728 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011729 if !exists("+shellslash") || !&ssl
11730 let tmpfile = substitute(tmpfile,'/','\','g')
11731 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011732 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011733 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011734 endif
11735 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011736" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011737 else
11738 " re-use temporary filename
11739 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011740" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011741 endif
11742
11743 " use fname's suffix for the temporary file
11744 if a:fname != ""
11745 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011746" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011747 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011748 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011749 elseif a:fname =~ '.txz$'
11750 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011751 else
11752 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11753 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011754" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011755 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011756" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011757 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011758" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011759 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11760 endif
11761 endif
11762
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011763" 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 +000011764" call Dret("s:GetTempfile <".tmpfile.">")
11765 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011766endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011767
11768" ---------------------------------------------------------------------
11769" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011770" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011771fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011772" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011773 if s:user == ""
11774 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11775 else
11776 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11777 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011778 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011779 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011780 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011781 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011782 else
11783 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11784 endif
11785" call Dret("s:MakeSshCmd <".sshcmd.">")
11786 return sshcmd
11787endfun
11788
11789" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011790" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11791fun! s:MakeBookmark(fname)
11792" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11793
11794 if !exists("g:netrw_bookmarklist")
11795 let g:netrw_bookmarklist= []
11796 endif
11797
11798 if index(g:netrw_bookmarklist,a:fname) == -1
11799 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011800 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011801 call add(g:netrw_bookmarklist,a:fname.'/')
11802 elseif a:fname !~ '/'
11803 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11804 else
11805 call add(g:netrw_bookmarklist,a:fname)
11806 endif
11807 call sort(g:netrw_bookmarklist)
11808 endif
11809
11810" call Dret("s:MakeBookmark")
11811endfun
11812
11813" ---------------------------------------------------------------------
11814" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11815fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011817 " get bookmarks from .netrwbook file
11818 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011819 if filereadable(s:NetrwFile(savefile))
11820" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011821 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011823 NetrwKeepj call delete(savefile)
11824 endif
11825" call Dret("s:MergeBookmarks")
11826endfun
11827
11828" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011829" s:NetrwBMShow: {{{2
11830fun! s:NetrwBMShow()
11831" call Dfunc("s:NetrwBMShow()")
11832 redir => bmshowraw
11833 menu
11834 redir END
11835 let bmshowlist = split(bmshowraw,'\n')
11836 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011837 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011838 if bmshowfuncs != []
11839 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011840 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011841 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011842 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011843 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011844 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011845" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11846endfun
11847
11848" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011849" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011850fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011851 if !exists("w:netrw_liststyle")
11852 let w:netrw_liststyle= g:netrw_liststyle
11853 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011854" 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 +020011855
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011856" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11857
Bram Moolenaaradc21822011-04-01 18:03:16 +020011858 if &ft != "netrw"
11859 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11860 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011861" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011862
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011863 elseif g:netrw_cursor == 8
11864 if w:netrw_liststyle == s:WIDELIST
11865 setl cursorline
11866 setl cursorcolumn
11867 else
11868 setl cursorline
11869 endif
11870 elseif g:netrw_cursor == 7
11871 setl cursorline
11872 elseif g:netrw_cursor == 6
11873 if w:netrw_liststyle == s:WIDELIST
11874 setl cursorline
11875 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011876 elseif g:netrw_cursor == 4
11877 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011878" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011879 setl cursorline
11880 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011881
11882 elseif g:netrw_cursor == 3
11883 " thin-long-tree: cursorline, user's cursorcolumn
11884 " wide : cursorline, cursorcolumn
11885 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011886" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011887 setl cursorline
11888 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011889 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011890" 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 +020011891 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011892 endif
11893
11894 elseif g:netrw_cursor == 2
11895 " thin-long-tree: cursorline, user's cursorcolumn
11896 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011897" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011898 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011899
11900 elseif g:netrw_cursor == 1
11901 " thin-long-tree: user's cursorline, user's cursorcolumn
11902 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011903 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011904" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011905 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011906 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011907" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011908 endif
11909
11910 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011911 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011912" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011913 let &l:cursorline = s:netrw_usercul
11914 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011915 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011916
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011917" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011918" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011919endfun
11920
11921" ---------------------------------------------------------------------
11922" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11923fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011924" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011925 if exists("s:netrw_usercul")
11926 let &l:cursorline = s:netrw_usercul
11927 endif
11928 if exists("s:netrw_usercuc")
11929 let &l:cursorcolumn = s:netrw_usercuc
11930 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011931" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011932" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11933endfun
11934
11935" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011936" s:NetrwDelete: Deletes a file. {{{2
11937" Uses Steve Hall's idea to insure that Windows paths stay
11938" acceptable. No effect on Unix paths.
11939" Examples of use: let result= s:NetrwDelete(path)
11940fun! s:NetrwDelete(path)
11941" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11942
Bram Moolenaar5c736222010-01-06 20:54:52 +010011943 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011944 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
11945 if exists("+shellslash")
11946 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011947 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011948 let result = delete(path)
11949 let &shellslash = sskeep
11950 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011951" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011952 let result= delete(path)
11953 endif
11954 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011955" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011956 let result= delete(path)
11957 endif
11958 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011959 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011960 endif
11961
11962" call Dret("s:NetrwDelete ".result)
11963 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011964endfun
11965
11966" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011967" s:NetrwBufRemover: removes a buffer that: {{{2s
11968" has buffer-id > 1
11969" is unlisted
11970" is unnamed
11971" does not appear in any window
11972fun! s:NetrwBufRemover(bufid)
11973" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11974" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11975" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11976" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11977" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11978
11979 if a:bufid > 1 && !buflisted(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
11980" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
11981 exe "bd! ".a:bufid
11982 endif
11983
11984" call Dret("s:NetrwBufRemover")
11985endfun
11986
11987" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011988" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011989fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011990" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011991" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011992
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011993 " Clean out the last buffer:
11994 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11995 " If so, delete it.
11996 call s:NetrwBufRemover(bufnr("$"))
11997
Bram Moolenaar446cb832008-06-24 21:56:24 +000011998 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011999" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012000 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12001 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12002 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12003 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12004 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12005 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12006 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12007 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12008 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12009 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12010 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12011 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12012 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12013 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12014 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12015 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12016
Bram Moolenaar85850f32019-07-19 22:05:51 +020012017 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012018" call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012019 " when tree listing uses file TreeListing... a new buffer is made.
12020 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012021 " COMBAK: this causes a problem, see P43
12022" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012023 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012024 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012025 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012026" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012027 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012028
Bram Moolenaar446cb832008-06-24 21:56:24 +000012029 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012030" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012031 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12032 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12033 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12034 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12035 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12036 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12037 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12038 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12039 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12040 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12041 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12042 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12043 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12044 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12045 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12046 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12047
Bram Moolenaar5c736222010-01-06 20:54:52 +010012048 if a:0 > 0
12049 let b:netrw_curdir= a:1
12050 if b:netrw_curdir =~ '/$'
12051 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012052 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012053 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012054 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012055 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12056 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012057 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012058 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012059 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012060 endif
12061 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012062 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12063 let &l:bexpr = "netrw#BalloonHelp()"
12064 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012065
Bram Moolenaar8d043172014-01-23 14:24:41 +010012066" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012067endfun
12068
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012069" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012070" s:NetrwExe: executes a string using "!" {{{2
12071fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012072" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012073 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012074" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012075 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12076 set shell& shellcmdflag& shellxquote& shellxescape&
12077 set shellquote& shellpipe& shellredir& shellslash&
12078 exe a:cmd
12079 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12080 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012081" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012082 exe a:cmd
12083 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012084 if v:shell_error
12085 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12086 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012087" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012088endfun
12089
12090" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012091" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12092fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012093 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012094" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012095 let curbuf = bufnr("%")
12096 let curwin = winnr()
12097 let iwin = 1
12098 while iwin <= winnr("$")
12099 exe iwin."wincmd w"
12100 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12101 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12102 let winvars= w:
12103 break
12104 endif
12105 let iwin= iwin + 1
12106 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012107 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012108 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012109" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012110 for k in keys(winvars)
12111 let w:{k}= winvars[k]
12112 endfor
12113 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012114" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012115 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012116endfun
12117
Bram Moolenaara6878372014-03-22 21:02:50 +010012118" ---------------------------------------------------------------------
12119" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012120" Returns: 0=success
12121" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012122fun! s:NetrwLcd(newdir)
12123" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012124" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012125
Bram Moolenaar85850f32019-07-19 22:05:51 +020012126 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012127 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012128 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012129 catch /^Vim\%((\a\+)\)\=:E344/
12130 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12131 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012132 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012133 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12134 " forward slashes by earlier code; so check for both.
12135 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12136 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12137 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012138 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012139 endif
12140 endif
12141 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012142 let err472= 1
12143 endtry
12144
12145 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012146 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12147 if exists("w:netrw_prvdir")
12148 let a:newdir= w:netrw_prvdir
12149 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012150 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012151" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012152 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012153" 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 +010012154 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012155 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012156" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12157 return -1
12158 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012159
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012160" call Decho("getcwd <".getcwd().">")
12161" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012162" call Dret("s:NetrwLcd 0")
12163 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012164endfun
12165
Bram Moolenaar9964e462007-05-05 17:54:07 +000012166" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012167" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12168" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12169fun! s:NetrwSaveWordPosn()
12170" call Dfunc("NetrwSaveWordPosn()")
12171 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12172" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12173endfun
12174
12175" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012176" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12177" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12178fun! s:NetrwHumanReadable(sz)
12179" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12180
12181 if g:netrw_sizestyle == 'h'
12182 if a:sz >= 1000000000
12183 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12184 elseif a:sz >= 10000000
12185 let sz = printf("%d",a:sz/1000000)."m"
12186 elseif a:sz >= 1000000
12187 let sz = printf("%.1f",a:sz/1000000.0)."m"
12188 elseif a:sz >= 10000
12189 let sz = printf("%d",a:sz/1000)."k"
12190 elseif a:sz >= 1000
12191 let sz = printf("%.1f",a:sz/1000.0)."k"
12192 else
12193 let sz= a:sz
12194 endif
12195
12196 elseif g:netrw_sizestyle == 'H'
12197 if a:sz >= 1073741824
12198 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12199 elseif a:sz >= 10485760
12200 let sz = printf("%d",a:sz/1048576)."M"
12201 elseif a:sz >= 1048576
12202 let sz = printf("%.1f",a:sz/1048576.0)."M"
12203 elseif a:sz >= 10240
12204 let sz = printf("%d",a:sz/1024)."K"
12205 elseif a:sz >= 1024
12206 let sz = printf("%.1f",a:sz/1024.0)."K"
12207 else
12208 let sz= a:sz
12209 endif
12210
12211 else
12212 let sz= a:sz
12213 endif
12214
12215" call Dret("s:NetrwHumanReadable ".sz)
12216 return sz
12217endfun
12218
12219" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012220" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12221" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12222fun! s:NetrwRestoreWordPosn()
12223" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012224 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012225" call Dret("NetrwRestoreWordPosn")
12226endfun
12227
12228" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012229" s:RestoreBufVars: {{{2
12230fun! s:RestoreBufVars()
12231" call Dfunc("s:RestoreBufVars()")
12232
12233 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12234 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12235 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12236 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12237 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12238 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12239
12240" call Dret("s:RestoreBufVars")
12241endfun
12242
12243" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012244" s:RemotePathAnalysis: {{{2
12245fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012246" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012247
Bram Moolenaara6878372014-03-22 21:02:50 +010012248 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012249 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012250 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012251 let s:user = substitute(a:dirname,dirpat,'\3','')
12252 let s:machine = substitute(a:dirname,dirpat,'\4','')
12253 let s:port = substitute(a:dirname,dirpat,'\5','')
12254 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012255 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012256 if s:machine =~ '@'
12257 let dirpat = '^\(.*\)@\(.\{-}\)$'
12258 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12259 let s:machine = substitute(s:machine,dirpat,'\2','')
12260 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012261
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012262" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12263" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12264" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12265" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12266" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12267" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012268
12269" call Dret("s:RemotePathAnalysis")
12270endfun
12271
12272" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012273" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12274" Returns status
12275" Runs system() on
12276" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012277" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012278fun! s:RemoteSystem(cmd)
12279" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12280 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012281 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 +000012282 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012283 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012284 else
12285 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12286 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12287 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012288 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012289 else
12290 let cmd= cmd.' '
12291 endif
12292 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012293" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012294 let ret= system(cmd)
12295 endif
12296" call Dret("s:RemoteSystem ".ret)
12297 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012298endfun
12299
12300" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012301" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012302fun! s:RestoreWinVars()
12303" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012304 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012305 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12306 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12307 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12308 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12309 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12310 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12311 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12312 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12313 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12314 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12315 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12316 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012317 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12318 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012319 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12320 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12321 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12322" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012323endfun
12324
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012325" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012326" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12327"
12328" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12329" is true) and a command, :Rexplore, which call this function.
12330"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012331" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012332"
12333" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012334fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012335 if exists("s:netrwdrag")
12336 return
12337 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012338" 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 +010012339" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12340" 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 +010012341
12342 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012343 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012344" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012345 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012346 unlet w:netrw_rexfile
12347" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012348 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012349" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012350" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12351" 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 +020012352 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012353
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012354 " ---------------------------
12355 " :Rex issued while in a file
12356 " ---------------------------
12357
Bram Moolenaara6878372014-03-22 21:02:50 +010012358 " record current file so :Rex can return to it from netrw
12359 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012360" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012361
12362 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012363" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012364 return
12365 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012366" 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 +020012367 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012368 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012369 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012370 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012371 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012372 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012373 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012374 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012375 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012376" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12377 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012378" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12379 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012380 if exists("s:rexposn_".bufnr('%'))
12381 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012382 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012383 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012384" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012385 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012386
Bram Moolenaar85850f32019-07-19 22:05:51 +020012387 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12388 if exists("s:explore_match")
12389 exe "2match netrwMarkFile /".s:explore_match."/"
12390 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012391 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012392
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012393" 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 +010012394" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012395endfun
12396
12397" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012398" s:SaveBufVars: save selected b: variables to s: variables {{{2
12399" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012400fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012401" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012402
12403 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12404 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12405 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12406 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12407 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12408 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12409
12410" call Dret("s:SaveBufVars")
12411endfun
12412
12413" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012414" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12415fun! s:SavePosn(posndict)
12416" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12417
Bram Moolenaar85850f32019-07-19 22:05:51 +020012418 if !exists("a:posndict[bufnr('%')]")
12419 let a:posndict[bufnr("%")]= []
12420 endif
12421" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12422 call add(a:posndict[bufnr("%")],winsaveview())
12423" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012424
12425" call Dret("s:SavePosn posndict")
12426 return a:posndict
12427endfun
12428
12429" ---------------------------------------------------------------------
12430" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12431fun! s:RestorePosn(posndict)
12432" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012433 if exists("a:posndict")
12434 if has_key(a:posndict,bufnr("%"))
12435" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12436 let posnlen= len(a:posndict[bufnr("%")])
12437 if posnlen > 0
12438 let posnlen= posnlen - 1
12439" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12440 call winrestview(a:posndict[bufnr("%")][posnlen])
12441 call remove(a:posndict[bufnr("%")],posnlen)
12442" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12443 endif
12444 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012445 endif
12446" call Dret("s:RestorePosn")
12447endfun
12448
12449" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012450" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012451fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012452" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012453 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12454 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12455 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12456 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12457 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12458 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12459 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12460 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12461 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12462 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12463 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12464 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12465 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12466 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12467 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12468 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12469 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12470 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12471" call Dret("s:SaveWinVars")
12472endfun
12473
12474" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012475" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012476" To allow separate windows to have their own activities, such as
12477" Explore **/pattern, several variables have been made window-oriented.
12478" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012479" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012480" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012481fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012482" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012483 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12484 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12485 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12486 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12487 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12488 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12489 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12490 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12491 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12492 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12493" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012494endfun
12495
12496" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012497" s:SetRexDir: set directory for :Rexplore {{{2
12498fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012499" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012500 let w:netrw_rexdir = a:dirname
12501 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012502 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012503" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12504" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012505" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012506" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012507" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012508endfun
12509
12510" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012511" s:ShowLink: used to modify thin and tree listings to show links {{{2
12512fun! s:ShowLink()
12513" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012514" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12515" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012516 if exists("b:netrw_curdir")
12517 norm! $?\a
12518 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12519 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012520" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12521" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12522" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12523 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012524 let dirlen = strlen(b:netrw_curdir)
12525 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012526" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012527 endif
12528 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012529" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12530" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012531 setl noro ma
12532 call setline(".",modline)
12533 setl ro noma nomod
12534 endif
12535" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12536endfun
12537
12538" ---------------------------------------------------------------------
12539" s:ShowStyle: {{{2
12540fun! s:ShowStyle()
12541 if !exists("w:netrw_liststyle")
12542 let liststyle= g:netrw_liststyle
12543 else
12544 let liststyle= w:netrw_liststyle
12545 endif
12546 if liststyle == s:THINLIST
12547 return s:THINLIST.":thin"
12548 elseif liststyle == s:LONGLIST
12549 return s:LONGLIST.":long"
12550 elseif liststyle == s:WIDELIST
12551 return s:WIDELIST.":wide"
12552 elseif liststyle == s:TREELIST
12553 return s:TREELIST.":tree"
12554 else
12555 return 'n/a'
12556 endif
12557endfun
12558
12559" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012560" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12561" Solution from Nicolai Weibull, vim docs (:help strlen()),
12562" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012563fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012564" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12565
12566 if v:version >= 703 && exists("*strdisplaywidth")
12567 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012568
Bram Moolenaar8d043172014-01-23 14:24:41 +010012569 elseif type(g:Align_xstrlen) == 1
12570 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12571 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012572
Bram Moolenaar8d043172014-01-23 14:24:41 +010012573 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012574 " number of codepoints (Latin a + combining circumflex is two codepoints)
12575 " (comment from TM, solution from NW)
12576 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012577
Bram Moolenaar8d043172014-01-23 14:24:41 +010012578 elseif g:Align_xstrlen == 2
12579 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012580 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12581 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012582 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012583
Bram Moolenaar8d043172014-01-23 14:24:41 +010012584 elseif g:Align_xstrlen == 3
12585 " virtual length (counting, for instance, tabs as anything between 1 and
12586 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012587 " preceded by lam, one otherwise, etc.)
12588 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012589 let modkeep= &l:mod
12590 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012591 call setline(line("."),a:x)
12592 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012593 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012594 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012595 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012596
Bram Moolenaar446cb832008-06-24 21:56:24 +000012597 else
12598 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012599 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012600 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012601" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012602 return ret
12603endfun
12604
12605" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012606" s:ShellEscape: shellescape(), or special windows handling {{{2
12607fun! s:ShellEscape(s, ...)
12608 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12609 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12610 endif
12611 let f = a:0 > 0 ? a:1 : 0
12612 return shellescape(a:s, f)
12613endfun
12614
12615" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012616" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012617fun! s:TreeListMove(dir)
12618" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012619 let curline = getline('.')
12620 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12621 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12622 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12623 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12624 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12625 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12626" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12627" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12628" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12629" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12630" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12631 " COMBAK : need to handle when on a directory
12632 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012633 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012634 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012635 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012636 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012637" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012638 elseif a:dir == '[]' && nxtline != ''
12639 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012640" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012641 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12642 if nl != 0
12643 NetrwKeepj norm! k
12644 else
12645 NetrwKeepj norm! G
12646 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012647" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012648 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012649 endif
12650
12651" call Dret("s:TreeListMove")
12652endfun
12653
12654" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012655" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12656" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12657" can't be called except via emenu. But due to locale, that menu line may not be called
12658" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12659fun! s:UpdateBuffersMenu()
12660" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012661 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012662 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012663 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012664 catch /^Vim\%((\a\+)\)\=:E/
12665 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012666 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012667 endtry
12668 endif
12669" call Dret("s:UpdateBuffersMenu")
12670endfun
12671
12672" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012673" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012674" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012675fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012676" call Dfunc("s:UseBufWinVars()")
12677 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012678 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12679 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12680 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12681 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12682 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12683 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12684 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12685 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12686 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 +000012687" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012688endfun
12689
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012690" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012691" s:UserMaps: supports user-defined UserMaps {{{2
12692" * calls a user-supplied funcref(islocal,curdir)
12693" * interprets result
12694" See netrw#UserMaps()
12695fun! s:UserMaps(islocal,funcname)
12696" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12697
12698 if !exists("b:netrw_curdir")
12699 let b:netrw_curdir= getcwd()
12700 endif
12701 let Funcref = function(a:funcname)
12702 let result = Funcref(a:islocal)
12703
12704 if type(result) == 1
12705 " if result from user's funcref is a string...
12706" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12707 if result == "refresh"
12708" call Decho("refreshing display",'~'.expand("<slnum>"))
12709 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12710 elseif result != ""
12711" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12712 exe result
12713 endif
12714
12715 elseif type(result) == 3
12716 " if result from user's funcref is a List...
12717" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12718 for action in result
12719 if action == "refresh"
12720" call Decho("refreshing display",'~'.expand("<slnum>"))
12721 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12722 elseif action != ""
12723" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12724 exe action
12725 endif
12726 endfor
12727 endif
12728
12729" call Dret("s:UserMaps")
12730endfun
12731
Bram Moolenaar85850f32019-07-19 22:05:51 +020012732" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012733" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012734" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012735let &cpo= s:keepcpo
12736unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012737
Bram Moolenaar85850f32019-07-19 22:05:51 +020012738" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012739" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012740" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012741" vim:ts=8 fdm=marker