blob: 5ea8319cf0ec136495d268d6959debfdbe0ec24e [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 Moolenaar89a9c152021-08-29 21:55:35 +02001754 call s:NetrwSetSafeSetting("&go","begmr")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001755 call s:NetrwSetSafeSetting("&l:hid",0)
1756 call s:NetrwSetSafeSetting("&l:im",0)
1757 setl isk+=@ isk+=* isk+=/
1758 call s:NetrwSetSafeSetting("&l:magic",1)
1759 if g:netrw_use_noswf
1760 call s:NetrwSetSafeSetting("swf",0)
1761 endif
1762 call s:NetrwSetSafeSetting("&l:report",10000)
1763 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1764 call s:NetrwSetSafeSetting("&l:spell",0)
1765 call s:NetrwSetSafeSetting("&l:tw",0)
1766 call s:NetrwSetSafeSetting("&l:wig","")
1767 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001768
1769 " set up cuc and cul based on g:netrw_cursor and listing style
1770 " COMBAK -- cuc cul related
1771 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001772
1773 " allow the user to override safe options
1774" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1775 if &ft == "netrw"
1776" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1777 keepalt NetrwKeepj doau FileType netrw
1778 endif
1779
1780" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1781" 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>"))
1782" call Dret("s:NetrwOptionsSafe")
1783endfun
1784
1785" ---------------------------------------------------------------------
1786" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1787fun! s:NetrwOptionsRestore(vt)
1788" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001789" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001790" 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 +01001791 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001792" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001793" call Decho("..doing filetype detect anyway")
1794 filetype detect
1795" 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>"))
1796" 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 +02001797" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001798 return
1799 endif
1800 unlet {a:vt}netrw_optionsave
1801
1802 if exists("+acd")
1803 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001804" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001805 let curdir = getcwd()
1806 let &l:acd = {a:vt}netrw_acdkeep
1807 unlet {a:vt}netrw_acdkeep
1808 if &l:acd
1809 call s:NetrwLcd(curdir)
1810 endif
1811 endif
1812 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001813" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001814 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1815 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1816 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1817 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1818 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001819" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001820 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1821 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1822 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1823 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1824 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001825" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001826 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1827 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1828 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1829 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1830 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001831 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001832" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1833 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1834 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
1835 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&l:go")
1836 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1837" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1838 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1839 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1840" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1841 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1842" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1843 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1844 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001845 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001846 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1847 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1848" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1850 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1851 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1852 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1853" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001854 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001855 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1856 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1857 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001858 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001859" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001860 call s:NetrwRestoreSetting("s:yykeep","@@")
1861 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1862 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1863 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1864 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1865
Bram Moolenaara6878372014-03-22 21:02:50 +01001866 if exists("{a:vt}netrw_swfkeep")
1867 if &directory == ""
1868 " user hasn't specified a swapfile directory;
1869 " netrw will temporarily set the swapfile directory
1870 " to the current directory as returned by getcwd().
1871 let &l:directory= getcwd()
1872 sil! let &l:swf = {a:vt}netrw_swfkeep
1873 setl directory=
1874 unlet {a:vt}netrw_swfkeep
1875 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001876 if !g:netrw_use_noswf
1877 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1878 sil! let &l:swf= {a:vt}netrw_swfkeep
1879 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001880 unlet {a:vt}netrw_swfkeep
1881 endif
1882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001883 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001884 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1885 if exists("{a:vt}netrw_dirkeep")
1886 call s:NetrwLcd(dirkeep)
1887 unlet {a:vt}netrw_dirkeep
1888 endif
1889 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001890 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001891" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001892 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1893 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001894 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001895 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001896
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001897" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1898" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1899" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1900" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1901" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001902 " Moved the filetype detect here from NetrwGetFile() because remote files
1903 " were having their filetype detect-generated settings overwritten by
1904 " NetrwOptionRestore.
1905 if &ft != "netrw"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001906" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001907 filetype detect
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001908" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001909 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001910" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001911" 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 +02001912" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001913endfun
1914
1915" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001916" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1917" but only when the options' value and the safe setting differ
1918" Doing this means that netrw will not come up as having changed a
1919" setting last when it really didn't actually change it.
1920"
1921" Called from s:NetrwOptionsSafe
1922" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1923fun! s:NetrwSetSafeSetting(setting,safesetting)
1924" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001925
Bram Moolenaar85850f32019-07-19 22:05:51 +02001926 if a:setting =~ '^&'
1927" call Decho("fyi: a:setting starts with &")
1928 exe "let settingval= ".a:setting
1929" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001930
Bram Moolenaar85850f32019-07-19 22:05:51 +02001931 if settingval != a:safesetting
1932" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1933 if type(a:safesetting) == 0
1934 exe "let ".a:setting."=".a:safesetting
1935 elseif type(a:safesetting) == 1
1936 exe "let ".a:setting."= '".a:safesetting."'"
1937 else
1938 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1939 endif
1940 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001941 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001942
Bram Moolenaar85850f32019-07-19 22:05:51 +02001943" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001944endfun
1945
1946" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001947" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1948" but only if the setting value differs from the associated keepvar.
1949" Doing this means that netrw will not come up as having changed a
1950" setting last when it really didn't actually change it.
1951"
1952" Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
1953" keepvars are set up by s:NetrwOptionsSave
1954fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001955""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001956
Bram Moolenaar85850f32019-07-19 22:05:51 +02001957 " typically called from s:NetrwOptionsRestore
1958 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1959 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001960 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001961 if exists(a:keepvar)
1962 exe "let keepvarval= ".a:keepvar
1963 exe "let setting= ".a:setting
1964
1965"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1966"" call Decho("fyi: keepvarval=".keepvarval)
1967"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1968
1969 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001970"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001971 if type(a:setting) == 0
1972 exe "let ".a:setting."= ".keepvarval
1973 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001974 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001975 else
1976 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1977 endif
1978 endif
1979
1980 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001981 endif
1982
Bram Moolenaar85850f32019-07-19 22:05:51 +02001983"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001984endfun
1985
1986" ---------------------------------------------------------------------
1987" NetrwStatusLine: {{{2
1988fun! NetrwStatusLine()
1989
1990" vvv NetrwStatusLine() debugging vvv
1991" let g:stlmsg=""
1992" if !exists("w:netrw_explore_bufnr")
1993" let g:stlmsg="!X<explore_bufnr>"
1994" elseif w:netrw_explore_bufnr != bufnr("%")
1995" let g:stlmsg="explore_bufnr!=".bufnr("%")
1996" endif
1997" if !exists("w:netrw_explore_line")
1998" let g:stlmsg=" !X<explore_line>"
1999" elseif w:netrw_explore_line != line(".")
2000" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2001" endif
2002" if !exists("w:netrw_explore_list")
2003" let g:stlmsg=" !X<explore_list>"
2004" endif
2005" ^^^ NetrwStatusLine() debugging ^^^
2006
2007 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")
2008 " restore user's status line
2009 let &stl = s:netrw_users_stl
2010 let &laststatus = s:netrw_users_ls
2011 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2012 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2013 return ""
2014 else
2015 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2016 endif
2017endfun
2018
Bram Moolenaar85850f32019-07-19 22:05:51 +02002019" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002020" Netrw Transfer Functions: {{{1
2021" ===============================
2022
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002024" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002025" mode: =0 read remote file and insert before current line
2026" =1 read remote file and insert after current line
2027" =2 replace with remote file
2028" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002029fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002030" 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 +00002031
Bram Moolenaar5c736222010-01-06 20:54:52 +01002032 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002033 call s:NetrwOptionsSave("w:")
2034 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002035 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002036 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2037 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2038 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002039" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002040
Bram Moolenaar5c736222010-01-06 20:54:52 +01002041 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002042 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002043 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002044 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002045 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002046 elseif a:mode == 2 " replace with remote file
2047 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002048 elseif a:mode == 3 " skip read of file (leave as temporary)
2049 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002050 else
2051 exe a:mode
2052 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002054 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002055" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056
Bram Moolenaar5c736222010-01-06 20:54:52 +01002057 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002058 let tmpfile= s:GetTempfile("")
2059 if tmpfile == ""
2060" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002061 return
2062 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002065
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002066 " attempt to repeat with previous host-file-etc
2067 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002068" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 let choice = b:netrw_lastfile
2070 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 else
2073 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002074" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002075
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002076 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002077 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002078 echomsg 'NetRead Usage:'
2079 echomsg ':Nread machine:path uses rcp'
2080 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2081 echomsg ':Nread "machine id password path" uses ftp'
2082 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2083 echomsg ':Nread fetch://machine/path uses fetch'
2084 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2085 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002086 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002087 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002088 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2089 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2090 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2091 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002092 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002093 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002094
Bram Moolenaar9964e462007-05-05 17:54:07 +00002095 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002096 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002097" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002098 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002099 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002100 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002101 else
2102 " case "... ... ..."
2103 let choice = strpart(choice,1,strlen(choice)-1)
2104 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002105
Bram Moolenaar9964e462007-05-05 17:54:07 +00002106 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 let wholechoice = wholechoice . " " . choice
2108 let ichoice = ichoice + 1
2109 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002110 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002112 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002113" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 return
2115 endif
2116 let choice= a:{ichoice}
2117 endwhile
2118 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2119 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120 endif
2121 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002123" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002125
Bram Moolenaar5c736222010-01-06 20:54:52 +01002126 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002127 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002128 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002129" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002130 return
2131 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002132 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002133
Bram Moolenaar8d043172014-01-23 14:24:41 +01002134 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002135" 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 +02002136 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002138 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002139" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002142
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002143 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002144 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002145 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002146 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2147 echo "(netrw) Processing your read request..."
2148 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002149
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002151 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002153" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002154 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002155 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002156 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002157 " ER: the tmpfile is full path: rcp sees C:\... as host C
2158 if s:netrw_has_nt_rcp == 1
2159 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2160 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2161 else
2162 " Any way needed it machine contains a '.'
2163 let uid_machine = g:netrw_machine .'.'. $USERNAME
2164 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002165 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2167 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2168 else
2169 let uid_machine = g:netrw_machine
2170 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002172 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 +00002173 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002175
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002176 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002177 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002178 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002179" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002180 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002181 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002182 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002183 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002184 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002186 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002187 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002189 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002190 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193 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 +00002194 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002196 endif
2197 " 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 +00002198 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002199 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002200 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002201 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002202 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002203 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002204 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002206 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2207 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002208 q!
2209 endif
2210 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002211 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002213
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002214 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002215 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002216 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2217 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002218" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002219 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002220 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002221 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002222 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002224 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002225" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002227 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002228" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002230
Bram Moolenaar97d62492012-11-15 21:28:22 +01002231 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002232 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002235 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002237 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002238" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002239 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002242 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002244
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002245 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002246 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002248 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002249 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002251" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002252 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002255
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002256 " perform ftp:
2257 " -i : turns off interactive prompting from ftp
2258 " -n unix : DON'T use <.netrc>, even though it exists
2259 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002260 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002261 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2263 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002265 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002266 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002267 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002269 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002270 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002272
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002273 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002274 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002275 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002278 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 else
2280 let useport= ""
2281 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002282 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2283 " This is workaround to avoid mis-handle windows local-path:
2284 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2285 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2286 else
2287 let tmpfile_get = tmpfile
2288 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002289 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 +00002290 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002292
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002294 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002295 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002296" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002297 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002298 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002299 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002300 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002301" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002302 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002304
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002305 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2306 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002307" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002308 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002309 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 +00002310 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002311 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 +00002312 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002313 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002314
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002315 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002316 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002317" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002318 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2319 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002320" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2321" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2322 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 +00002323 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002325 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 endif
2327 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002329 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002330
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002332 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002333 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002335
Bram Moolenaar5c736222010-01-06 20:54:52 +01002336 if !executable(g:netrw_dav_cmd)
2337 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2338" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2339 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002340 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002341 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002342 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 +01002343 else
2344 " Construct execution string (four lines) which will be passed through filter
2345 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2346 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002347 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002349 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002350 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002351 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002353 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002354 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002355 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002356 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2357 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002358
Bram Moolenaar5c736222010-01-06 20:54:52 +01002359 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002360 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002361 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002362 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002363 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002364 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002365 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002366
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002367 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002369 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002370" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002371 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 +00002372 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002373 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002374
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002375 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002376 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002377 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002378 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002379" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002380 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002381 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002382 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002383 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002384" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002385 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002387 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002388 let netrw_option= "http"
2389 else
2390 let netrw_option= "ftp"
2391 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002392" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002393
Bram Moolenaar446cb832008-06-24 21:56:24 +00002394 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002395 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 +00002396 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002397 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 +00002398 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002399
Bram Moolenaar446cb832008-06-24 21:56:24 +00002400 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002401 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002402" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002403 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002404
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002405 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002406 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002407 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2409 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 +00002410 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002411 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002412
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002413 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002414 " NetRead: (file) NetRead Method #10 {{{3
2415 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002416" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2417 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002418 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2419 let b:netrw_lastfile = choice
2420
2421 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002422 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002423 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002424 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002425 endif
2426 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002427
Bram Moolenaar5c736222010-01-06 20:54:52 +01002428 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002430" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002431 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002432 unlet b:netrw_fname
2433 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002434 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 +01002435" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002436 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002437 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002438 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002439
Bram Moolenaar9964e462007-05-05 17:54:07 +00002440" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441endfun
2442
2443" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002444" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002445fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002447
Bram Moolenaar5c736222010-01-06 20:54:52 +01002448 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002449 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002450 call s:NetrwOptionsSave("w:")
2451 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002452
Bram Moolenaar5c736222010-01-06 20:54:52 +01002453 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002454 let tmpfile= s:GetTempfile("")
2455 if tmpfile == ""
2456" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002457 return
2458 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002459
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002460 if a:0 == 0
2461 let ichoice = 0
2462 else
2463 let ichoice = 1
2464 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaar9964e462007-05-05 17:54:07 +00002466 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002467" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002468 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002469 " For binary writes, always write entire file.
2470 " (line numbers don't really make sense for that).
2471 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002472" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002473 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474 elseif g:netrw_cygwin
2475 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002476 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002477" 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 +01002478 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002479 else
2480 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002481" 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 +01002482 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002483 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002484
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002486 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002487 " on the temporary file's name. Deletion of the temporary file during
2488 " cleanup then causes an error message.
2489 0file!
2490 endif
2491
Bram Moolenaar5c736222010-01-06 20:54:52 +01002492 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002493 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002494
Bram Moolenaar9964e462007-05-05 17:54:07 +00002495 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002496 " attempt to repeat with previous host-file-etc
2497 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002498" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002499 let choice = b:netrw_lastfile
2500 let ichoice= ichoice + 1
2501 else
2502 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002503
Bram Moolenaar8d043172014-01-23 14:24:41 +01002504 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002506 echomsg 'NetWrite Usage:"'
2507 echomsg ':Nwrite machine:path uses rcp'
2508 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2509 echomsg ':Nwrite "machine id password path" uses ftp'
2510 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2511 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2512 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2513 echomsg ':Nwrite rcp://machine/path uses rcp'
2514 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2515 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2516 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002517 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002518 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002519
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002520 elseif match(choice,"^\"") != -1
2521 if match(choice,"\"$") != -1
2522 " case "..."
2523 let choice=strpart(choice,1,strlen(choice)-2)
2524 else
2525 " case "... ... ..."
2526 let choice = strpart(choice,1,strlen(choice)-1)
2527 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002528
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002529 while match(choice,"\"$") == -1
2530 let wholechoice= wholechoice . " " . choice
2531 let ichoice = ichoice + 1
2532 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002533 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002534 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002535 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002536" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002537 return
2538 endif
2539 let choice= a:{ichoice}
2540 endwhile
2541 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2542 endif
2543 endif
2544 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002546" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002547
Bram Moolenaar9964e462007-05-05 17:54:07 +00002548 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002549 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002550 if !exists("b:netrw_method") || b:netrw_method < 0
2551" call Dfunc("netrw#NetWrite : unsupported method")
2552 return
2553 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002554
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002555 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002556 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002557 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002558 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2559 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002560" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002561 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002562
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002563 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002565 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002566" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 if s:netrw_has_nt_rcp == 1
2568 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2569 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2570 else
2571 let uid_machine = g:netrw_machine .'.'. $USERNAME
2572 endif
2573 else
2574 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2575 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2576 else
2577 let uid_machine = g:netrw_machine
2578 endif
2579 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002580 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 +00002581 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002582
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002583 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002584 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002585 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002586" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002587 let netrw_fname = b:netrw_fname
2588
2589 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2590 let bhkeep = &l:bh
2591 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002592 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002594
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002595" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002596 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002597 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002598" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002599 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002600 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002602 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002603 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002605 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606 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 +00002607 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2609 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 endif
2611 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2612 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002613 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002615 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002616 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002618
2619 " remove enew buffer (quietly)
2620 let filtbuf= bufnr("%")
2621 exe curbuf."b!"
2622 let &l:bh = bhkeep
2623 exe filtbuf."bw!"
2624
Bram Moolenaar071d4272004-06-13 20:20:40 +00002625 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002626
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002627 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002628 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002629 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002630 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002631" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002632 let netrw_fname = b:netrw_fname
2633 let bhkeep = &l:bh
2634
2635 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2636 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002637 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002638 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002639 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002640
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002641 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002642 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002643" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002644 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002645 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002646" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002647 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002648 if exists("g:netrw_uid") && g:netrw_uid != ""
2649 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002650 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002651" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002652 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002653 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002654 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002655" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002656 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002657 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002659 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002663 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002664 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002666 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002667 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002669 " save choice/id/password for future use
2670 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002671
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002672 " perform ftp:
2673 " -i : turns off interactive prompting from ftp
2674 " -n unix : DON'T use <.netrc>, even though it exists
2675 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002676 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2679 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002680 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002681 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002682 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002683 let mod=1
2684 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002685
2686 " remove enew buffer (quietly)
2687 let filtbuf= bufnr("%")
2688 exe curbuf."b!"
2689 let &l:bh= bhkeep
2690 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002691
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002692 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002693 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002694 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002695" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002696 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002697 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002698 else
2699 let useport= ""
2700 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002701 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 +00002702 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002703
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002705 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002706 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002708 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2709 if executable(curl)
2710 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002711 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 +01002712 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002713 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002714 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002715
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002716 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002717 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002718 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002719" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002720
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002721 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002722 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2723 let bhkeep = &l:bh
2724
2725 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2726 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002727 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002728 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002729
Bram Moolenaarff034192013-04-24 18:51:19 +02002730 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002731 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002732 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002733 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002734 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002735 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002736 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002737 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002738 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002739 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002740
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002742 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002743 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002744
2745 " remove enew buffer (quietly)
2746 let filtbuf= bufnr("%")
2747 exe curbuf."b!"
2748 let &l:bh = bhkeep
2749 exe filtbuf."bw!"
2750
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002751 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002752
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002753 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002754 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002755 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002756" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002757 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 +00002758 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002759
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002760 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002761 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002762 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002763" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002764 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2766 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2767 else
2768 let uid_machine = g:netrw_machine
2769 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002770
2771 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2772 let bhkeep = &l:bh
2773 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002774 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002775 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002776
Bram Moolenaarff034192013-04-24 18:51:19 +02002777 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002778 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002780 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002781 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002782 let filtbuf= bufnr("%")
2783 exe curbuf."b!"
2784 let &l:bh = bhkeep
2785 exe filtbuf."bw!"
2786 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002787
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002788 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002789 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002790 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002791 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002792 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002794 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002795
Bram Moolenaar5c736222010-01-06 20:54:52 +01002796 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002797" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002798 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002799" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002800 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002801 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002802 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002803
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002804 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002805 " restore modifiability; usually equivalent to set nomod
2806 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002807" 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 +02002808 elseif !exists("leavemod")
2809 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002811 setl nomod
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 Moolenaar071d4272004-06-13 20:20:40 +00002813 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002814
Bram Moolenaar9964e462007-05-05 17:54:07 +00002815" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002816endfun
2817
2818" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002819" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002820" uses NetRead to get a copy of the file into a temporarily file,
2821" then sources that file,
2822" then removes that file.
2823fun! netrw#NetSource(...)
2824" call Dfunc("netrw#NetSource() a:0=".a:0)
2825 if a:0 > 0 && a:1 == '?'
2826 " give help
2827 echomsg 'NetSource Usage:'
2828 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2829 echomsg ':Nsource fetch://machine/path uses fetch'
2830 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002831 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002832 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2833 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2834 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2835 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2836 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002837 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002838 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002839 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002840 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002841" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002842 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002843" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002844 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002845" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002846 if delete(s:netrw_tmpfile)
2847 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2848 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002849 unlet s:netrw_tmpfile
2850 else
2851 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2852 endif
2853 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002854 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 endif
2856" call Dret("netrw#NetSource")
2857endfun
2858
Bram Moolenaar8d043172014-01-23 14:24:41 +01002859" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002860" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2861" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002862fun! netrw#SetTreetop(iscmd,...)
2863" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2864" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002865
Bram Moolenaar85850f32019-07-19 22:05:51 +02002866 " iscmd==0: netrw#SetTreetop called using gn mapping
2867 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2868" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002869 " clear out the current tree
2870 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002871" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002872 let inittreetop= w:netrw_treetop
2873 unlet w:netrw_treetop
2874 endif
2875 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002876" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002877 unlet w:netrw_treedict
2878 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002879" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002880
Bram Moolenaar85850f32019-07-19 22:05:51 +02002881 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002882 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002883" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002884 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002885 if isdirectory(s:NetrwFile(a:1))
2886" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002887 let treedir = a:1
2888 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002890 let treedir = b:netrw_curdir."/".a:1
2891 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002892" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002893 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002894 " normally the cursor is left in the message window.
2895 " However, here this results in the directory being listed in the message window, which is not wanted.
2896 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002897 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002898 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002899 let treedir = "."
2900 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002901 endif
2902 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002904
2905 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002906 let islocal= expand("%") !~ '^\a\{3,}://'
2907" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002908
2909 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002910 if islocal
2911 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2912 else
2913 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2914 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002915
Bram Moolenaara6878372014-03-22 21:02:50 +01002916" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002917endfun
2918
Bram Moolenaar9964e462007-05-05 17:54:07 +00002919" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002920" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002921" readcmd == %r : replace buffer with newly read file
2922" == 0r : read file at top of buffer
2923" == r : read file after current line
2924" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002925fun! s:NetrwGetFile(readcmd, tfile, method)
2926" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002927
2928 " readcmd=='t': simply do nothing
2929 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002930" 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 +01002931" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002932 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002933 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002934
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935 " get name of remote filename (ie. url and all)
2936 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002937" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002938
Bram Moolenaar9964e462007-05-05 17:54:07 +00002939 if exists("*NetReadFixup")
2940 " for the use of NetReadFixup (not otherwise used internally)
2941 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002942 endif
2943
Bram Moolenaar9964e462007-05-05 17:54:07 +00002944 if a:readcmd[0] == '%'
2945 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002947
2948 " rename the current buffer to the temp file (ie. tfile)
2949 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002950 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 else
2952 let tfile= a:tfile
2953 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002954 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955
2956 " edit temporary file (ie. read the temporary file in)
2957 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002958" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959 call zip#Browse(tfile)
2960 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002961" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002962 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002963 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002964" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002966 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002969 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002971 call tar#Browse(tfile)
2972 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002973" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002974 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002977 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 endif
2979
2980 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002981 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002982
Bram Moolenaar97d62492012-11-15 21:28:22 +01002983 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002984 " Note that isk must not include a "/" for scripts.vim
2985 " to process this detection correctly.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002987 let iskkeep= &l:isk
2988 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002989 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002990" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002991 let line1 = 1
2992 let line2 = line("$")
2993
Bram Moolenaar8d043172014-01-23 14:24:41 +01002994 elseif !&ma
2995 " 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 +01002996 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002997" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002998 return
2999
Bram Moolenaar9964e462007-05-05 17:54:07 +00003000 elseif s:FileReadable(a:tfile)
3001 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003002" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003003 let curline = line(".")
3004 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003005" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003006 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003007 let line1= curline + 1
3008 let line2= line("$") - lastline + 1
3009
3010 else
3011 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003012" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3013" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003014 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003015" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003016 return
3017 endif
3018
3019 " User-provided (ie. optional) fix-it-up command
3020 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003021" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003022 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003023" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003025 endif
3026
Bram Moolenaaradc21822011-04-01 18:03:16 +02003027 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003028 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003029 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003030 endif
3031
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003032" 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 +00003033
3034 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003035" redraw!
3036
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003037" 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 +00003038" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003039endfun
3040
Bram Moolenaar9964e462007-05-05 17:54:07 +00003041" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003042" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003043" Input:
3044" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3045" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003046" b:netrw_method= 1: rcp
3047" 2: ftp + <.netrc>
3048" 3: ftp + machine, id, password, and [path]filename
3049" 4: scp
3050" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003051" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003052" 7: rsync
3053" 8: fetch
3054" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003055" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003056" g:netrw_machine= hostname
3057" b:netrw_fname = filename
3058" g:netrw_port = optional port number (for ftp)
3059" g:netrw_choice = copy of input url (choice)
3060fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003061" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003062
Bram Moolenaar251e1912011-06-19 05:09:16 +02003063 " sanity check: choice should have at least three slashes in it
3064 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3065 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3066 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003067" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003068 return
3069 endif
3070
Bram Moolenaar5c736222010-01-06 20:54:52 +01003071 " record current g:netrw_machine, if any
3072 " curmachine used if protocol == ftp and no .netrc
3073 if exists("g:netrw_machine")
3074 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003075" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003076 else
3077 let curmachine= "N O T A HOST"
3078 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003079 if exists("g:netrw_port")
3080 let netrw_port= g:netrw_port
3081 endif
3082
3083 " insure that netrw_ftp_cmd starts off every method determination
3084 " with the current g:netrw_ftp_cmd
3085 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003086
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003087 " initialization
3088 let b:netrw_method = 0
3089 let g:netrw_machine = ""
3090 let b:netrw_fname = ""
3091 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003092 let g:netrw_choice = a:choice
3093
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003094 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003095 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003096 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3097 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003098 " rcpurm : rcp://[user@]host/filename Use rcp
3099 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003100 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003101 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003102 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003103 " rsyncurm : rsync://host[:port]/path Use rsync
3104 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3105 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003106 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003107 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3108 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003109 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3110 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003112 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003113 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003114 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003116 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003117 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003118 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003119
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003120" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003122 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003124" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003125 let b:netrw_method = 1
3126 let userid = substitute(a:choice,rcpurm,'\1',"")
3127 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3128 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 if userid != ""
3130 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003132
Bram Moolenaaradc21822011-04-01 18:03:16 +02003133 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003135" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003136 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003137 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3138 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3139 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003140
Bram Moolenaar15146672011-10-20 22:22:38 +02003141 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003143" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003144 let b:netrw_method = 5
3145 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3146 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003147 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003148
Bram Moolenaaradc21822011-04-01 18:03:16 +02003149 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003150 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003151" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003152 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003153 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003154 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3155 else
3156 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3157 endif
3158 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003159
Bram Moolenaaradc21822011-04-01 18:03:16 +02003160 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003161 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003162" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003163 let b:netrw_method = 7
3164 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3165 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003166
Bram Moolenaaradc21822011-04-01 18:03:16 +02003167 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003168 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003169" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003170 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003171 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3172 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3173 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003174" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003175 if userid != ""
3176 let g:netrw_uid= userid
3177 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003178
Bram Moolenaaradc21822011-04-01 18:03:16 +02003179 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003180 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003181 call NetUserPass("ftp:".g:netrw_machine)
3182 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003183 " if there's a change in hostname, require password re-entry
3184 unlet s:netrw_passwd
3185 endif
3186 if exists("netrw_port")
3187 unlet netrw_port
3188 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003189 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003190
Bram Moolenaar446cb832008-06-24 21:56:24 +00003191 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003192 let b:netrw_method = 3
3193 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003194 let host= substitute(g:netrw_machine,'\..*$','','')
3195 if exists("s:netrw_hup[host]")
3196 call NetUserPass("ftp:".host)
3197
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003198 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003199" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3200" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003201 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003202 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003203" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003204 endif
3205 let b:netrw_method= 2
3206 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003207" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003208 let b:netrw_method= 2
3209 else
3210 if !exists("g:netrw_uid") || g:netrw_uid == ""
3211 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003212 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003213 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003214 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003215 endif
3216 let b:netrw_method= 3
3217 endif
3218 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003219
Bram Moolenaaradc21822011-04-01 18:03:16 +02003220 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003221 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003222" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003223 let b:netrw_method = 8
3224 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3225 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3226 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3227 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003228
Bram Moolenaaradc21822011-04-01 18:03:16 +02003229 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003231" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003233 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3234 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003235 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003236 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003237 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003238
Bram Moolenaaradc21822011-04-01 18:03:16 +02003239 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003240 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003241" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003242 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 let b:netrw_method = 3
3244 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3245 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003246
Bram Moolenaar9964e462007-05-05 17:54:07 +00003247 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 let b:netrw_method = 2
3249 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3250 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3251 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003252
Bram Moolenaaradc21822011-04-01 18:03:16 +02003253 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003254 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003255" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003256 let b:netrw_method = 9
3257 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3258 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003259
Bram Moolenaaradc21822011-04-01 18:03:16 +02003260 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003261 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003262" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003263 let b:netrw_method = 1
3264 let userid = substitute(a:choice,rcphf,'\2',"")
3265 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3266 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003267" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3268" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3269" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3270" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003271 if userid != ""
3272 let g:netrw_uid= userid
3273 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003274
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003275 " Method#10: file://user@hostname/...path-to-file {{{3
3276 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003277" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003278 let b:netrw_method = 10
3279 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003280" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003281
Bram Moolenaaradc21822011-04-01 18:03:16 +02003282 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003283 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003284 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003285 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003286 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003287 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003288 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003289 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003290
Bram Moolenaar81695252004-12-29 20:58:21 +00003291 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003292 " remove any leading [:#] from port number
3293 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3294 elseif exists("netrw_port")
3295 " retain port number as implicit for subsequent ftp operations
3296 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003297 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003298
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003299" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3300" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3301" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3302" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003303" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003304" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003305" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003306" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003307" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003308" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003309" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003310" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312
3313" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003314" NetReadFixup: this sort of function is typically written by the user {{{2
3315" to handle extra junk that their system's ftp dumps
3316" into the transfer. This function is provided as an
3317" example and as a fix for a Windows 95 problem: in my
3318" experience, win95's ftp always dumped four blank lines
3319" at the end of the transfer.
3320if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3321 fun! NetReadFixup(method, line1, line2)
3322" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003323
3324 " sanity checks -- attempt to convert inputs to integers
3325 let method = a:method + 0
3326 let line1 = a:line1 + 0
3327 let line2 = a:line2 + 0
3328 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3329" call Dret("NetReadFixup")
3330 return
3331 endif
3332
Bram Moolenaar9964e462007-05-05 17:54:07 +00003333 if method == 3 " ftp (no <.netrc>)
3334 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003335 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003336 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003337 call histdel("/",-1)
3338 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003339 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003340
Bram Moolenaar9964e462007-05-05 17:54:07 +00003341" call Dret("NetReadFixup")
3342 endfun
3343endif
3344
3345" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003346" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003347" Usage: :call NetUserPass() -- will prompt for userid and password
3348" :call NetUserPass("uid") -- will prompt for password
3349" :call NetUserPass("uid","password") -- sets global userid and password
3350" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3351" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352fun! NetUserPass(...)
3353
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003354" call Dfunc("NetUserPass() a:0=".a:0)
3355
3356 if !exists('s:netrw_hup')
3357 let s:netrw_hup= {}
3358 endif
3359
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003361 " case: no input arguments
3362
3363 " change host and username if not previously entered; get new password
3364 if !exists("g:netrw_machine")
3365 let g:netrw_machine= input('Enter hostname: ')
3366 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003368 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369 let g:netrw_uid= input('Enter username: ')
3370 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003371 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003372 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003373
3374 " set up hup database
3375 let host = substitute(g:netrw_machine,'\..*$','','')
3376 if !exists('s:netrw_hup[host]')
3377 let s:netrw_hup[host]= {}
3378 endif
3379 let s:netrw_hup[host].uid = g:netrw_uid
3380 let s:netrw_hup[host].passwd = s:netrw_passwd
3381
3382 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003383 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003384
3385 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003386 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003387 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003388" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003389 let host = substitute(a:1,'^ftp:','','')
3390 let host = substitute(host,'\..*','','')
3391 if exists("s:netrw_hup[host]")
3392 let g:netrw_uid = s:netrw_hup[host].uid
3393 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003394" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3395" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003396 else
3397 let g:netrw_uid = input("Enter UserId: ")
3398 let s:netrw_passwd = inputsecret("Enter Password: ")
3399 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003400
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003401 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003402 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003403" 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 +02003404 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003405 if g:netrw_machine =~ '[0-9.]\+'
3406 let host= g:netrw_machine
3407 else
3408 let host= substitute(g:netrw_machine,'\..*$','','')
3409 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003410 else
3411 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003412 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003413 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003414" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003415 if exists("g:netrw_passwd")
3416 " ask for password if one not previously entered
3417 let s:netrw_passwd= g:netrw_passwd
3418 else
3419 let s:netrw_passwd = inputsecret("Enter Password: ")
3420 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003421 endif
3422
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003423" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003424 if exists("host")
3425 if !exists('s:netrw_hup[host]')
3426 let s:netrw_hup[host]= {}
3427 endif
3428 let s:netrw_hup[host].uid = g:netrw_uid
3429 let s:netrw_hup[host].passwd = s:netrw_passwd
3430 endif
3431
3432 elseif a:0 == 2
3433 let g:netrw_uid = a:1
3434 let s:netrw_passwd = a:2
3435
3436 elseif a:0 == 3
3437 " enter hostname, user-id, and password into the hup dictionary
3438 let host = substitute(a:1,'^\a\+:','','')
3439 let host = substitute(host,'\..*$','','')
3440 if !exists('s:netrw_hup[host]')
3441 let s:netrw_hup[host]= {}
3442 endif
3443 let s:netrw_hup[host].uid = a:2
3444 let s:netrw_hup[host].passwd = a:3
3445 let g:netrw_uid = s:netrw_hup[host].uid
3446 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003447" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3448" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003449 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003450
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003451" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003452endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453
Bram Moolenaar85850f32019-07-19 22:05:51 +02003454" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003455" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003456" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003458" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003459" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3460fun! s:ExplorePatHls(pattern)
3461" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3462 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003463" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003464 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003465" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003466 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3467" call Dret("s:ExplorePatHls repat<".repat.">")
3468 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003469endfun
3470
3471" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003472" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003473" 0: (user: <mb>) bookmark current directory
3474" 1: (user: <gb>) change to the bookmarked directory
3475" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003476" 3: (browsing) records current directory history
3477" 4: (user: <u>) go up (previous) directory, using history
3478" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003479" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003480fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003481" 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 +02003482 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3483" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3484 return
3485 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003486
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003487 let ykeep = @@
3488 let curbufnr = bufnr("%")
3489
Bram Moolenaar9964e462007-05-05 17:54:07 +00003490 if a:chg == 0
3491 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003492" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003493 if exists("s:netrwmarkfilelist_{curbufnr}")
3494 call s:NetrwBookmark(0)
3495 echo "bookmarked marked files"
3496 else
3497 call s:MakeBookmark(a:curdir)
3498 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003499 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003500
3501 elseif a:chg == 1
3502 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003505" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003506 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003507 else
3508 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3509 endif
3510
3511 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003512" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003513 let didwork= 0
3514 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003515" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003516 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003517" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003518 let cnt= 1
3519 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003520" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003521 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003522 let didwork = 1
3523 let cnt = cnt + 1
3524 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003525 endif
3526
3527 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003528 " Note: history is saved only when PerformListing is done;
3529 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3530 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003531 let first = 1
3532 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003533 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003534 while ( first || cnt != g:netrw_dirhistcnt )
3535" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003536 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003537" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003538 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003539 let didwork= 1
3540 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003541 let histcnt = histcnt + 1
3542 let first = 0
3543 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003544 if cnt < 0
3545 let cnt= cnt + g:netrw_dirhistmax
3546 endif
3547 endwhile
3548 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003549 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003550 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003551 if didwork
3552 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3553 endif
3554
3555 elseif a:chg == 3
3556 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003557" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558 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 +02003559 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003560 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3561 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003562 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003563" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003564 endif
3565
3566 elseif a:chg == 4
3567 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003568" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003569 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3571 if g:netrw_dirhistcnt < 0
3572 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003573 endif
3574 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003575 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003576 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003577 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3578" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003579 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003580 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003581" call Decho("setl ma noro",'~'.expand("<slnum>"))
3582 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003583 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003584" call Decho("setl nomod",'~'.expand("<slnum>"))
3585" 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 +00003586 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003587" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3588 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003589 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003590 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003591 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003592 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003593 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003594 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003595 echo "Sorry, no predecessor directory exists yet"
3596 endif
3597
3598 elseif a:chg == 5
3599 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003600" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003601 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003602 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3603 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3604" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003605 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003606" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003607 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003608 sil! NetrwKeepj %d _
3609" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3610" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003611 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003612" 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 +02003613 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003614" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3615 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003616 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003617 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3618 if g:netrw_dirhistcnt < 0
3619 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003620 endif
3621 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003622 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003623 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003624 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003625 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003626 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003627
3628 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003629" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003630 if exists("s:netrwmarkfilelist_{curbufnr}")
3631 call s:NetrwBookmark(1)
3632 echo "removed marked files from bookmarks"
3633 else
3634 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003635 let iremove = v:count
3636 let dremove = g:netrw_bookmarklist[iremove - 1]
3637" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003638 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003639" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3640 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3641 echo "removed ".dremove." from g:netrw_bookmarklist"
3642" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003643 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003644" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003645 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003646 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003647 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003648 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003649" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003650endfun
3651
3652" ---------------------------------------------------------------------
3653" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003654" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003655" Sister function: s:NetrwBookHistSave()
3656fun! s:NetrwBookHistRead()
3657" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003658 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003659" 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 +02003660 return
3661 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003662 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003663
3664 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003665 if !exists("s:netrw_initbookhist")
3666 let home = s:NetrwHome()
3667 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003668 if filereadable(s:NetrwFile(savefile))
3669" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003670 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003671 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003672
3673 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003674 if g:netrw_dirhistmax > 0
3675 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003676 if filereadable(s:NetrwFile(savefile))
3677" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003678 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003679 endif
3680 let s:netrw_initbookhist= 1
3681 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003682 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003684
Bram Moolenaar97d62492012-11-15 21:28:22 +01003685 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003686" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3687" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003688" call Dret("s:NetrwBookHistRead")
3689endfun
3690
3691" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693" Sister function: s:NetrwBookHistRead()
3694" I used to do this via viminfo but that appears to
3695" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003696" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3697" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003701 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003703 return
3704 endif
3705
Bram Moolenaar5c736222010-01-06 20:54:52 +01003706 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003707" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003708 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003709
3710 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003711 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003713 if g:netrw_use_noswf
3714 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3715 else
3716 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3717 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003718 setl nocin noai noci magic nospell nohid wig= noaw
3719 setl ma noro write
3720 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003721 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003722
Bram Moolenaar85850f32019-07-19 22:05:51 +02003723 " rename enew'd file: .netrwhist -- no attempt to merge
3724 " record dirhistmax and current dirhistcnt
3725 " save history
3726" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003727 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003728 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003729 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3730 if g:netrw_dirhistmax > 0
3731 let lastline = line("$")
3732 let cnt = g:netrw_dirhistcnt
3733 let first = 1
3734 while ( first || cnt != g:netrw_dirhistcnt )
3735 let lastline= lastline + 1
3736 if exists("g:netrw_dirhist_{cnt}")
3737 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3738" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3739 endif
3740 let first = 0
3741 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3742 if cnt < 0
3743 let cnt= cnt + g:netrw_dirhistmax
3744 endif
3745 endwhile
3746 exe "sil! w! ".savefile
3747" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3748 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749
Bram Moolenaar85850f32019-07-19 22:05:51 +02003750 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003751 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003753" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754 " merge and write .netrwbook
3755 let savefile= s:NetrwHome()."/.netrwbook"
3756
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003757 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003759 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003760 for bdm in booklist
3761 if index(g:netrw_bookmarklist,bdm) == -1
3762 call add(g:netrw_bookmarklist,bdm)
3763 endif
3764 endfor
3765 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003766 endif
3767
3768 " construct and save .netrwbook
3769 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003770 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003771" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003772 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003773
3774 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003775 let bgone= bufnr("%")
3776 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003777 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003778
3779" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003780endfun
3781
3782" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003783" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3784" list of the contents of a local or remote directory. It is assumed that the
3785" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3786" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003787" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003788fun! s:NetrwBrowse(islocal,dirname)
3789 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003790" 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 +02003791" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3792" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3793" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003794
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003795 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3796 " This is useful when one edits a local file, then :e ., then :Rex
3797 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3798 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003799" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003800 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003802 " s:NetrwBrowse : initialize history {{{3
3803 if !exists("s:netrw_initbookhist")
3804 NetrwKeepj call s:NetrwBookHistRead()
3805 endif
3806
3807 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003808 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003809 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003810" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003811 else
3812 let dirname= a:dirname
3813 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814
Bram Moolenaar85850f32019-07-19 22:05:51 +02003815 " repoint t:netrw_lexbufnr if appropriate
3816 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3817" call Decho("set repointlexbufnr to true!")
3818 let repointlexbufnr= 1
3819 endif
3820
3821 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822 if exists("s:netrw_skipbrowse")
3823 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003824" 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 +01003825" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003826 return
3827 endif
3828 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003830" call Dret("s:NetrwBrowse : missing shellescape()")
3831 return
3832 endif
3833 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835" call Dret("s:NetrwBrowse : missing fnameescape()")
3836 return
3837 endif
3838
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003839 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003840 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003841
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003842 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003843 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3844 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3845" call Decho("clearing marked files",'~'.expand("<slnum>"))
3846 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3847 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003848 endif
3849
3850 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003851 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3853" 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 +02003854 if s:NetrwLcd(dirname)
3855" call Dret("s:NetrwBrowse : lcd failure")
3856 return
3857 endif
3858 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003859" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003860
Bram Moolenaar5c736222010-01-06 20:54:52 +01003861 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003865" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003867 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003869" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003870
3871 " remove any filetype indicator from end of dirname, except for the
3872 " "this is a directory" indicator (/).
3873 " There shouldn't be one of those here, anyway.
3874 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003875" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003876 call s:RemotePathAnalysis(dirname)
3877
3878 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3879 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003880 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003882" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003883 let b:netrw_curdir = dirname
3884 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003885 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003886 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3887 sil call netrw#NetRead(2,url)
3888 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003889" call Decho("url<".url.">",'~'.expand("<slnum>"))
3890" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3891" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003892 if s:path =~ '.bz2'
3893 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3894 elseif s:path =~ '.gz'
3895 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3896 elseif s:path =~ '.gz'
3897 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3898 else
3899 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3900 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901 endif
3902
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003903 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003904 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003905 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003906" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003907 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003908" 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 +00003909
Bram Moolenaar446cb832008-06-24 21:56:24 +00003910" call Dret("s:NetrwBrowse : file<".s:fname.">")
3911 return
3912 endif
3913
Bram Moolenaaradc21822011-04-01 18:03:16 +02003914 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915 call s:UseBufWinVars()
3916
3917 " set up some variables {{{3
3918 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003919 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 let s:last_sort_by = g:netrw_sort_by
3921
3922 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003923 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003924
Bram Moolenaar97d62492012-11-15 21:28:22 +01003925 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003926" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003927 let svpos = winsaveview()
3928" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003930
Bram Moolenaar446cb832008-06-24 21:56:24 +00003931 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003932 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3933 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3934" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3935" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3936 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3937 else
3938" " call Decho("2match none",'~'.expand("<slnum>"))
3939 2match none
3940 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003941 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003942 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003943 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003945 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003946" 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 +01003947" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 return
3949 endif
3950
3951 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003952" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003953 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003954 if b:netrw_curdir =~ '[/\\]$'
3955 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3956 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003957 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3958 let b:netrw_curdir= b:netrw_curdir."/"
3959 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960 if b:netrw_curdir == ''
3961 if has("amiga")
3962 " On the Amiga, the empty string connotes the current directory
3963 let b:netrw_curdir= getcwd()
3964 else
3965 " under unix, when the root directory is encountered, the result
3966 " from the preceding substitute is an empty string.
3967 let b:netrw_curdir= '/'
3968 endif
3969 endif
3970 if !a:islocal && b:netrw_curdir !~ '/$'
3971 let b:netrw_curdir= b:netrw_curdir.'/'
3972 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974
3975 " ------------
3976 " (local only) {{{3
3977 " ------------
3978 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003980
3981 " Set up ShellCmdPost handling. Append current buffer to browselist
3982 call s:LocalFastBrowser()
3983
3984 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3985 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003986" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3987" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003989 if s:NetrwLcd(b:netrw_curdir)
3990" call Dret("s:NetrwBrowse : lcd failure")
3991 return
3992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993 endif
3994 endif
3995
3996 " --------------------------------
3997 " remote handling: {{{3
3998 " --------------------------------
3999 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001
Bram Moolenaar97d62492012-11-15 21:28:22 +01004002 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003" 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 +02004004 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004005 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4008 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4009 if dirname !~ '/$'
4010 let dirname= dirname.'/'
4011 endif
4012 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004013" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004014 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004015 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004016" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004017 endif
4018
4019 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4020 if dirname !~ dirpat
4021 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004022 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004023 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004024 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004025" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004026 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004027" 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 +00004028" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4029 return
4030 endif
4031 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004033 endif " (additional remote handling)
4034
Bram Moolenaar85850f32019-07-19 22:05:51 +02004035 " -------------------------------
4036 " Perform Directory Listing: {{{3
4037 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004038 NetrwKeepj call s:NetrwMaps(a:islocal)
4039 NetrwKeepj call s:NetrwCommands(a:islocal)
4040 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004041
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004043 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004044" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4045
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046 " If there is a rexposn: restore position with rexposn
4047 " Otherwise : set rexposn
4048 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004049" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4050 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4051 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4052 NetrwKeepj exe w:netrw_bannercnt
4053 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054 else
4055 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4056 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004057 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004058 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004060 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004061 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004062
Bram Moolenaar85850f32019-07-19 22:05:51 +02004063 " repoint t:netrw_lexbufnr if appropriate
4064 if exists("repointlexbufnr")
4065 let t:netrw_lexbufnr= bufnr("%")
4066" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4067 endif
4068
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069 " restore position
4070 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004071" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4072 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004073 endif
4074
Bram Moolenaara6878372014-03-22 21:02:50 +01004075 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004076 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4077 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4079" 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 +02004080" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004081 return
4082endfun
4083
4084" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004085" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4086" may not apply correctly; ie. netrw's idea of the current directory may
4087" differ from vim's. This function insures that netrw's idea of the current
4088" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004089" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004090fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004091" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4092" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4093" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4094" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4095" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004096
4097 " clean up any leading treedepthstring
4098 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4099 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004100" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004101 else
4102 let fname= a:fname
4103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104
4105 if g:netrw_keepdir
4106 " vim's idea of the current directory possibly may differ from netrw's
4107 if !exists("b:netrw_curdir")
4108 let b:netrw_curdir= getcwd()
4109 endif
4110
4111 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004115" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116 else
4117 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004119" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120 endif
4121
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004122 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004124 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004125" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004126 else
4127 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004128 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004129" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004130 endif
4131 else
4132 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004133 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004134" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4135" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4136" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137 endif
4138
Bram Moolenaar85850f32019-07-19 22:05:51 +02004139" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004140 return ret
4141endfun
4142
4143" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004144" s:NetrwFileInfo: supports qf (query for file information) {{{2
4145fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004146" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004147 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004148 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004149 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004150 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004152 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004153 let lsopt= "-lsadh --si"
4154 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004155" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004156 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004157
4158 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004159 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004161
Bram Moolenaara6878372014-03-22 21:02:50 +01004162 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004163 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004165
4166 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004167 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004169
Bram Moolenaar446cb832008-06-24 21:56:24 +00004170 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004172 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004174 endif
4175 else
4176 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004177" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4178 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179 let fname= substitute(a:fname,".$","","")
4180 else
4181 let fname= a:fname
4182 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004183 let t = getftime(s:NetrwFile(fname))
4184 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004185 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004186 let sz= s:NetrwHumanReadable(sz)
4187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004188 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4189" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004190 endif
4191 else
4192 echo "sorry, \"qf\" not supported yet for remote files"
4193 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004194 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004195" call Dret("s:NetrwFileInfo")
4196endfun
4197
4198" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004199" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4200fun! s:NetrwFullPath(filename)
4201" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4202 let filename= a:filename
4203 if filename !~ '^/'
4204 let filename= resolve(getcwd().'/'.filename)
4205 endif
4206 if filename != "/" && filename =~ '/$'
4207 let filename= substitute(filename,'/$','','')
4208 endif
4209" " call Dret("s:NetrwFullPath <".filename.">")
4210 return filename
4211endfun
4212
4213" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004214" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004216" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004217" 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 +00004218fun! s:NetrwGetBuffer(islocal,dirname)
4219" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004220" 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 +02004221" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4222" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004223 let dirname= a:dirname
4224
4225 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004226" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004227 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004228" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004229 let s:netrwbuf= {}
4230 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004231" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4232" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4233
4234 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4235 let bufnum = -1
4236
4237 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4238 if has_key(s:netrwbuf,"NetrwTreeListing")
4239 let bufnum= s:netrwbuf["NetrwTreeListing"]
4240 else
4241 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4242 endif
4243" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4244 if !bufexists(bufnum)
4245 call remove(s:netrwbuf,"NetrwTreeListing"])
4246 let bufnum= -1
4247 endif
4248 elseif bufnr("NetrwTreeListing") != -1
4249 let bufnum= bufnr("NetrwTreeListing")
4250" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4251 else
4252" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4253 let bufnum= -1
4254 endif
4255
4256 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004259 if !bufexists(bufnum)
4260 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4261 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004263
Bram Moolenaar446cb832008-06-24 21:56:24 +00004264 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004265" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004266 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004267 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004268" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4269
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004270 " highjack the current buffer
4271 " IF the buffer already has the desired name
4272 " AND it is empty
4273 let curbuf = bufname("%")
4274 if curbuf == '.'
4275 let curbuf = getcwd()
4276 endif
4277" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
4278" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
4279" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4280" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4281" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4282" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4283 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004284" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4285 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004286 else " DEBUG
4287" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004288 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004289 " 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 +00004290
4291 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004292 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004293" 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 +00004294 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004295" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296 " name the buffer
4297 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4298 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004299" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004300 let w:netrw_treebufnr = bufnr("%")
4301 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004302 if g:netrw_use_noswf
4303 setl nobl bt=nofile noswf
4304 else
4305 setl nobl bt=nofile
4306 endif
4307 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4308 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4309 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4310 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004311" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004313 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004314 " enter the new buffer into the s:netrwbuf dictionary
4315 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4316" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4317" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004319" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320
4321 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004322" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004324 setl ei=all
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004325 if getline(2) =~# '^" Netrw Directory Listing'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004326" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
4327 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004329" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
4330 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004332" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004334 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 endif
4336 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004337
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004338 if line("$") <= 1 && getline(1) == ""
4339 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004340 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004341" 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>"))
4342" 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 +01004343" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4344 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004345
Bram Moolenaar97d62492012-11-15 21:28:22 +01004346 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004347" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004348 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349 sil NetrwKeepj %d _
4350" 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>"))
4351" 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 +01004352" 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 +00004353 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004354
Bram Moolenaar446cb832008-06-24 21:56:24 +00004355 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004356" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4357" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004358 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004359 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004360 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004361" 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>"))
4362" 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 +01004363" 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 +00004364 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004365
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004367" 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>"))
4368" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4369" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004370 return 1
4371 endif
4372 endif
4373
4374 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4375 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4376 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4377 " med 1 D H
4378 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004379" 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 +00004380 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004381 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004382 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004383
4384 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4386" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4387 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004389" 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>"))
4390" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4391" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392 return 0
4393endfun
4394
4395" ---------------------------------------------------------------------
4396" s:NetrwGetcwd: get the current directory. {{{2
4397" Change backslashes to forward slashes, if any.
4398" If doesc is true, escape certain troublesome characters
4399fun! s:NetrwGetcwd(doesc)
4400" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4401 let curdir= substitute(getcwd(),'\\','/','ge')
4402 if curdir !~ '[\/]$'
4403 let curdir= curdir.'/'
4404 endif
4405 if a:doesc
4406 let curdir= fnameescape(curdir)
4407 endif
4408" call Dret("NetrwGetcwd <".curdir.">")
4409 return curdir
4410endfun
4411
4412" ---------------------------------------------------------------------
4413" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4414fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004415" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4416" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4417 let keepsol= &l:sol
4418 setl nosol
4419
Bram Moolenaar446cb832008-06-24 21:56:24 +00004420 call s:UseBufWinVars()
4421
4422 " insure that w:netrw_liststyle is set up
4423 if !exists("w:netrw_liststyle")
4424 if exists("g:netrw_liststyle")
4425 let w:netrw_liststyle= g:netrw_liststyle
4426 else
4427 let w:netrw_liststyle= s:THINLIST
4428 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004429" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430 endif
4431
4432 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4433 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004434" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004435 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004436 let dirname= "./"
4437 let curline= getline('.')
4438
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004439 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004440 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441 let s:netrw_skipbrowse= 1
4442 echo 'Pressing "s" also works'
4443
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004444 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004445 let s:netrw_skipbrowse= 1
4446 echo 'Press "S" to edit sorting sequence'
4447
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004448 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004449 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004451
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004452 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004453 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004454 let s:netrw_skipbrowse= 1
4455 echo 'Pressing "a" also works'
4456
4457 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004458 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004459 endif
4460
4461 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004462" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004463 NetrwKeepj norm! 0
4464 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465
4466 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004467" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004468 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4470
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004471 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004472" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004473 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004474 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475
4476 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004477" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004478 let dirname= getline('.')
4479
4480 if !exists("b:netrw_cpf")
4481 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004482 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 +01004483 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004484" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004485 endif
4486
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004488 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004489" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4490" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004492 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004493 else
4494 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004495 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004496 endif
4497 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004498 let eofname= filestart + b:netrw_cpf + 1
4499 if eofname <= col("$")
4500 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004502 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004503 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004504 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004505 let dirname = @a
4506 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004507" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004509" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510 endif
4511
4512 " symlinks are indicated by a trailing "@". Remove it before further processing.
4513 let dirname= substitute(dirname,"@$","","")
4514
4515 " executables are indicated by a trailing "*". Remove it before further processing.
4516 let dirname= substitute(dirname,"\*$","","")
4517
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004518 let &l:sol= keepsol
4519
Bram Moolenaar446cb832008-06-24 21:56:24 +00004520" call Dret("s:NetrwGetWord <".dirname.">")
4521 return dirname
4522endfun
4523
4524" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004525" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4526" g:netrw_bufsettings will be used after the listing is produced.
4527" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004528fun! s:NetrwListSettings(islocal)
4529" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004530" 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 +00004531 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004532" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4533 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4534 setl bt=nofile nobl ma nonu nowrap noro nornu
4535 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004537 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004538 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004539" call Dredir("ls!","s:NetrwListSettings")
4540" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004541 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004542 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004543 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004544 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004546 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004547 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004548" 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 +00004549" call Dret("s:NetrwListSettings")
4550endfun
4551
4552" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004553" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004554" islocal=0: remote browsing
4555" =1: local browsing
4556fun! s:NetrwListStyle(islocal)
4557" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004558
Bram Moolenaar97d62492012-11-15 21:28:22 +01004559 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560 let fname = s:NetrwGetWord()
4561 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004562 let svpos = winsaveview()
4563" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004564 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004565" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4566" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4567" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004568
Bram Moolenaar85850f32019-07-19 22:05:51 +02004569 " repoint t:netrw_lexbufnr if appropriate
4570 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4571" call Decho("set repointlexbufnr to true!")
4572 let repointlexbufnr= 1
4573 endif
4574
Bram Moolenaar446cb832008-06-24 21:56:24 +00004575 if w:netrw_liststyle == s:THINLIST
4576 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004577" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004578 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4579
4580 elseif w:netrw_liststyle == s:LONGLIST
4581 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004582" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004583 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4584
4585 elseif w:netrw_liststyle == s:WIDELIST
4586 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004587" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004588 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4589
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004590 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004591" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004592 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4593
4594 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004595 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004596 let g:netrw_liststyle = s:THINLIST
4597 let w:netrw_liststyle = g:netrw_liststyle
4598 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4599 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004600 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004601" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602
4603 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004604" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4605 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004606 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004608 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004609" 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 +00004610
4611 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004612" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004613 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004614 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004615
Bram Moolenaar85850f32019-07-19 22:05:51 +02004616 " repoint t:netrw_lexbufnr if appropriate
4617 if exists("repointlexbufnr")
4618 let t:netrw_lexbufnr= bufnr("%")
4619" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4620 endif
4621
Bram Moolenaar13600302014-05-22 18:26:40 +02004622 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004623" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4624 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004625 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004626
4627" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4628endfun
4629
4630" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004631" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4632fun! s:NetrwBannerCtrl(islocal)
4633" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4634
Bram Moolenaar97d62492012-11-15 21:28:22 +01004635 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004636 " toggle the banner (enable/suppress)
4637 let g:netrw_banner= !g:netrw_banner
4638
4639 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004640 let svpos= winsaveview()
4641" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004642 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4643
4644 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004645 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4646 let fname= s:NetrwGetWord()
4647 sil NetrwKeepj $
4648 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4649" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4650 if result <= 0 && exists("w:netrw_bannercnt")
4651 exe "NetrwKeepj ".w:netrw_bannercnt
4652 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004653 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004654 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004655" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4656endfun
4657
4658" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004659" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4660"
4661" No bang: enters files/directories into Netrw's bookmark system
4662" No argument and in netrw buffer:
4663" if there are marked files: bookmark marked files
4664" otherwise : bookmark file/directory under cursor
4665" No argument and not in netrw buffer: bookmarks current open file
4666" Has arguments: globs them individually and bookmarks them
4667"
4668" With bang: deletes files/directories from Netrw's bookmark system
4669fun! s:NetrwBookmark(del,...)
4670" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4671 if a:0 == 0
4672 if &ft == "netrw"
4673 let curbufnr = bufnr("%")
4674
4675 if exists("s:netrwmarkfilelist_{curbufnr}")
4676 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004677" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004678 let svpos = winsaveview()
4679" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004680 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004681 for fname in s:netrwmarkfilelist_{curbufnr}
4682 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4683 endfor
4684 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4685 call s:NetrwUnmarkList(curbufnr,curdir)
4686 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004687" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4688 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004689 else
4690 let fname= s:NetrwGetWord()
4691 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4692 endif
4693
4694 else
4695 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004696" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004697 let fname= expand("%")
4698 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4699 endif
4700
4701 else
4702 " bookmark specified files
4703 " attempts to infer if working remote or local
4704 " by deciding if the current file begins with an url
4705 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004706 let islocal= expand("%") !~ '^\a\{3,}://'
4707" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004708 let i = 1
4709 while i <= a:0
4710 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004711 if v:version > 704 || (v:version == 704 && has("patch656"))
4712 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004713 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004714 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004715 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004716 else
4717 let mbfiles= [a:{i}]
4718 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004720 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004721" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004722 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4723 endfor
4724 let i= i + 1
4725 endwhile
4726 endif
4727
4728 " update the menu
4729 call s:NetrwBookmarkMenu()
4730
4731" call Dret("s:NetrwBookmark")
4732endfun
4733
4734" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004735" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4736" .2.[cnt] for bookmarks, and
4737" .3.[cnt] for history
4738" (see s:NetrwMenu())
4739fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004740 if !exists("s:netrw_menucnt")
4741 return
4742 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004743" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004744
4745 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004746 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004747 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004748" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004749 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4750 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004751 endif
4752 if !exists("s:netrw_initbookhist")
4753 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004754 endif
4755
4756 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004757 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004758 let cnt= 1
4759 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004760" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004761 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004762
4763 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004764 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004765
4766 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004767 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 +01004768 let cnt= cnt + 1
4769 endfor
4770
4771 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004772
4773 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004774 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004775 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004776 let first = 1
4777 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004778 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004779 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004780 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004781 if exists("g:netrw_dirhist_{cnt}")
4782 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004783" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004784 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4785 endif
4786 let first = 0
4787 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4788 if cnt < 0
4789 let cnt= cnt + g:netrw_dirhistmax
4790 endif
4791 endwhile
4792 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004793
Bram Moolenaar9964e462007-05-05 17:54:07 +00004794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004795" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004796endfun
4797
4798" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004799" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4800" directory and a new directory name. Also, if the
4801" "new directory name" is actually a file,
4802" NetrwBrowseChgDir() edits the file.
4803fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004804" 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 +01004805" 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 +00004806
Bram Moolenaar97d62492012-11-15 21:28:22 +01004807 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004808 if !exists("b:netrw_curdir")
4809 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4810 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004811 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004812" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4813" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004814" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004816 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004817 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004818" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004819
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004820 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004822 call s:SavePosn(s:netrw_posn)
4823 NetrwKeepj call s:NetrwOptionsSave("s:")
4824 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004825 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004826 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004827 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004828 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004829 endif
4830 let newdir = a:newdir
4831 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004832 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004833" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004834" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004835" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004836
4837 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004838" 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 +01004839 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004840" 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 +01004841 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004842 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" 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 +01004844 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845" 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 +02004846 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004847 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004848 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004849 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" 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 +01004851 endif
4852 endif
4853" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004854" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004855 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004856
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857 " set up o/s-dependent directory recognition pattern
4858 if has("amiga")
4859 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004860 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861 let dirpat= '[\/]$'
4862 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004863" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864
4865 if dirname !~ dirpat
4866 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004867 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004869" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870 endif
4871
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004872" 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 +01004873 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004874 " ------------------------------
4875 " NetrwBrowseChgDir: edit a file {{{3
4876 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004877" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004878
Bram Moolenaar97d62492012-11-15 21:28:22 +01004879 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004880 let s:rexposn_{bufnr("%")}= winsaveview()
4881" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004882" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4883" 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 +01004884
Bram Moolenaar446cb832008-06-24 21:56:24 +00004885 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004886" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4887" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004888" let newdir = s:NetrwTreePath(s:netrw_treetop)
4889" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004890 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004891 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4892" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4893 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004894 if dirname =~ '/$'
4895 let dirname= dirname.newdir
4896 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004897 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004899" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4900" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004902" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004904 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004907" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004908 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004910" 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 +02004911 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004912 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004913 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004914" " 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 +01004915 if type(g:netrw_browse_split) == 3
4916 " open file in server
4917 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004918" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004919 call s:NetrwServerEdit(a:islocal,dirname)
4920" call Dret("s:NetrwBrowseChgDir")
4921 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004922
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004923 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004924 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004925" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004926 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4927 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004928 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004929 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004930 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004931 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004932
Bram Moolenaar446cb832008-06-24 21:56:24 +00004933 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004934 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004935" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004936 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4937 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004938 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004939 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004940 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004941 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004942
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004944 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004945" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004946 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004947 if !exists("b:netrw_curdir")
4948 let b:netrw_curdir= getcwd()
4949 endif
4950 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004951
Bram Moolenaar446cb832008-06-24 21:56:24 +00004952 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004953 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004954" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004956 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004957" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004958 return
4959 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004960 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004961
Bram Moolenaar9964e462007-05-05 17:54:07 +00004962 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004964" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004965 call s:NetrwMenu(0)
4966 " optional change to window
4967 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004968" 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 +02004969 if winnr("$")+1 == g:netrw_chgwin
4970 " if g:netrw_chgwin is set to one more than the last window, then
4971 " vertically split the last window to make that window available.
4972 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004973 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004974 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004975 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004976 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004977 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004978 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004979 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004980 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004981
Bram Moolenaar9964e462007-05-05 17:54:07 +00004982 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004983
Bram Moolenaar446cb832008-06-24 21:56:24 +00004984 " the point where netrw actually edits the (local) file
4985 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004986 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004987 if !&mod
4988 " if e the new file would fail due to &mod, then don't change any of the flags
4989 let dolockout= 1
4990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004991 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004992" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004993 " some like c-^ to return to the last edited file
4994 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004995 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4996 " so emit error E37 instead.
Bram Moolenaar8d043172014-01-23 14:24:41 +01004997 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004998 exe "NetrwKeepj keepalt e ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004999 else
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005000 exe "NetrwKeepj e ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01005001 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005002" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005003 " COMBAK -- cuc cul related
5004 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005005 if &hidden || &bufhidden == "hide"
5006 " file came from vim's hidden storage. Don't "restore" options with it.
5007 let dorestore= 0
5008 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005009 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005010" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005011 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005012
5013 " handle g:Netrw_funcref -- call external-to-netrw functions
5014 " This code will handle g:Netrw_funcref as an individual function reference
5015 " or as a list of function references. It will ignore anything that's not
5016 " a function reference. See :help Funcref for information about function references.
5017 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005018" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005019 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005021 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005022 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005023" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005025 if type(Fncref) == 2
5026 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005027 endif
5028 endfor
5029 endif
5030 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005031 endif
5032
5033 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005034 " ----------------------------------------------------
5035 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5036 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005037" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005038 let dirname = newdir
5039 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005040 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005041 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005042
5043 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005044 " ---------------------------------------------
5045 " NetrwBrowseChgDir: refresh the directory list {{{3
5046 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005047" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005048 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005049 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005050
5051 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005052 " --------------------------------------
5053 " NetrwBrowseChgDir: go up one directory {{{3
5054 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005055" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005056
5057 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5058 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005059" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5060" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005061 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005062 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005063 endif
5064
5065 if has("amiga")
5066 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005067" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068 if a:islocal
5069 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5070 let dirname= substitute(dirname,'/$','','')
5071 else
5072 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5073 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005074" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005075
Bram Moolenaar8d043172014-01-23 14:24:41 +01005076 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
5077 " windows
5078 if a:islocal
5079 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5080 if dirname == ""
5081 let dirname= '/'
5082 endif
5083 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005084 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005085 endif
5086 if dirname =~ '^\a:$'
5087 let dirname= dirname.'/'
5088 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005089" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005090
Bram Moolenaar446cb832008-06-24 21:56:24 +00005091 else
5092 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005093" 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 +00005094 if a:islocal
5095 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5096 if dirname == ""
5097 let dirname= '/'
5098 endif
5099 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005100 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005101 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005102" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005104 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005105 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005106
5107 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005108 " --------------------------------------
5109 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5110 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005111" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5113" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005114 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005115 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5117 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005118 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005119 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005120" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005121 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005122 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005123" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005124
5125 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005126" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005127 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005128" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129 let haskey= 1
5130 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005131" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 endif
5133
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005134 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005135" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005136 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005137 if has_key(w:netrw_treedict,treedir."/")
5138 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005139" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005140 let haskey = 1
5141 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005142" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005143 endif
5144 endif
5145
5146 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005147" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 if !haskey && treedir =~ '/$'
5149 let treedir= substitute(treedir,'/$','','')
5150 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005151" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 let haskey = 1
5153 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005154" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155 endif
5156 endif
5157
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005158" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159 if haskey
5160 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005161" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005162 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5164" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005165 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005166 else
5167 " go down one directory
5168 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005169" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5170" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005172 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005173" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005174 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175
5176 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005177 " ----------------------------------------
5178 " NetrwBrowseChgDir: Go down one directory {{{3
5179 " ----------------------------------------
5180 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005181" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005182 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005183 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005184 endif
5185
Bram Moolenaar97d62492012-11-15 21:28:22 +01005186 " --------------------------------------
5187 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5188 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005189 if dorestore
5190 " dorestore is zero'd when a local file was hidden or bufhidden;
5191 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005193 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005194" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005195" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005196 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005197 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005198" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005199 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5201" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005202 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005203" 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 +02005204 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5206" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005207 setl ma ro 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 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005210 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005211 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005212 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005213
Bram Moolenaar446cb832008-06-24 21:56:24 +00005214" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5215 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005216endfun
5217
5218" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005219" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5220" for thin, long, and wide: cursor placed just after banner
5221" for tree, keeps cursor on current filename
5222fun! s:NetrwBrowseUpDir(islocal)
5223" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005224 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5225 " this test needed because occasionally this function seems to be incorrectly called
5226 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005227 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005228 " directories.
5229" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5230 return
5231 endif
5232
Bram Moolenaara6878372014-03-22 21:02:50 +01005233 norm! 0
5234 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005235" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005236 let curline= getline(".")
5237 let swwline= winline() - 1
5238 if exists("w:netrw_treetop")
5239 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005240 elseif exists("b:netrw_curdir")
5241 let w:netrw_treetop= b:netrw_curdir
5242 else
5243 let w:netrw_treetop= getcwd()
5244 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005245 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005246 let curfile = getline(".")
5247 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005248 if a:islocal
5249 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5250 else
5251 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5252 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005253" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5254" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5255 if w:netrw_treetop == '/'
5256 keepj call search('^\M'.curfile,"w")
5257 elseif curfile == '../'
5258 keepj call search('^\M'.curfile,"wb")
5259 else
5260" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5261 while 1
5262 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5263 let treepath= s:NetrwTreePath(w:netrw_treetop)
5264" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5265 if treepath == curpath
5266 break
5267 endif
5268 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005269 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005270
Bram Moolenaara6878372014-03-22 21:02:50 +01005271 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005272" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005273 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005274 if exists("b:netrw_curdir")
5275 let curdir= b:netrw_curdir
5276 else
5277 let curdir= expand(getcwd())
5278 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005279 if a:islocal
5280 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5281 else
5282 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5283 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005284 call s:RestorePosn(s:netrw_posn)
5285 let curdir= substitute(curdir,'^.*[\/]','','')
5286 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005287 endif
5288" call Dret("s:NetrwBrowseUpDir")
5289endfun
5290
5291" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005292" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005293" given filename; typically this means given their extension.
5294" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005295fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005296 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005297" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005298
Bram Moolenaar91359012019-11-30 17:57:03 +01005299 if a:remote == 0 && isdirectory(a:fname)
5300 " if its really just a local directory, then do a "gf" instead
5301" 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 +01005302" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5303 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005304" call Dret("netrw#BrowseX")
5305 return
5306 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5307 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5308" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5309" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5310" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5311" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5312 norm! gf
5313" call Dret("netrw#BrowseX")
5314 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005315 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005316" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005317
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005318 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5319 let remote = a:remote
5320 else
5321 let remote = 0
5322 endif
5323
Bram Moolenaar97d62492012-11-15 21:28:22 +01005324 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005325 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005326" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005327
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005328 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5329 let awkeep = &aw
5330 set noaw
5331
Bram Moolenaar5c736222010-01-06 20:54:52 +01005332 " special core dump handler
5333 if a:fname =~ '/core\(\.\d\+\)\=$'
5334 if exists("g:Netrw_corehandler")
5335 if type(g:Netrw_corehandler) == 2
5336 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005337" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005338 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005339 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005340 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005341" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005342 for Fncref in g:Netrw_corehandler
5343 if type(FncRef) == 2
5344 call FncRef(a:fname)
5345 endif
5346 endfor
5347 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005348" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005349 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005350 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005351 let &aw= awkeep
5352" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005353 return
5354 endif
5355 endif
5356
Bram Moolenaar446cb832008-06-24 21:56:24 +00005357 " set up the filename
5358 " (lower case the extension, make a local copy of a remote file)
5359 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5360 if has("win32") || has("win95") || has("win64") || has("win16")
5361 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005362 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005363 if exten =~ "[\\/]"
5364 let exten= ""
5365 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005366" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005367
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005368 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005369 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005370" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005371 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005372 call netrw#NetRead(3,a:fname)
5373 " attempt to rename tempfile
5374 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005375 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005376" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5377" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005378 if s:netrw_tmpfile != newname && newname != ""
5379 if rename(s:netrw_tmpfile,newname) == 0
5380 " renaming succeeded
5381" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5382 let fname= newname
5383 else
5384 " renaming failed
5385" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5386 let fname= s:netrw_tmpfile
5387 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005388 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005389 let fname= s:netrw_tmpfile
5390 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005391 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005392" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005393 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005394 " special ~ handler for local
5395 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005396" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5397 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005398 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005399 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005400" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5401" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005403 " set up redirection (avoids browser messages)
5404 " by default, g:netrw_suppress_gx_mesg is true
5405 if g:netrw_suppress_gx_mesg
5406 if &srr =~ "%s"
5407 if (has("win32") || has("win95") || has("win64") || has("win16"))
5408 let redir= substitute(&srr,"%s","nul","")
5409 else
5410 let redir= substitute(&srr,"%s","/dev/null","")
5411 endif
5412 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5413 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005414 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005415 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005418" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005420 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005421 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005422" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423 if g:netrw_browsex_viewer =~ '\s'
5424 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5425 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5426 let oviewer = ''
5427 let cnt = 1
5428 while !executable(viewer) && viewer != oviewer
5429 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5430 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5431 let cnt = cnt + 1
5432 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005433" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005434 endwhile
5435 else
5436 let viewer = g:netrw_browsex_viewer
5437 let viewopt = ""
5438 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005439" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005440 endif
5441
5442 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005443" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005444 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005445" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005446 let ret= netrwFileHandlers#Invoke(exten,fname)
5447
5448 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005449" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005450 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 let ret= v:shell_error
5452
5453 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005454" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005455 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005456 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005457 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005458 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005459 else
5460 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5461 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005462 let ret= v:shell_error
5463
Bram Moolenaar97d62492012-11-15 21:28:22 +01005464 elseif has("win32unix")
5465 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005466" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005467 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005468" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005469 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005470 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005471" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005472 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005473 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005474" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005475 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005476 else
5477 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5478 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005479 let ret= v:shell_error
5480
Bram Moolenaar85850f32019-07-19 22:05:51 +02005481 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005482" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5483 if a:fname =~ '^https\=://'
5484 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5485 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005486" call Decho("fname<".fname.">")
5487" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005488 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5489
5490 else
5491 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5492 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005493 let ret= v:shell_error
5494
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005495 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5496" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5497 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5498 let ret= v:shell_error
5499
5500 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5501" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5502 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5503 let ret= v:shell_error
5504
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005505 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005506" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005507 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005508 let ret= v:shell_error
5509
5510 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005511" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005512 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005513 let ret= v:shell_error
5514
5515 else
5516 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005517" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005518 let ret= netrwFileHandlers#Invoke(exten,fname)
5519 endif
5520
5521 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5522 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005523" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005524 let ret= netrwFileHandlers#Invoke(exten,fname)
5525 endif
5526
Bram Moolenaarc236c162008-07-13 17:41:49 +00005527 " restoring redraw! after external file handlers
5528 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005529
5530 " cleanup: remove temporary file,
5531 " delete current buffer if success with handler,
5532 " return to prior buffer (directory listing)
5533 " Feb 12, 2008: had to de-activiate removal of
5534 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005535" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005536"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005537" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005538" endif
5539
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005540 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005541 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005542 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005543 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005545 if use_ctrlo
5546 exe "sil! NetrwKeepj norm! \<c-o>"
5547 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005549" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005550 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005551 let @@ = ykeep
5552 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005554" call Dret("netrw#BrowseX")
5555endfun
5556
5557" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005558" netrw#GX: gets word under cursor for gx support {{{2
5559" See also: netrw#BrowseXVis
5560" netrw#BrowseX
5561fun! netrw#GX()
5562" call Dfunc("netrw#GX()")
5563 if &ft == "netrw"
5564 let fname= s:NetrwGetWord()
5565 else
5566 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5567 endif
5568" call Dret("netrw#GX <".fname.">")
5569 return fname
5570endfun
5571
5572" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005573" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5574fun! netrw#BrowseXVis()
5575" call Dfunc("netrw#BrowseXVis()")
Bram Moolenaar91359012019-11-30 17:57:03 +01005576 let akeep = @a
5577 norm! gv"ay
5578 let gxfile= @a
5579 let @a = akeep
5580 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005581" call Dret("netrw#BrowseXVis")
5582endfun
5583
5584" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005585" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5586" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5587" to become an unlisted buffer, so in that case don't bwipe it.
5588fun! s:NetrwBufRename(newname)
5589" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5590" call Dredir("ls!","s:NetrwBufRename (before rename)")
5591 let oldbufname= bufname(bufnr("%"))
5592" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5593
5594 if oldbufname != a:newname
5595" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5596 let b:junk= 1
5597" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5598 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005599" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005600 let oldbufnr= bufnr(oldbufname)
5601" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5602" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5603 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5604" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5605 exe "bwipe! ".oldbufnr
5606" else " Decho
5607" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005608" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5609" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5610" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005611 endif
5612" call Dredir("ls!","s:NetrwBufRename (after rename)")
5613" else " Decho
5614" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5615 endif
5616
5617" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5618endfun
5619
5620" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005621" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005622fun! netrw#CheckIfRemote(...)
5623" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5624 if a:0 > 0
5625 let curfile= a:1
5626 else
5627 let curfile= expand("%")
5628 endif
5629" call Decho("curfile<".curfile.">")
5630 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005631" call Dret("netrw#CheckIfRemote 1")
5632 return 1
5633 else
5634" call Dret("netrw#CheckIfRemote 0")
5635 return 0
5636 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005637endfun
5638
5639" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005640" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5641fun! s:NetrwChgPerm(islocal,curdir)
5642" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005643 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005644 call inputsave()
5645 let newperm= input("Enter new permission: ")
5646 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005647 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5648 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5649" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005650 call system(chgperm)
5651 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005652 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005653 endif
5654 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005655 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005656 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005657 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005658" call Dret("s:NetrwChgPerm")
5659endfun
5660
5661" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005662" s:CheckIfKde: checks if kdeinit is running {{{2
5663" Returns 0: kdeinit not running
5664" 1: kdeinit is running
5665fun! s:CheckIfKde()
5666" call Dfunc("s:CheckIfKde()")
5667 " seems kde systems often have gnome-open due to dependencies, even though
5668 " gnome-open's subsidiary display tools are largely absent. Kde systems
5669 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5670 if !exists("s:haskdeinit")
5671 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005672 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005673 if v:shell_error
5674 let s:haskdeinit = 0
5675 endif
5676 else
5677 let s:haskdeinit= 0
5678 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005679" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005680 endif
5681
5682" call Dret("s:CheckIfKde ".s:haskdeinit)
5683 return s:haskdeinit
5684endfun
5685
5686" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005687" s:NetrwClearExplore: clear explore variables (if any) {{{2
5688fun! s:NetrwClearExplore()
5689" call Dfunc("s:NetrwClearExplore()")
5690 2match none
5691 if exists("s:explore_match") |unlet s:explore_match |endif
5692 if exists("s:explore_indx") |unlet s:explore_indx |endif
5693 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5694 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5695 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5696 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5697 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5698 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5699 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5700" redraw!
5701 echo " "
5702 echo " "
5703" call Dret("s:NetrwClearExplore")
5704endfun
5705
5706" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005707" s:NetrwExploreListUniq: {{{2
5708fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005709" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005710
5711 " this assumes that the list is already sorted
5712 let newexplist= []
5713 for member in a:explist
5714 if !exists("uniqmember") || member != uniqmember
5715 let uniqmember = member
5716 let newexplist = newexplist + [ member ]
5717 endif
5718 endfor
5719
Bram Moolenaar15146672011-10-20 22:22:38 +02005720" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005721 return newexplist
5722endfun
5723
5724" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005725" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5726fun! s:NetrwForceChgDir(islocal,newdir)
5727" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005728 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005729 if a:newdir !~ '/$'
5730 " ok, looks like force is needed to get directory-style treatment
5731 if a:newdir =~ '@$'
5732 let newdir= substitute(a:newdir,'@$','/','')
5733 elseif a:newdir =~ '[*=|\\]$'
5734 let newdir= substitute(a:newdir,'.$','/','')
5735 else
5736 let newdir= a:newdir.'/'
5737 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005738" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005739 else
5740 " should already be getting treatment as a directory
5741 let newdir= a:newdir
5742 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005743 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005744 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005745 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005746" call Dret("s:NetrwForceChgDir")
5747endfun
5748
5749" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005750" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005751" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5752" expr : this is the expression to follow the directory. Will use s:ComposePath()
5753" pare =1: remove the current directory from the resulting glob() filelist
5754" =0: leave the current directory in the resulting glob() filelist
5755fun! s:NetrwGlob(direntry,expr,pare)
5756" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005757 if netrw#CheckIfRemote()
5758 keepalt 1sp
5759 keepalt enew
5760 let keep_liststyle = w:netrw_liststyle
5761 let w:netrw_liststyle = s:THINLIST
5762 if s:NetrwRemoteListing() == 0
5763 keepj keepalt %s@/@@
5764 let filelist= getline(1,$)
5765 q!
5766 else
5767 " remote listing error -- leave treedict unchanged
5768 let filelist= w:netrw_treedict[a:direntry]
5769 endif
5770 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005771 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5772 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5773 if a:pare
5774 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5775 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005776 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005777 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5778 if a:pare
5779 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5780 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005781 endif
5782" call Dret("s:NetrwGlob ".string(filelist))
5783 return filelist
5784endfun
5785
5786" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005787" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5788fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005789" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005790 if a:newfile =~ '[/@*=|\\]$'
5791 let newfile= substitute(a:newfile,'.$','','')
5792 else
5793 let newfile= a:newfile
5794 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005795 if a:islocal
5796 call s:NetrwBrowseChgDir(a:islocal,newfile)
5797 else
5798 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5799 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005800" call Dret("s:NetrwForceFile")
5801endfun
5802
5803" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005804" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5805" and switches the hiding mode. The actual hiding is done by
5806" s:NetrwListHide().
5807" g:netrw_hide= 0: show all
5808" 1: show not-hidden files
5809" 2: show hidden files only
5810fun! s:NetrwHide(islocal)
5811" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005812 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005813 let svpos= winsaveview()
5814" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005815
5816 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005817" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5818" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005819
5820 " hide the files in the markfile list
5821 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005822" 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 +00005823 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5824 " remove fname from hiding list
5825 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5826 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5827 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005828" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005829 else
5830 " append fname to hiding list
5831 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5832 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5833 else
5834 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005836" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005837 endif
5838 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005839 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005840 let g:netrw_hide= 1
5841
5842 else
5843
5844 " switch between show-all/show-not-hidden/show-hidden
5845 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005846 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005847 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005848 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005849 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005850" call Dret("NetrwHide")
5851 return
5852 endif
5853 endif
5854
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005855 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005856" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5857 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005858 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005859" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005860endfun
5861
5862" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005863" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5864fun! s:NetrwHideEdit(islocal)
5865" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5866
5867 let ykeep= @@
5868 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005869 let svpos= winsaveview()
5870" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005871
5872 " get new hiding list from user
5873 call inputsave()
5874 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5875 call inputrestore()
5876 let g:netrw_list_hide= newhide
5877" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5878
5879 " refresh the listing
5880 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5881
5882 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005883" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5884 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005885 let @@= ykeep
5886
5887" call Dret("NetrwHideEdit")
5888endfun
5889
5890" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005891" s:NetrwHidden: invoked by "gh" {{{2
5892fun! s:NetrwHidden(islocal)
5893" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005894 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005895 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005896 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005897" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898
5899 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005900 " remove .file pattern from hiding list
5901" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005902 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005903 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005904" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5906 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005907" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005908 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5909 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005910 if g:netrw_list_hide =~ '^,'
5911 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5912 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005913
5914 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005915 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005916" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5917 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005918 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005919" call Dret("s:NetrwHidden")
5920endfun
5921
5922" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005923" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5924fun! s:NetrwHome()
5925 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005926 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005927 else
5928 " go to vim plugin home
5929 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005930 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005931 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005932 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005933 let home= basehome."/.vim"
5934 break
5935 endif
5936 endfor
5937 if home == ""
5938 " just pick the first directory
5939 let home= substitute(&rtp,',.*$','','')
5940 endif
5941 if (has("win32") || has("win95") || has("win64") || has("win16"))
5942 let home= substitute(home,'/','\\','g')
5943 endif
5944 endif
5945 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005946 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005947" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005948 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005949" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005950 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005951 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005952" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005953 call mkdir(home)
5954 endif
5955 endif
5956 let g:netrw_home= home
5957 return home
5958endfun
5959
5960" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005961" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5962fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005963 if exists("s:netrwdrag")
5964 return
5965 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005966 if &ft != "netrw"
5967 return
5968 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005969" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005970
Bram Moolenaar97d62492012-11-15 21:28:22 +01005971 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005972 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005973 while getchar(0) != 0
5974 "clear the input stream
5975 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005976 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005977 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005978 let mouse_lnum = v:mouse_lnum
5979 let wlastline = line('w$')
5980 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005981" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5982" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005983 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5984 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005985 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005986" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5987 return
5988 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005989 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005990 " 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 +01005991 " without this test when its disabled.
5992 " 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 +01005993" 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 +01005994 if v:mouse_col > virtcol('.')
5995 let @@= ykeep
5996" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5997 return
5998 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005999
Bram Moolenaar446cb832008-06-24 21:56:24 +00006000 if a:islocal
6001 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006002 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006003 endif
6004 else
6005 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006006 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006007 endif
6008 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006009 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006010" call Dret("s:NetrwLeftmouse")
6011endfun
6012
6013" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006014" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6015fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006016 if &ft != "netrw"
6017 return
6018 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006019" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6020 call s:NetrwMarkFileTgt(a:islocal)
6021" call Dret("s:NetrwCLeftmouse")
6022endfun
6023
6024" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006025" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6026" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006027" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006028" a:islocal=2 : <c-r> used, remote
6029" a:islocal=3 : <c-r> used, local
6030fun! s:NetrwServerEdit(islocal,fname)
6031" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6032 let islocal = a:islocal%2 " =0: remote =1: local
6033 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006034" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006035
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006036 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006037 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006038 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006039" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006040 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006041 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006042 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6043 unlet s:netrw_browse_split_{winnr()}
6044 endif
6045 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6046" call Dret("s:NetrwServerEdit")
6047 return
6048 endif
6049
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006050" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006051 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006052" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006053
6054 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006055" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006056 let srvrname = g:netrw_browse_split[0]
6057 let tabnum = g:netrw_browse_split[1]
6058 let winnum = g:netrw_browse_split[2]
6059
6060 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006061" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006062
6063 if !ctrlr
6064 " user must have closed the server window and the user did not use <c-r>, but
6065 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006066" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006067 if exists("g:netrw_browse_split")
6068 unlet g:netrw_browse_split
6069 endif
6070 let g:netrw_browse_split= 0
6071 if exists("s:netrw_browse_split_".winnr())
6072 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6073 endif
6074 call s:NetrwBrowseChgDir(islocal,a:fname)
6075" call Dret("s:NetrwServerEdit")
6076 return
6077
6078 elseif has("win32") && executable("start")
6079 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006080" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006081 call system("start gvim --servername ".srvrname)
6082
6083 else
6084 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006086 call system("gvim --servername ".srvrname)
6087 endif
6088 endif
6089
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6092 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006093 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006094
6095 else
6096
6097 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6098
6099 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006100" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006101 if exists("g:netrw_browse_split")
6102 unlet g:netrw_browse_split
6103 endif
6104 let g:netrw_browse_split= 0
6105 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6106" call Dret("s:NetrwServerEdit")
6107 return
6108
6109 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006110" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006111 if has("win32") && executable("start")
6112 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006113" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006114 call system("start gvim --servername ".g:netrw_servername)
6115 else
6116 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006117" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006118 call system("gvim --servername ".g:netrw_servername)
6119 endif
6120 endif
6121 endif
6122
6123 while 1
6124 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006125" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6126 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006127 break
6128 catch /^Vim\%((\a\+)\)\=:E241/
6129 sleep 200m
6130 endtry
6131 endwhile
6132
6133 if exists("g:netrw_browse_split")
6134 if type(g:netrw_browse_split) != 3
6135 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6136 endif
6137 unlet g:netrw_browse_split
6138 endif
6139 let g:netrw_browse_split= [g:netrw_servername,1,1]
6140 endif
6141
6142 else
6143 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6144 endif
6145
6146" call Dret("s:NetrwServerEdit")
6147endfun
6148
6149" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006150" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6151fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006152 if &ft != "netrw"
6153 return
6154 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006155" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006156
Bram Moolenaar8d043172014-01-23 14:24:41 +01006157 let s:ngw= s:NetrwGetWord()
6158 call s:NetrwMarkFile(a:islocal,s:ngw)
6159
6160" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006161endfun
6162
6163" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006164" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6165" Used to mark multiple files.
6166fun! s:NetrwSLeftdrag(islocal)
6167" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6168 if !exists("s:netrwdrag")
6169 let s:netrwdrag = winnr()
6170 if a:islocal
6171 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006172 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006173 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006174 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006175 endif
6176 let ngw = s:NetrwGetWord()
6177 if !exists("s:ngw") || s:ngw != ngw
6178 call s:NetrwMarkFile(a:islocal,ngw)
6179 endif
6180 let s:ngw= ngw
6181" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6182endfun
6183
6184" ---------------------------------------------------------------------
6185" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6186fun! s:NetrwSLeftrelease(islocal)
6187" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6188 if exists("s:netrwdrag")
6189 nunmap <s-leftrelease>
6190 let ngw = s:NetrwGetWord()
6191 if !exists("s:ngw") || s:ngw != ngw
6192 call s:NetrwMarkFile(a:islocal,ngw)
6193 endif
6194 if exists("s:ngw")
6195 unlet s:ngw
6196 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006197 unlet s:netrwdrag
6198 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006199" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006200endfun
6201
6202" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006203" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6204" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006205fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006206" 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 +02006207" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006208 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006209
6210 " 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 +02006211 " How-it-works: take the hiding command, convert it into a range.
6212 " Duplicate characters don't matter.
6213 " Remove all such characters from the '/~@#...890' string.
6214 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006215" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006216 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006217 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006218" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006219
6220 while listhide != ""
6221 if listhide =~ ','
6222 let hide = substitute(listhide,',.*$','','e')
6223 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6224 else
6225 let hide = listhide
6226 let listhide = ""
6227 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006228" 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 +01006229 if g:netrw_sort_by =~ '^[ts]'
6230 if hide =~ '^\^'
6231" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6232 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6233 elseif hide =~ '^\\(\^'
6234 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6235 endif
6236" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6237 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006238
6239 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006240" 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 +00006241 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006242" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006243 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006244 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006245" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006246 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006248" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006249 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006250
Bram Moolenaar446cb832008-06-24 21:56:24 +00006251 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006252 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006253" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006254 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006255" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006256 endif
6257
Bram Moolenaaradc21822011-04-01 18:03:16 +02006258 " remove any blank lines that have somehow remained.
6259 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006260 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006261
Bram Moolenaar97d62492012-11-15 21:28:22 +01006262 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006263" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006264endfun
6265
6266" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006268" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006269fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006270" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006271
Bram Moolenaar97d62492012-11-15 21:28:22 +01006272 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006273 " get name of new directory from user. A bare <CR> will skip.
6274 " if its currently a directory, also request will be skipped, but with
6275 " a message.
6276 call inputsave()
6277 let newdirname= input("Please give directory name: ")
6278 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006279" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006280
6281 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006282 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006283" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006284 return
6285 endif
6286
6287 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006288" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289
6290 " Local mkdir:
6291 " sanity checks
6292 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006293" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6294 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006295 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006296 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006297 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006298 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006299" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006300 return
6301 endif
6302 if s:FileReadable(fullnewdir)
6303 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006304 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006306 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006307" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006308 return
6309 endif
6310
6311 " requested new local directory is neither a pre-existing file or
6312 " directory, so make it!
6313 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006314 if has("unix")
6315 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6316 else
6317 call mkdir(fullnewdir,"p")
6318 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319 else
6320 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006321 if s:NetrwLcd(b:netrw_curdir)
6322" call Dret("s:NetrwMakeDir : lcd failure")
6323 return
6324 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006325" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006326 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006327 if v:shell_error != 0
6328 let @@= ykeep
6329 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 +01006330" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006331 return
6332 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006333 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006334" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006335 if s:NetrwLcd(netrw_origdir)
6336" call Dret("s:NetrwBrowse : lcd failure")
6337 return
6338 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006339 endif
6340 endif
6341
6342 if v:shell_error == 0
6343 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006344" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006345 let svpos= winsaveview()
6346" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006347 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006348" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6349 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006350 elseif !exists("g:netrw_quiet")
6351 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6352 endif
6353" redraw!
6354
6355 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006356 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006357" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006358 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6359 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006361 if v:shell_error == 0
6362 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006363 let svpos= winsaveview()
6364" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006365 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006366" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6367 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006368 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006369 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370 endif
6371" redraw!
6372
6373 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006374 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006375 let svpos= winsaveview()
6376" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006377" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006378 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006379" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006380 let remotepath= b:netrw_fname
6381 else
6382 let remotepath= ""
6383 endif
6384 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006385 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006386" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6387 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006388
Bram Moolenaar446cb832008-06-24 21:56:24 +00006389 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006390 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006391 let svpos= winsaveview()
6392" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006393" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006394 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006395" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006396 let remotepath= b:netrw_fname
6397 else
6398 let remotepath= ""
6399 endif
6400 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006401 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006402" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6403 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006404 endif
6405
Bram Moolenaar97d62492012-11-15 21:28:22 +01006406 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006407" call Dret("s:NetrwMakeDir")
6408endfun
6409
6410" ---------------------------------------------------------------------
6411" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6412fun! s:TreeSqueezeDir(islocal)
6413" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6414 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6415 " its a tree-listing style
6416 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006417 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006418 let depth = strchars(substitute(curdepth,' ','','g'))
6419 let srch = -1
6420" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6421" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006422" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006423" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6424 if depth >= 2
6425 NetrwKeepj norm! 0
6426 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6427 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6428" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6429" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6430 elseif depth == 1
6431 NetrwKeepj norm! 0
6432 let treedepthchr= substitute(s:treedepthstring,' ','','')
6433 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6434" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6435 endif
6436 if srch > 0
6437" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6438 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6439 exe srch
6440 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006441 endif
6442" call Dret("s:TreeSqueezeDir")
6443endfun
6444
6445" ---------------------------------------------------------------------
6446" s:NetrwMaps: {{{2
6447fun! s:NetrwMaps(islocal)
6448" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6449
Bram Moolenaar85850f32019-07-19 22:05:51 +02006450 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006451 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006452" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006453 if !hasmapto("<Plug>NetrwReturn")
6454 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006455" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006456 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6457 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006458" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006459 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6460 endif
6461 endif
6462 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006463" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006464 endif
6465
Bram Moolenaar85850f32019-07-19 22:05:51 +02006466 " generate default <Plug> maps {{{3
6467 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006468 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006469 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6470 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6471 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6472 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6473 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6474 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6475 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6476 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6477 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6478 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6479" ---------------------------------------------------------------------
6480" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6481" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6482" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6483" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6484" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6485" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6486" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6487" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6488" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6489" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6490" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6491" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6492" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6493" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6494" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6495" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6496" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6497" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6498" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6499" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6500" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6501" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6502" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6503" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6504" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6505" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6506" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6507" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6508" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6509" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6510" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6511" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6512" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6513" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6514" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6515" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6516" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6517" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6518" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6519" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6520" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6521" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6522" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6523" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6524" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6525" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6526" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6527
Bram Moolenaara6878372014-03-22 21:02:50 +01006528 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006529" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006530 " local normal-mode maps {{{3
6531 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6532 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6533 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6534 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6535 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6536 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6537 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6538 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6539 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6540 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6541 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6542" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006543 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6544 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6545 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006546 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006547 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006548 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6549 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6550 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6551 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006552 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6553 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6554 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6555 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6556 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6557 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6558 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6559 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6560 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6561 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6562 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6563 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6564 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006565 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006566 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006567 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6568 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6569 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6570 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6571 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006572 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006573 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006574 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6575 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006576 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6577 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6578 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006579 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006580 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006581 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6582 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006583 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006584 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006585 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6586 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6587 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006588 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6589 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006590
6591 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 +01006592 if !hasmapto('<Plug>NetrwHideEdit')
6593 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006594 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006595 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006596 if !hasmapto('<Plug>NetrwRefresh')
6597 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006598 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006599 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 +01006600 if s:didstarstar || !mapcheck("<s-down>","n")
6601 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006602 endif
6603 if s:didstarstar || !mapcheck("<s-up>","n")
6604 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006605 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006606 if !hasmapto('<Plug>NetrwTreeSqueeze')
6607 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006608 endif
6609 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006610 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6611 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006612 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6613 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6614 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6615 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6616 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6617 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6618 imap <buffer> <leftmouse> <Plug>ILeftmouse
6619 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006620 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006621 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006622 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006623 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006624 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006625 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006626 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6627 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006628 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6630 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6631 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6632 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6633 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6634 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6635 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006636 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6637
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006638 " support user-specified maps
6639 call netrw#UserMaps(1)
6640
Bram Moolenaar85850f32019-07-19 22:05:51 +02006641 else
6642 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006643" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006644 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006645 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6646 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6647 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6648 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6649 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6650 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6651 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6652 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6653 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6654 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6655 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6656" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006657 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6658 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6659 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6660 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6661 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6662 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6663 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6664 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006665 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006666 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006667 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6668 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6669 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6670 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6671 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6672 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6673 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6674 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6675 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6676 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6677 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006678 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006679 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006680 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6681 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6682 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6683 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6684 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006685 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6686 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6687 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6688 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006690 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6691 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006692 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006693 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 +01006694 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6695 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6696 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6697 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6698 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6699 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6700 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6701 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6702 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006703 if !hasmapto('<Plug>NetrwHideEdit')
6704 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006705 endif
6706 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6707 if !hasmapto('<Plug>NetrwRefresh')
6708 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006709 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006710 if !hasmapto('<Plug>NetrwTreeSqueeze')
6711 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006712 endif
6713 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006714
6715 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006716 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006717
6718 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6719 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006720 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6721 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6722 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6723 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6724 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6725 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6726 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6727 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6728 nmap <middlemouse> <Plug>NetrwMiddlemouse
6729 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6730 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6731 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6732 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006733 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006734 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006735 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6736 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006737 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006738 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6739 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6740 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6741 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6742 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6743 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6744 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006745 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006746
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006747 " support user-specified maps
6748 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006749 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006750
6751" call Dret("s:NetrwMaps")
6752endfun
6753
6754" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006755" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006756" If -buffer, the command is only available from within netrw buffers
6757" Otherwise, the command is available from any window, so long as netrw
6758" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006759fun! s:NetrwCommands(islocal)
6760" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6761
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006762 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6763 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006764 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 +01006765 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006766 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006767 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006768 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006769 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006770 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006771
6772" call Dret("s:NetrwCommands")
6773endfun
6774
6775" ---------------------------------------------------------------------
6776" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6777" glob()ing only works with local files
6778fun! s:NetrwMarkFiles(islocal,...)
6779" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006780 let curdir = s:NetrwGetCurdir(a:islocal)
6781 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006782 while i <= a:0
6783 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006784 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006785 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006786 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006787 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006788 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006789 else
6790 let mffiles= [a:{i}]
6791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006792" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006793 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006794" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006795 call s:NetrwMarkFile(a:islocal,mffile)
6796 endfor
6797 let i= i + 1
6798 endwhile
6799" call Dret("s:NetrwMarkFiles")
6800endfun
6801
6802" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006803" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006804fun! s:NetrwMarkTarget(...)
6805" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6806 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006807 let curdir = s:NetrwGetCurdir(1)
6808 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006809 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006810 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6811 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006813" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006814 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006815 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6816 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006817 let svpos = winsaveview()
6818" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006819 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006820" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6821 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006822" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006823endfun
6824
6825" ---------------------------------------------------------------------
6826" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6827" mark and unmark files. If a markfile list exists,
6828" then the rename and delete functions will use it instead
6829" of whatever may happen to be under the cursor at that
6830" moment. When the mouse and gui are available,
6831" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006832"
6833" Creates two lists
6834" s:netrwmarkfilelist -- holds complete paths to all marked files
6835" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6836"
6837" Creates a marked file match string
6838" s:netrwmarfilemtch_# -- used with 2match to display marked files
6839"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006840" Creates a buffer version of islocal
6841" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006842fun! s:NetrwMarkFile(islocal,fname)
6843" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006844" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006845
6846 " sanity check
6847 if empty(a:fname)
6848" call Dret("s:NetrwMarkFile : emtpy fname")
6849 return
6850 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006851 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006852
Bram Moolenaar97d62492012-11-15 21:28:22 +01006853 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006854 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006855 if a:fname =~ '^\a'
6856 let leader= '\<'
6857 else
6858 let leader= ''
6859 endif
6860 if a:fname =~ '\a$'
6861 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6862 else
6863 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6864 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006865
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006866 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006867 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006868" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6869" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6870" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006871 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006872
6873 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006874 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006875" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006876 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006877 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006878
6879 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006880 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006881" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006882 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6883 if s:netrwmarkfilelist_{curbufnr} == []
6884 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006885" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006886 call s:NetrwUnmarkList(curbufnr,curdir)
6887 else
6888 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006889" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006890 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006891 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006892 for fname in s:netrwmarkfilelist_{curbufnr}
6893 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006894 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006895 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006896 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006897 endif
6898 let first= 0
6899 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006900" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006901 endif
6902 endif
6903
6904 else
6905 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006906" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006907
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006908" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006909 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6911" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912
6913 " build initial markfile matching pattern
6914 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006915 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006917 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006919" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006920 endif
6921
6922 " handle global markfilelist
6923 if exists("s:netrwmarkfilelist")
6924 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6925 if index(s:netrwmarkfilelist,dname) == -1
6926 " append new filename to global markfilelist
6927 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006928" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006929 else
6930 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006931" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6932" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006933 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006934" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006935 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006936" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006937 unlet s:netrwmarkfilelist
6938 endif
6939 endif
6940 else
6941 " initialize new global-directory markfilelist
6942 let s:netrwmarkfilelist= []
6943 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006944" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006945 endif
6946
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006947 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006948 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6949 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6950" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6951 if exists("g:did_drchip_netrwlist_syntax")
6952 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6953 endif
6954 else
6955" " call Decho("2match none",'~'.expand("<slnum>"))
6956 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006957 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006958 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006959 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006960" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6961" 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 +00006962endfun
6963
6964" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006965" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6966" mA: move the argument list to marked file list (tomflist=1)
6967" Uses the global marked file list
6968fun! s:NetrwMarkFileArgList(islocal,tomflist)
6969" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6970
6971 let svpos = winsaveview()
6972" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6973 let curdir = s:NetrwGetCurdir(a:islocal)
6974 let curbufnr = bufnr("%")
6975
6976 if a:tomflist
6977 " mA: move argument list to marked file list
6978 while argc()
6979 let fname= argv(0)
6980" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6981 exe "argdel ".fnameescape(fname)
6982 call s:NetrwMarkFile(a:islocal,fname)
6983 endwhile
6984
6985 else
6986 " ma: move marked file list to argument list
6987 if exists("s:netrwmarkfilelist")
6988
6989 " for every filename in the marked list
6990 for fname in s:netrwmarkfilelist
6991" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6992 exe "argadd ".fnameescape(fname)
6993 endfor " for every file in the marked list
6994
6995 " unmark list and refresh
6996 call s:NetrwUnmarkList(curbufnr,curdir)
6997 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6998" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6999 NetrwKeepj call winrestview(svpos)
7000 endif
7001 endif
7002
7003" call Dret("s:NetrwMarkFileArgList")
7004endfun
7005
7006" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007007" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7008" compress/decompress files using the programs
7009" in g:netrw_compress and g:netrw_uncompress,
7010" using g:netrw_compress_suffix to know which to
7011" do. By default:
7012" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007013" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007014fun! s:NetrwMarkFileCompress(islocal)
7015" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007016 let svpos = winsaveview()
7017" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007018 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007019 let curbufnr = bufnr("%")
7020
Bram Moolenaarff034192013-04-24 18:51:19 +02007021 " sanity check
7022 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007023 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007024" call Dret("s:NetrwMarkFileCompress")
7025 return
7026 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007027" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007028
Bram Moolenaar446cb832008-06-24 21:56:24 +00007029 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007030
7031 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007032 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007033 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007034" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007035 if exists("g:netrw_decompress['".sfx."']")
7036 " fname has a suffix indicating that its compressed; apply associated decompression routine
7037 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007038" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007039 let exe= netrw#WinPath(exe)
7040 if a:islocal
7041 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007042 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007043 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007044 call system(exe." ".fname)
7045 if v:shell_error
7046 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007047 endif
7048 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007049 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7050 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007051 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007052
Bram Moolenaarff034192013-04-24 18:51:19 +02007053 endif
7054 unlet sfx
7055
Bram Moolenaar446cb832008-06-24 21:56:24 +00007056 if exists("exe")
7057 unlet exe
7058 elseif a:islocal
7059 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007060 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007061 if v:shell_error
7062 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7063 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007064 else
7065 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007066 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007068 endfor " for every file in the marked list
7069
Bram Moolenaar446cb832008-06-24 21:56:24 +00007070 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007071 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007072" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7073 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007074 endif
7075" call Dret("s:NetrwMarkFileCompress")
7076endfun
7077
7078" ---------------------------------------------------------------------
7079" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7080" If no marked files, then set up directory as the
7081" target. Currently does not support copying entire
7082" directories. Uses the local-buffer marked file list.
7083" Returns 1=success (used by NetrwMarkFileMove())
7084" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007085fun! s:NetrwMarkFileCopy(islocal,...)
7086" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7087
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007088 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007089 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007090 if b:netrw_curdir !~ '/$'
7091 if !exists("b:netrw_curdir")
7092 let b:netrw_curdir= curdir
7093 endif
7094 let b:netrw_curdir= b:netrw_curdir."/"
7095 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007096
Bram Moolenaarff034192013-04-24 18:51:19 +02007097 " sanity check
7098 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007099 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007100" call Dret("s:NetrwMarkFileCopy")
7101 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007102 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007103" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007104
Bram Moolenaar446cb832008-06-24 21:56:24 +00007105 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007106 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007107" call Dret("s:NetrwMarkFileCopy 0")
7108 return 0
7109 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007110" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007111
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007112 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007113 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007114" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007115 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007116 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7117" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7118 return
7119 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007120
7121 " copy marked files while within the same directory (ie. allow renaming)
7122 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7123 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7124 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007125" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007126 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007127 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7128 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007129" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007130 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007131 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007132 let oldname = a:1
7133 else
7134 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007135" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007136 let s:recursive= 1
7137 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7138 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7139 if ret == 0
7140 break
7141 endif
7142 endfor
7143 unlet s:recursive
7144 call s:NetrwUnmarkList(curbufnr,curdir)
7145" call Dret("s:NetrwMarkFileCopy ".ret)
7146 return ret
7147 endif
7148
7149 call inputsave()
7150 let newname= input("Copy ".oldname." to : ",oldname,"file")
7151 call inputrestore()
7152 if newname == ""
7153" call Dret("s:NetrwMarkFileCopy 0")
7154 return 0
7155 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007156 let args= s:ShellEscape(oldname)
7157 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007158 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007159 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7160 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007161 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007162 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7163 let args= substitute(args,'/','\\','g')
7164 let tgt = substitute(tgt, '/','\\','g')
7165 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007166 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7167 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7168 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7169 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7170" call Decho("args <".args.">",'~'.expand("<slnum>"))
7171" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007172 if isdirectory(s:NetrwFile(args))
7173" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007174 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007175" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007176 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7177 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7178 " contents to a target. One must append the source directory name to the target to get xcopy to
7179 " do the right thing.
7180 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007181" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007182 endif
7183 else
7184 let copycmd= g:netrw_localcopycmd
7185 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007186 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007187 let copycmd = substitute(copycmd,'\s.*$','','')
7188 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007189 let copycmd = netrw#WinPath(copycmd).copycmdargs
7190 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007191 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007192 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007193" call Decho("args <".args.">",'~'.expand("<slnum>"))
7194" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7195" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7196" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007197 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007198 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007199 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007200 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 +01007201 else
7202 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7203 endif
7204" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007205 return 0
7206 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007207
7208 elseif a:islocal && !s:netrwmftgt_islocal
7209 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007210" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007211 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007212
7213 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007214 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007215" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007216 NetrwKeepj call netrw#Obtain(a:islocal,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 remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007220" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007221 let curdir = getcwd()
7222 let tmpdir = s:GetTempfile("")
7223 if tmpdir !~ '/'
7224 let tmpdir= curdir."/".tmpdir
7225 endif
7226 if exists("*mkdir")
7227 call mkdir(tmpdir)
7228 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007229 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007230 if v:shell_error != 0
7231 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 +01007232" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007233 return
7234 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007235 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007236 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007237 if s:NetrwLcd(tmpdir)
7238" call Dret("s:NetrwMarkFileCopy : lcd failure")
7239 return
7240 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007241 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007242 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007243 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007244 if getcwd() == tmpdir
7245 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007246 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007248 if s:NetrwLcd(curdir)
7249" call Dret("s:NetrwMarkFileCopy : lcd failure")
7250 return
7251 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007252 if delete(tmpdir,"d")
7253 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007254 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007255 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007256 if s:NetrwLcd(curdir)
7257" call Dret("s:NetrwMarkFileCopy : lcd failure")
7258 return
7259 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007260 endif
7261 endif
7262 endif
7263
7264 " -------
7265 " cleanup
7266 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007267" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007268 " remove markings from local buffer
7269 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007270" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7271" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7272" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7273" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7274" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7275" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7276 if exists("s:recursive")
7277" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7278 else
7279" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007280 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007281 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007282 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007283 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007284 else
7285 " refresh local and targets for fast browsing
7286 if !exists("s:recursive")
7287 " remove markings from local buffer
7288" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7289 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7290 endif
7291
7292 " refresh buffers
7293 if s:netrwmftgt_islocal
7294" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7295 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7296 endif
7297 if a:islocal && s:netrwmftgt != curdir
7298" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7299 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7300 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007301 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007302
Bram Moolenaar446cb832008-06-24 21:56:24 +00007303" call Dret("s:NetrwMarkFileCopy 1")
7304 return 1
7305endfun
7306
7307" ---------------------------------------------------------------------
7308" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7309" invoke vim's diff mode on the marked files.
7310" Either two or three files can be so handled.
7311" Uses the global marked file list.
7312fun! s:NetrwMarkFileDiff(islocal)
7313" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7314 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007315
Bram Moolenaarff034192013-04-24 18:51:19 +02007316 " sanity check
7317 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007318 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007319" call Dret("s:NetrwMarkFileDiff")
7320 return
7321 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007322 let curdir= s:NetrwGetCurdir(a:islocal)
7323" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007324
Bram Moolenaara6878372014-03-22 21:02:50 +01007325 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007326 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007327 for fname in s:netrwmarkfilelist
7328 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007329 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007330" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007331 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007332 diffthis
7333 elseif cnt == 2 || cnt == 3
7334 vsplit
7335 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007336" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007337 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338 diffthis
7339 else
7340 break
7341 endif
7342 endfor
7343 call s:NetrwUnmarkList(curbufnr,curdir)
7344 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007345
Bram Moolenaar446cb832008-06-24 21:56:24 +00007346" call Dret("s:NetrwMarkFileDiff")
7347endfun
7348
7349" ---------------------------------------------------------------------
7350" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7351" Uses global markfilelist
7352fun! s:NetrwMarkFileEdit(islocal)
7353" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7354
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007355 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007356 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007357
7358 " sanity check
7359 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007360 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007361" call Dret("s:NetrwMarkFileEdit")
7362 return
7363 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007365
Bram Moolenaar446cb832008-06-24 21:56:24 +00007366 if exists("s:netrwmarkfilelist_{curbufnr}")
7367 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007368 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007369 " unmark markedfile list
7370" call s:NetrwUnmarkList(curbufnr,curdir)
7371 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007372" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007373 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007374 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007375 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007376
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377" call Dret("s:NetrwMarkFileEdit")
7378endfun
7379
7380" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007381" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007382fun! s:NetrwMarkFileQFEL(islocal,qfel)
7383" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7384 call s:NetrwUnmarkAll()
7385 let curbufnr= bufnr("%")
7386
7387 if !empty(a:qfel)
7388 for entry in a:qfel
7389 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007390" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007391 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007392" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007393 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7394 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7395 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7396 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007397" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007398 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7399 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007400" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007401 endif
7402 endfor
7403 echo "(use me to edit marked files)"
7404 else
7405 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7406 endif
7407
7408" call Dret("s:NetrwMarkFileQFEL")
7409endfun
7410
7411" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007412" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7413" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7414" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7415fun! s:NetrwMarkFileExe(islocal,enbloc)
7416" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007417 let svpos = winsaveview()
7418" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007419 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007420 let curbufnr = bufnr("%")
7421
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007422 if a:enbloc == 0
7423 " individually apply command to files, one at a time
7424 " sanity check
7425 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7426 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7427" call Dret("s:NetrwMarkFileExe")
7428 return
7429 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007430" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007431
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007432 if exists("s:netrwmarkfilelist_{curbufnr}")
7433 " get the command
7434 call inputsave()
7435 let cmd= input("Enter command: ","","file")
7436 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007437" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007438 if cmd == ""
7439" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7440 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007441 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007442
7443 " apply command to marked files, individually. Substitute: filename -> %
7444 " If no %, then append a space and the filename to the command
7445 for fname in s:netrwmarkfilelist_{curbufnr}
7446 if a:islocal
7447 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007448 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007449 endif
7450 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007451 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007452 endif
7453 if cmd =~ '%'
7454 let xcmd= substitute(cmd,'%',fname,'g')
7455 else
7456 let xcmd= cmd.' '.fname
7457 endif
7458 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007459" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007460 let ret= system(xcmd)
7461 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007462" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463 let ret= s:RemoteSystem(xcmd)
7464 endif
7465 if v:shell_error < 0
7466 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7467 break
7468 else
7469 echo ret
7470 endif
7471 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007472
7473 " unmark marked file list
7474 call s:NetrwUnmarkList(curbufnr,curdir)
7475
7476 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007477 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007478" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7479 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007480 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007481 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007482 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483
7484 else " apply command to global list of files, en bloc
7485
7486 call inputsave()
7487 let cmd= input("Enter command: ","","file")
7488 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007489" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007490 if cmd == ""
7491" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7492 return
7493 endif
7494 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007495 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007496 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007497 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007498 endif
7499 if a:islocal
7500 call system(cmd)
7501 if v:shell_error < 0
7502 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7503 endif
7504 else
7505 let ret= s:RemoteSystem(cmd)
7506 endif
7507 call s:NetrwUnmarkAll()
7508
7509 " refresh the listing
7510 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007511" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7512 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007513
7514 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007515
Bram Moolenaar446cb832008-06-24 21:56:24 +00007516" call Dret("s:NetrwMarkFileExe")
7517endfun
7518
7519" ---------------------------------------------------------------------
7520" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7521" as the marked file(s) (toggles suffix presence)
7522" Uses the local marked file list.
7523fun! s:NetrwMarkHideSfx(islocal)
7524" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007525 let svpos = winsaveview()
7526" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007527 let curbufnr = bufnr("%")
7528
7529 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7530 if exists("s:netrwmarkfilelist_{curbufnr}")
7531
7532 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007533" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007534 " construct suffix pattern
7535 if fname =~ '\.'
7536 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7537 else
7538 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7539 endif
7540 " determine if its in the hiding list or not
7541 let inhidelist= 0
7542 if g:netrw_list_hide != ""
7543 let itemnum = 0
7544 let hidelist= split(g:netrw_list_hide,',')
7545 for hidepat in hidelist
7546 if sfxpat == hidepat
7547 let inhidelist= 1
7548 break
7549 endif
7550 let itemnum= itemnum + 1
7551 endfor
7552 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007553" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007554 if inhidelist
7555 " remove sfxpat from list
7556 call remove(hidelist,itemnum)
7557 let g:netrw_list_hide= join(hidelist,",")
7558 elseif g:netrw_list_hide != ""
7559 " append sfxpat to non-empty list
7560 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7561 else
7562 " set hiding list to sfxpat
7563 let g:netrw_list_hide= sfxpat
7564 endif
7565 endfor
7566
7567 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007568 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007569" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7570 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007571 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007572 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007573 endif
7574
7575" call Dret("s:NetrwMarkHideSfx")
7576endfun
7577
7578" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007579" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007580" Uses the local marked-file list.
7581fun! s:NetrwMarkFileVimCmd(islocal)
7582" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007583 let svpos = winsaveview()
7584" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007585 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007586 let curbufnr = bufnr("%")
7587
Bram Moolenaarff034192013-04-24 18:51:19 +02007588 " sanity check
7589 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007590 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007591" call Dret("s:NetrwMarkFileVimCmd")
7592 return
7593 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007594" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007595
Bram Moolenaar15146672011-10-20 22:22:38 +02007596 if exists("s:netrwmarkfilelist_{curbufnr}")
7597 " get the command
7598 call inputsave()
7599 let cmd= input("Enter vim command: ","","file")
7600 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007601" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007602 if cmd == ""
7603" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7604 return
7605 endif
7606
7607 " apply command to marked files. Substitute: filename -> %
7608 " If no %, then append a space and the filename to the command
7609 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007610" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007611 if a:islocal
7612 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007614" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007615 exe cmd
7616 exe "sil! keepalt wq!"
7617 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007618" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007619 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007620 endif
7621 endfor
7622
7623 " unmark marked file list
7624 call s:NetrwUnmarkList(curbufnr,curdir)
7625
7626 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007627 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007628" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7629 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007630 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007631 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007633
Bram Moolenaar15146672011-10-20 22:22:38 +02007634" call Dret("s:NetrwMarkFileVimCmd")
7635endfun
7636
7637" ---------------------------------------------------------------------
7638" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7639" as the marked file(s) (toggles suffix presence)
7640" Uses the local marked file list.
7641fun! s:NetrwMarkHideSfx(islocal)
7642" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007643 let svpos = winsaveview()
7644" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007645 let curbufnr = bufnr("%")
7646
7647 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7648 if exists("s:netrwmarkfilelist_{curbufnr}")
7649
7650 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007651" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007652 " construct suffix pattern
7653 if fname =~ '\.'
7654 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7655 else
7656 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7657 endif
7658 " determine if its in the hiding list or not
7659 let inhidelist= 0
7660 if g:netrw_list_hide != ""
7661 let itemnum = 0
7662 let hidelist= split(g:netrw_list_hide,',')
7663 for hidepat in hidelist
7664 if sfxpat == hidepat
7665 let inhidelist= 1
7666 break
7667 endif
7668 let itemnum= itemnum + 1
7669 endfor
7670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007671" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007672 if inhidelist
7673 " remove sfxpat from list
7674 call remove(hidelist,itemnum)
7675 let g:netrw_list_hide= join(hidelist,",")
7676 elseif g:netrw_list_hide != ""
7677 " append sfxpat to non-empty list
7678 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7679 else
7680 " set hiding list to sfxpat
7681 let g:netrw_list_hide= sfxpat
7682 endif
7683 endfor
7684
7685 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007686 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007687" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7688 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007689 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007690 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007691 endif
7692
7693" call Dret("s:NetrwMarkHideSfx")
7694endfun
7695
7696" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007697" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7698" Uses the global markfilelist
7699fun! s:NetrwMarkFileGrep(islocal)
7700" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007701 let svpos = winsaveview()
7702" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007703 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007704 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007705
7706 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007707" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007708 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007709" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007710 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007711 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007712" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007713 let netrwmarkfilelist= "*"
7714 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007715
Bram Moolenaarff034192013-04-24 18:51:19 +02007716 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007717" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007718 call inputsave()
7719 let pat= input("Enter pattern: ","")
7720 call inputrestore()
7721 let patbang = ""
7722 if pat =~ '^!'
7723 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007724 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007725 endif
7726 if pat =~ '^\i'
7727 let pat = escape(pat,'/')
7728 let pat = '/'.pat.'/'
7729 else
7730 let nonisi = pat[0]
7731 endif
7732
7733 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007734" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007735 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007736 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007737 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007738 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007739" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7740 return
7741 endtry
7742 echo "(use :cn, :cp to navigate, :Rex to return)"
7743
7744 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007745" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7746 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007747
7748 if exists("nonisi")
7749 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007750" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007751 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007752 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007753 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007754 endif
7755
7756" call Dret("s:NetrwMarkFileGrep")
7757endfun
7758
7759" ---------------------------------------------------------------------
7760" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7761" uses the global marked file list
7762" s:netrwmfloc= 0: target directory is remote
7763" = 1: target directory is local
7764fun! s:NetrwMarkFileMove(islocal)
7765" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007766 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007767 let curbufnr = bufnr("%")
7768
7769 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007770 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007771 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007772" call Dret("s:NetrwMarkFileMove")
7773 return
7774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007775" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007776
Bram Moolenaar446cb832008-06-24 21:56:24 +00007777 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007778 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007779" call Dret("s:NetrwMarkFileCopy 0")
7780 return 0
7781 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007782" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007783
7784 if a:islocal && s:netrwmftgt_islocal
7785 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007786" call Decho("move from local to local",'~'.expand("<slnum>"))
7787" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007788 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007789 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7790" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7791 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007792 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007793 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007794" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007795 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007796 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007797" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007798 if g:netrw_localmovecmd =~ '\s'
7799 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7800 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7801 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007802" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007803 else
7804 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007805" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007806 endif
7807 else
7808 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007810 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007811 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007812 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7813 let fname= substitute(fname,'/','\\','g')
7814 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007815" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007816 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007817 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007818 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007819 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 +01007820 else
7821 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7822 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007823 break
7824 endif
7825 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826
7827 elseif a:islocal && !s:netrwmftgt_islocal
7828 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007829" call Decho("move from local to remote",'~'.expand("<slnum>"))
7830" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007832 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007834 for fname in mflist
7835 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7836 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7837 endfor
7838 unlet mflist
7839
7840 elseif !a:islocal && s:netrwmftgt_islocal
7841 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007842" call Decho("move from remote to local",'~'.expand("<slnum>"))
7843" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007844 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007845 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007846" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007847 for fname in mflist
7848 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7849 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7850 endfor
7851 unlet mflist
7852
7853 elseif !a:islocal && !s:netrwmftgt_islocal
7854 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007855" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7856" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007857 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007858 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007859" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007860 for fname in mflist
7861 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7862 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7863 endfor
7864 unlet mflist
7865 endif
7866
7867 " -------
7868 " cleanup
7869 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007870" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007871
7872 " remove markings from local buffer
7873 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7874
7875 " refresh buffers
7876 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007877" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007878 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007879 endif
7880 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007881" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007882 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007883 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007884 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007885" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007886 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007887 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007888
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889" call Dret("s:NetrwMarkFileMove")
7890endfun
7891
7892" ---------------------------------------------------------------------
7893" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7894" using the hardcopy command. Local marked-file list only.
7895fun! s:NetrwMarkFilePrint(islocal)
7896" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7897 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007898
7899 " sanity check
7900 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007901 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007902" call Dret("s:NetrwMarkFilePrint")
7903 return
7904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007905" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7906 let curdir= s:NetrwGetCurdir(a:islocal)
7907
Bram Moolenaar446cb832008-06-24 21:56:24 +00007908 if exists("s:netrwmarkfilelist_{curbufnr}")
7909 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007910 call s:NetrwUnmarkList(curbufnr,curdir)
7911 for fname in netrwmarkfilelist
7912 if a:islocal
7913 if g:netrw_keepdir
7914 let fname= s:ComposePath(curdir,fname)
7915 endif
7916 else
7917 let fname= curdir.fname
7918 endif
7919 1split
7920 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007922 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007923" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924 hardcopy
7925 q
7926 endfor
7927 2match none
7928 endif
7929" call Dret("s:NetrwMarkFilePrint")
7930endfun
7931
7932" ---------------------------------------------------------------------
7933" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7934" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007935" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007936fun! s:NetrwMarkFileRegexp(islocal)
7937" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7938
7939 " get the regular expression
7940 call inputsave()
7941 let regexp= input("Enter regexp: ","","file")
7942 call inputrestore()
7943
7944 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007945 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007946" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007947 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007948" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007949 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007950 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007951 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007952 else
7953 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007954 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007955 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007956" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957
7958 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007959 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007960 if fname =~ '^'.fnameescape(curdir)
7961" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7962 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7963 else
7964" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7965 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7966 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007967 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007968
7969 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007970" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007971
7972 " convert displayed listing into a filelist
7973 let eikeep = &ei
7974 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007975 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007976 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007977" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007978 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007979 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007980 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007981 sil NetrwKeepj norm! "ap
7982 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007983 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007984 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007985 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007987 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007988 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007989 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007990 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007991 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007992 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007993 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7994 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007995 call histdel("/",-1)
7996 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007997 endif
7998 " convert regexp into the more usual glob-style format
7999 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008000" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008001 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008002 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008003 let filelist= getline(1,line("$"))
8004 q!
8005 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008006 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007 endfor
8008 unlet filelist
8009 let @a = areg
8010 let &ei = eikeep
8011 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008012 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013
8014" call Dret("s:NetrwMarkFileRegexp")
8015endfun
8016
8017" ---------------------------------------------------------------------
8018" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8019" Uses the local marked file list.
8020fun! s:NetrwMarkFileSource(islocal)
8021" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8022 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008023
8024 " sanity check
8025 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008026 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008027" call Dret("s:NetrwMarkFileSource")
8028 return
8029 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008030" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8031 let curdir= s:NetrwGetCurdir(a:islocal)
8032
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033 if exists("s:netrwmarkfilelist_{curbufnr}")
8034 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035 call s:NetrwUnmarkList(curbufnr,curdir)
8036 for fname in netrwmarkfilelist
8037 if a:islocal
8038 if g:netrw_keepdir
8039 let fname= s:ComposePath(curdir,fname)
8040 endif
8041 else
8042 let fname= curdir.fname
8043 endif
8044 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008045" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008046 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008047 endfor
8048 2match none
8049 endif
8050" call Dret("s:NetrwMarkFileSource")
8051endfun
8052
8053" ---------------------------------------------------------------------
8054" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8055" Uses the global markfilelist
8056fun! s:NetrwMarkFileTag(islocal)
8057" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008058 let svpos = winsaveview()
8059" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008060 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008061 let curbufnr = bufnr("%")
8062
Bram Moolenaarff034192013-04-24 18:51:19 +02008063 " sanity check
8064 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008065 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008066" call Dret("s:NetrwMarkFileTag")
8067 return
8068 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008069" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008070
Bram Moolenaar446cb832008-06-24 21:56:24 +00008071 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008072" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8073 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008074 call s:NetrwUnmarkAll()
8075
8076 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008077
8078" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8079 call system(g:netrw_ctags." ".netrwmarkfilelist)
8080 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8082 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008083
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008085 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008086 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008087 let curdir= b:netrw_curdir
8088 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008089 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008091" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008092 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008093 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008094 wq!
8095 endif
8096 2match none
8097 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008098" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8099 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008100 endif
8101
8102" call Dret("s:NetrwMarkFileTag")
8103endfun
8104
8105" ---------------------------------------------------------------------
8106" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008107" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008108" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008109" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008110" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008111fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008112" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8113 let svpos = winsaveview()
8114" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008115 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 let hadtgt = exists("s:netrwmftgt")
8117 if !exists("w:netrw_bannercnt")
8118 let w:netrw_bannercnt= b:netrw_bannercnt
8119 endif
8120
8121 " set up target
8122 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008123" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008124 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8125 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008126" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008127 unlet s:netrwmftgt s:netrwmftgt_islocal
8128 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008129 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008130 endif
8131 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008132" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8133 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008134" call Dret("s:NetrwMarkFileTgt : removed target")
8135 return
8136 else
8137 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008138" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008139 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008140
8141 else
8142 " get word under cursor.
8143 " * If directory, use it for the target.
8144 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008145" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146 let curword= s:NetrwGetWord()
8147 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008148 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008151 elseif !a:islocal && tgtdir =~ '/$'
8152 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008153" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 else
8155 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008156" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008157 endif
8158 endif
8159 if a:islocal
8160 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8161 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008162" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008163 endif
8164 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008165 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008166 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8167 endif
8168 let s:netrwmftgt_islocal= a:islocal
8169
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008170 " need to do refresh so that the banner will be updated
8171 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008172 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008173" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008174 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008176" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008177 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008178 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8179 else
8180 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8181 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008182" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8183 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008185 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008186 endif
8187
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8189" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008190" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8191endfun
8192
8193" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8195fun! s:NetrwGetCurdir(islocal)
8196" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8197
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008198 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008199 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8200" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8201 elseif !exists("b:netrw_curdir")
8202 let b:netrw_curdir= getcwd()
8203" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8204 endif
8205
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008206" 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 +01008207 if b:netrw_curdir !~ '\<\a\{3,}://'
8208 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008209" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008210 if g:netrw_keepdir == 0
8211 call s:NetrwLcd(curdir)
8212 endif
8213 endif
8214
8215" call Dret("s:NetrwGetCurdir <".curdir.">")
8216 return b:netrw_curdir
8217endfun
8218
8219" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008220" s:NetrwOpenFile: query user for a filename and open it {{{2
8221fun! s:NetrwOpenFile(islocal)
8222" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008223 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008224 call inputsave()
8225 let fname= input("Enter filename: ")
8226 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008227" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8228
8229 " determine if Lexplore is in use
8230 if exists("t:netrw_lexbufnr")
8231 " check if t:netrw_lexbufnr refers to a netrw window
8232" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8233 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8234 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8235" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8236 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8237 exe "NetrwKeepj e ".fnameescape(fname)
8238 let @@= ykeep
8239" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8240 endif
8241 endif
8242
8243 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008244 if fname !~ '[/\\]'
8245 if exists("b:netrw_curdir")
8246 if exists("g:netrw_quiet")
8247 let netrw_quiet_keep = g:netrw_quiet
8248 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008249 let g:netrw_quiet = 1
8250 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008251 let s:rexposn_{bufnr("%")}= winsaveview()
8252" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008253 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008254 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008255 else
8256 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8257 endif
8258 if exists("netrw_quiet_keep")
8259 let g:netrw_quiet= netrw_quiet_keep
8260 else
8261 unlet g:netrw_quiet
8262 endif
8263 endif
8264 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008265 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008266 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008267 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008268" call Dret("s:NetrwOpenFile")
8269endfun
8270
8271" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008272" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8273" For the mapping to this function be made via
8274" netrwPlugin, you'll need to have had
8275" g:netrw_usetab set to non-zero.
8276fun! netrw#Shrink()
8277" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8278 let curwin = winnr()
8279 let wiwkeep = &wiw
8280 set wiw=1
8281
8282 if &ft == "netrw"
8283 if winwidth(0) > g:netrw_wiw
8284 let t:netrw_winwidth= winwidth(0)
8285 exe "vert resize ".g:netrw_wiw
8286 wincmd l
8287 if winnr() == curwin
8288 wincmd h
8289 endif
8290" call Decho("vert resize 0",'~'.expand("<slnum>"))
8291 else
8292 exe "vert resize ".t:netrw_winwidth
8293" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8294 endif
8295
8296 elseif exists("t:netrw_lexbufnr")
8297 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8298 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8299 let t:netrw_winwidth= winwidth(0)
8300 exe "vert resize ".g:netrw_wiw
8301 wincmd l
8302 if winnr() == curwin
8303 wincmd h
8304 endif
8305" call Decho("vert resize 0",'~'.expand("<slnum>"))
8306 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8307 exe "vert resize ".t:netrw_winwidth
8308" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8309 else
8310 call netrw#Lexplore(0,0)
8311 endif
8312
8313 else
8314 call netrw#Lexplore(0,0)
8315 endif
8316 let wiw= wiwkeep
8317
8318" call Dret("netrw#Shrink")
8319endfun
8320
8321" ---------------------------------------------------------------------
8322" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8323fun! s:NetSortSequence(islocal)
8324" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8325
8326 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008327 let svpos= winsaveview()
8328" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008329 call inputsave()
8330 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8331 call inputrestore()
8332
8333 " refresh the listing
8334 let g:netrw_sort_sequence= newsortseq
8335 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008336" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8337 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008338 let @@= ykeep
8339
8340" call Dret("NetSortSequence")
8341endfun
8342
8343" ---------------------------------------------------------------------
8344" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8345" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008346" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008347fun! s:NetrwUnmarkList(curbufnr,curdir)
8348" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8349
8350 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008351 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008352 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8353 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8354 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8355 call remove(s:netrwmarkfilelist,idx) " remove from global list
8356 endfor
8357 if s:netrwmarkfilelist == []
8358 unlet s:netrwmarkfilelist
8359 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008360
Bram Moolenaar446cb832008-06-24 21:56:24 +00008361 " getting rid of the local marked-file lists is easy
8362 unlet s:netrwmarkfilelist_{a:curbufnr}
8363 endif
8364 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8365 unlet s:netrwmarkfilemtch_{a:curbufnr}
8366 endif
8367 2match none
8368" call Dret("s:NetrwUnmarkList")
8369endfun
8370
8371" ---------------------------------------------------------------------
8372" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8373fun! s:NetrwUnmarkAll()
8374" call Dfunc("s:NetrwUnmarkAll()")
8375 if exists("s:netrwmarkfilelist")
8376 unlet s:netrwmarkfilelist
8377 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008378 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008379 2match none
8380" call Dret("s:NetrwUnmarkAll")
8381endfun
8382
8383" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008384" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385fun! s:NetrwUnmarkAll2()
8386" call Dfunc("s:NetrwUnmarkAll2()")
8387 redir => netrwmarkfilelist_let
8388 let
8389 redir END
8390 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008391 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008392 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8393 for flist in netrwmarkfilelist_list
8394 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8395 unlet s:netrwmarkfilelist_{curbufnr}
8396 unlet s:netrwmarkfilemtch_{curbufnr}
8397 endfor
8398" call Dret("s:NetrwUnmarkAll2")
8399endfun
8400
8401" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008402" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8403"
8404" Marked files are in two types of lists:
8405" s:netrwmarkfilelist -- holds complete paths to all marked files
8406" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8407"
8408" Marked files suitable for use with 2match are in:
8409" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008410fun! s:NetrwUnMarkFile(islocal)
8411" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008412 let svpos = winsaveview()
8413" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008414 let curbufnr = bufnr("%")
8415
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008416 " unmark marked file list
8417 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8418 if exists("s:netrwmarkfilelist")
8419" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008421 endif
8422
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008423 let ibuf= 1
8424 while ibuf < bufnr("$")
8425 if exists("s:netrwmarkfilelist_".ibuf)
8426 unlet s:netrwmarkfilelist_{ibuf}
8427 unlet s:netrwmarkfilemtch_{ibuf}
8428 endif
8429 let ibuf = ibuf + 1
8430 endwhile
8431 2match none
8432
Bram Moolenaar446cb832008-06-24 21:56:24 +00008433" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008434"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8435call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008436" call Dret("s:NetrwUnMarkFile")
8437endfun
8438
8439" ---------------------------------------------------------------------
8440" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8441fun! s:NetrwMenu(domenu)
8442
8443 if !exists("g:NetrwMenuPriority")
8444 let g:NetrwMenuPriority= 80
8445 endif
8446
Bram Moolenaaradc21822011-04-01 18:03:16 +02008447 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8449
8450 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008451" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008453 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8454 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8455 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8456 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8457 if g:netrw_dirhistmax > 0
8458 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8459 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8460 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8461 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8462 else
8463 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8464 endif
8465 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8466 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8467 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8468 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8469 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8470 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8471 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8472 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8473 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8474 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8475 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8476 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8477 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8478 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8479 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 +01008480 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 +02008481 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8482 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8483 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8484 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8485 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8486 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8487 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8488 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8489 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8490 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8491 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8492 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8493 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8494 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8495 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8496 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8500 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8510 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>'
8511 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>'
8512 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>'
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8514 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>'
8515 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>'
8516 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 +01008517 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 +02008518 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008520 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008521 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8522 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008523
8524 elseif !a:domenu
8525 let s:netrwcnt = 0
8526 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008527 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008528 exe curwin."wincmd w"
8529
8530 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008531" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008532 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008533" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008534 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008535 endif
8536 endif
8537" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008538 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008539 endif
8540
8541endfun
8542
8543" ---------------------------------------------------------------------
8544" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8545" Used by the O maps (as <SID>NetrwObtain())
8546fun! s:NetrwObtain(islocal)
8547" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8548
Bram Moolenaar97d62492012-11-15 21:28:22 +01008549 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008550 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008551 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008552 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008553 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8554 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008555 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008556 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008557 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008558
8559" call Dret("NetrwObtain")
8560endfun
8561
8562" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008563" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8564" If there's only one window, then the window will first be split.
8565" Returns:
8566" choice = 0 : didn't have to choose
8567" choice = 1 : saved modified file in window first
8568" choice = 2 : didn't save modified file, opened window
8569" choice = 3 : cancel open
8570fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008571" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008572
Bram Moolenaar97d62492012-11-15 21:28:22 +01008573 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008575 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008576
8577 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008578 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 let lastwinnr = winnr("$")
8580 let curword = s:NetrwGetWord()
8581 let choice = 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008582 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008583 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008584 let curdir = s:treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008585" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008586
Bram Moolenaar8d043172014-01-23 14:24:41 +01008587 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008588 if lastwinnr == 1
8589 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008590" 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 +02008591 " g:netrw_preview=0: preview window shown in a horizontally split window
8592 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008594 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008595 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008596" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008597 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008598 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008599 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008600 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008601" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008602 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008604 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008605" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606
8607 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008608 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008609 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008610 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008611 wincmd p
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008612" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008613
8614 " prevwinnr: the window number of the "prev" window
8615 " prevbufnr: the buffer number of the buffer in the "prev" window
8616 " bnrcnt : the qty of windows open on the "prev" buffer
8617 let prevwinnr = winnr()
8618 let prevbufnr = bufnr("%")
8619 let prevbufname = bufname("%")
8620 let prevmod = &mod
8621 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008622 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008623" 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 +01008624
8625 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008626 " and it doesn't appear in any other extant window, then ask the
8627 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008628 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008629" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008630 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008631" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008632 exe prevwinnr."wincmd w"
8633
8634 if bnrcnt == 1 && &hidden == 0
8635 " only one copy of the modified buffer in a window, and
8636 " hidden not set, so overwriting will lose the modified file. Ask first...
8637 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008638" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008639 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640
8641 if choice == 1
8642 " Yes -- write file & then browse
8643 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008644 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008645 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008647 exe origwin."wincmd w"
8648 let &ei = eikeep
8649 let @@ = ykeep
8650" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651 return choice
8652 endif
8653
8654 elseif choice == 2
8655 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008657 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008658
8659 else
8660 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008661" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008662 exe origwin."wincmd w"
8663 let &ei= eikeep
8664 let @@ = ykeep
8665" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008666 return choice
8667 endif
8668 endif
8669 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008670 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008671 endif
8672
8673 " restore b:netrw_curdir (window split/enew may have lost it)
8674 let b:netrw_curdir= curdir
8675 if a:islocal < 2
8676 if a:islocal
8677 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8678 else
8679 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8680 endif
8681 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008682 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008683" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008684 return choice
8685endfun
8686
8687" ---------------------------------------------------------------------
8688" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8689" Always assumed to be local -> remote
8690" call s:NetrwUpload(filename, target)
8691" call s:NetrwUpload(filename, target, fromdirectory)
8692fun! s:NetrwUpload(fname,tgt,...)
8693" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8694
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695 if a:tgt =~ '^\a\{3,}://'
8696 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008697 else
8698 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8699 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008700" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701
8702 if a:0 > 0
8703 let fromdir= a:1
8704 else
8705 let fromdir= getcwd()
8706 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008707" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008708
8709 if type(a:fname) == 1
8710 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008711" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008712 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008713" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8714 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8715" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008716 if a:tgt =~ '/$'
8717 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008718" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008719 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008720 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008721" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008722 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008723" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008724 endif
8725 q!
8726
8727 elseif type(a:fname) == 3
8728 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008729" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008730 let curdir= getcwd()
8731 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008732 if s:NetrwLcd(fromdir)
8733" call Dret("s:NetrwUpload : lcd failure")
8734 return
8735 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008736 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008737 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008738 if exists("g:netrw_port") && g:netrw_port != ""
8739 let useport= " ".g:netrw_scpport." ".g:netrw_port
8740 else
8741 let useport= ""
8742 endif
8743 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8744 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008745 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 +02008746 if s:NetrwLcd(curdir)
8747" call Dret("s:NetrwUpload : lcd failure")
8748 return
8749 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008750
8751 elseif a:tgt =~ '^ftp:'
8752 call s:NetrwMethod(a:tgt)
8753
8754 if b:netrw_method == 2
8755 " handle uploading a list of files via ftp+.netrc
8756 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008757 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008758" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008759
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008760 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008761" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762
8763 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008764 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008766 endif
8767
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008768 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008769" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770
Bram Moolenaaradc21822011-04-01 18:03:16 +02008771 if tgtdir == ""
8772 let tgtdir= '/'
8773 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008774 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008775" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776
8777 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8779" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008780 endfor
8781
8782 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783 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 +00008784 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8786 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008787 endif
8788 " 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 +01008789 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008790 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008791 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8792 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8793 else
8794 bw!|q
8795 endif
8796
8797 elseif b:netrw_method == 3
8798 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8799 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008800 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008801 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008802 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803
8804 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008805 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008806" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008807 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008808 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008809" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 endif
8811
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008812 if exists("g:netrw_uid") && g:netrw_uid != ""
8813 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008814 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008816 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008817 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008819" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008820 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008821 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008822" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008823 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008824 endif
8825
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008826 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008827" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828
8829 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008830 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832 endif
8833
8834 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008835 NetrwKeepj put =g:netrw_ftpextracmd
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 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008840 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008841" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endfor
8843
8844 " perform ftp:
8845 " -i : turns off interactive prompting from ftp
8846 " -n unix : DON'T use <.netrc>, even though it exists
8847 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008848 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008849 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008850 " 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 +01008851 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008852 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008853 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8854 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008855 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8857 let &debug = debugkeep
8858 let mod = 1
8859 else
8860 bw!|q
8861 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008862 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008863" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008864 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865 endif
8866 else
8867 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8868 endif
8869 endif
8870
8871" call Dret("s:NetrwUpload")
8872endfun
8873
8874" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008875" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008876fun! s:NetrwPreview(path) range
8877" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008878" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8879" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008880 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008881 NetrwKeepj call s:NetrwOptionsSave("s:")
8882 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8883 NetrwKeepj call s:NetrwOptionsSafe(1)
8884 else
8885 NetrwKeepj call s:NetrwOptionsSafe(0)
8886 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008887 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008888" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008890" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8891 if g:netrw_preview
8892 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008893 let pvhkeep = &pvh
8894 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8895 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008896" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8897 else
8898 " horizontal split
8899 let pvhkeep = &pvh
8900 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8901 let &pvh = winheight(0) - winsz
8902" 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 +02008903 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008904 " g:netrw_preview g:netrw_alto
8905 " 1 : vert 1: top -- preview window is vertically split off and on the left
8906 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8907 " 0 : 1: top -- preview window is horizontally split off and on the top
8908 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8909 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008910 " 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 +02008911 " the BufEnter event set up in netrwPlugin.vim
8912" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8913 let eikeep = &ei
8914 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008915 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008916 let &ei= eikeep
8917" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008918 if exists("pvhkeep")
8919 let &pvh= pvhkeep
8920 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008922 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 endif
8924 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008925 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 +00008926 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008927 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008928 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008929" call Dret("NetrwPreview")
8930endfun
8931
8932" ---------------------------------------------------------------------
8933" s:NetrwRefresh: {{{2
8934fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008935" 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 +00008936 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008937 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008938" call Decho("setl ma noro",'~'.expand("<slnum>"))
8939" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008940 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008941 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8942 if !exists("w:netrw_treetop")
8943 if exists("b:netrw_curdir")
8944 let w:netrw_treetop= b:netrw_curdir
8945 else
8946 let w:netrw_treetop= getcwd()
8947 endif
8948 endif
8949 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8950 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008951
8952 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008953 let screenposn = winsaveview()
8954" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008955
8956" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8957" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8958 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008959 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008960 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008961 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008962 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008963 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008964
8965 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008966" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8967 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008968
8969 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008970 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8971 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8972" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8973 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8974 else
8975" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8976 2match none
8977 endif
8978 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008979
Bram Moolenaar97d62492012-11-15 21:28:22 +01008980" restore
8981 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008982" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008983endfun
8984
8985" ---------------------------------------------------------------------
8986" s:NetrwRefreshDir: refreshes a directory by name {{{2
8987" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008988" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008989fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008990" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991 if g:netrw_fastbrowse == 0
8992 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008993" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008994 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008995" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008996
8997 if tgtwin > 0
8998 " tgtwin is being displayed, so refresh it
8999 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009000" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009001 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009002 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009003 exe curwin."wincmd w"
9004
9005 elseif bufnr(a:dirname) > 0
9006 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009007" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9008 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009009 endif
9010
9011 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009012" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009013 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009014 endif
9015" call Dret("s:NetrwRefreshDir")
9016endfun
9017
9018" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009019" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9020" window number to do its editing in.
9021" Supports [count]C where the count, if present, is used to specify
9022" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009023fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009024" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009025 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009026" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009027 if a:1 == "" " :NetrwC win#
9028 let g:netrw_chgwin= winnr()
9029 else " :NetrwC
9030 let g:netrw_chgwin= a:1
9031 endif
9032 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009033 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009034 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009035 let g:netrw_chgwin= winnr()
9036 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009037 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009038" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009039endfun
9040
9041" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009042" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9043" What this function does is to compute a priority for the patterns
9044" in the g:netrw_sort_sequence. It applies a substitute to any
9045" "files" that satisfy each pattern, putting the priority / in
9046" front. An "*" pattern handles the default priority.
9047fun! s:NetrwSetSort()
9048" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009049 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009050 if w:netrw_liststyle == s:LONGLIST
9051 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9052 else
9053 let seqlist = g:netrw_sort_sequence
9054 endif
9055 " sanity check -- insure that * appears somewhere
9056 if seqlist == ""
9057 let seqlist= '*'
9058 elseif seqlist !~ '\*'
9059 let seqlist= seqlist.',*'
9060 endif
9061 let priority = 1
9062 while seqlist != ""
9063 if seqlist =~ ','
9064 let seq = substitute(seqlist,',.*$','','e')
9065 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9066 else
9067 let seq = seqlist
9068 let seqlist = ""
9069 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009070 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009071 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009073 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009075 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078
9079 " sanity check
9080 if w:netrw_bannercnt > line("$")
9081 " apparently no files were left after a Hiding pattern was used
9082" call Dret("SetSort : no files left after hiding")
9083 return
9084 endif
9085 if seq == '*'
9086 let starpriority= spriority
9087 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009088 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009089 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009090 " sometimes multiple sorting patterns will match the same file or directory.
9091 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009092 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9093 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009094 endif
9095 let priority = priority + 1
9096 endwhile
9097 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009098 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9099 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009100 endif
9101
9102 " Following line associated with priority -- items that satisfy a priority
9103 " pattern get prefixed by ###/ which permits easy sorting by priority.
9104 " Sometimes files can satisfy multiple priority patterns -- only the latest
9105 " priority pattern needs to be retained. So, at this point, these excess
9106 " priority prefixes need to be removed, but not directories that happen to
9107 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009108 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9109 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009110 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009111
9112" call Dret("SetSort")
9113endfun
9114
Bram Moolenaarff034192013-04-24 18:51:19 +02009115" ---------------------------------------------------------------------
9116" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9117" Implements [count]Tb (bookhist<b>)
9118" [count]Th (bookhist<h>)
9119" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009120fun! s:NetrwSetTgt(islocal,bookhist,choice)
9121" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009122
9123 if a:bookhist == 'b'
9124 " supports choosing a bookmark as a target using a qb-generated list
9125 let choice= a:choice - 1
9126 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009127 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009128 else
9129 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9130 endif
9131
9132 elseif a:bookhist == 'h'
9133 " supports choosing a history stack entry as a target using a qb-generated list
9134 let choice= (a:choice % g:netrw_dirhistmax) + 1
9135 if exists("g:netrw_dirhist_".choice)
9136 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009137 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009138 else
9139 echomsg "Sorry, history#".a:choice." not available!"
9140 endif
9141 endif
9142
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009143 " refresh the display
9144 if !exists("b:netrw_curdir")
9145 let b:netrw_curdir= getcwd()
9146 endif
9147 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9148
Bram Moolenaarff034192013-04-24 18:51:19 +02009149" call Dret("s:NetrwSetTgt")
9150endfun
9151
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009153" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154fun! s:NetrwSortStyle(islocal)
9155" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009156 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009157 let svpos= winsaveview()
9158" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009159
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009160 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 +01009161 NetrwKeepj norm! 0
9162 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009163" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9164 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009165
9166" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9167endfun
9168
9169" ---------------------------------------------------------------------
9170" s:NetrwSplit: mode {{{2
9171" =0 : net and o
9172" =1 : net and t
9173" =2 : net and v
9174" =3 : local and o
9175" =4 : local and t
9176" =5 : local and v
9177fun! s:NetrwSplit(mode)
9178" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9179
Bram Moolenaar97d62492012-11-15 21:28:22 +01009180 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009181 call s:SaveWinVars()
9182
9183 if a:mode == 0
9184 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009185 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009186 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009187" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009188 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009189 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009190 NetrwKeepj call s:RestoreWinVars()
9191 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009192 unlet s:didsplit
9193
9194 elseif a:mode == 1
9195 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009196 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009197" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009198 tabnew
9199 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009200 NetrwKeepj call s:RestoreWinVars()
9201 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009202 unlet s:didsplit
9203
9204 elseif a:mode == 2
9205 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009206 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009207 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009208" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009209 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009210 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009211 NetrwKeepj call s:RestoreWinVars()
9212 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009213 unlet s:didsplit
9214
9215 elseif a:mode == 3
9216 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009217 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009218 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009219" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009220 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009221 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009222 NetrwKeepj call s:RestoreWinVars()
9223 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224 unlet s:didsplit
9225
9226 elseif a:mode == 4
9227 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009228 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009229 let eikeep = &ei
9230 let netrw_winnr = winnr()
9231 let netrw_line = line(".")
9232 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009233 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009234 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009235 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009236 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9237 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009238 let &ei = eikeep
9239 let netrw_curdir = s:NetrwTreeDir(0)
9240" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009241 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009242 let b:netrw_curdir = netrw_curdir
9243 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009244 NetrwKeepj call s:RestoreWinVars()
9245 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009246 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009247 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009248 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9249 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009250 let &ei= eikeep
9251 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009252 unlet s:didsplit
9253
9254 elseif a:mode == 5
9255 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009256 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009257 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009258" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009259 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009261 NetrwKeepj call s:RestoreWinVars()
9262 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 unlet s:didsplit
9264
9265 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009266 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 endif
9268
Bram Moolenaar97d62492012-11-15 21:28:22 +01009269 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009270" call Dret("s:NetrwSplit")
9271endfun
9272
9273" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009274" s:NetrwTgtMenu: {{{2
9275fun! s:NetrwTgtMenu()
9276 if !exists("s:netrw_menucnt")
9277 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009278 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009279" call Dfunc("s:NetrwTgtMenu()")
9280
9281 " the following test assures that gvim is running, has menus available, and has menus enabled.
9282 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9283 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009285 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9286 endif
9287 if !exists("s:netrw_initbookhist")
9288 call s:NetrwBookHistRead()
9289 endif
9290
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009291 " try to cull duplicate entries
9292 let tgtdict={}
9293
Bram Moolenaarff034192013-04-24 18:51:19 +02009294 " target bookmarked places
9295 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009296" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009297 let cnt= 1
9298 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009299 if has_key(tgtdict,bmd)
9300 let cnt= cnt + 1
9301 continue
9302 endif
9303 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009304 let ebmd= escape(bmd,g:netrw_menu_escape)
9305 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009306" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009307 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 +02009308 let cnt= cnt + 1
9309 endfor
9310 endif
9311
9312 " target directory browsing history
9313 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009314" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009315 let histcnt = 1
9316 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009317 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009318 if exists("g:netrw_dirhist_{histcnt}")
9319 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009320 if has_key(tgtdict,histentry)
9321 let histcnt = histcnt + 1
9322 continue
9323 endif
9324 let tgtdict[histentry] = histcnt
9325 let ehistentry = escape(histentry,g:netrw_menu_escape)
9326" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009327 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 +02009328 endif
9329 let histcnt = histcnt + 1
9330 endwhile
9331 endif
9332 endif
9333" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009334endfun
9335
9336" ---------------------------------------------------------------------
9337" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9338" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009339fun! s:NetrwTreeDir(islocal)
9340" 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 +02009341" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009342" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9343" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9344" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009345" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009346
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009347 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009348 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009349" 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 +01009350 let treedir= s:treedir
9351 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009352 unlet s:prevwinopen
9353" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009354 return treedir
9355 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009356 if exists("s:prevwinopen")
9357 unlet s:prevwinopen
9358 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009359
Bram Moolenaar8d043172014-01-23 14:24:41 +01009360 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9361 let b:netrw_curdir= getcwd()
9362 endif
9363 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009365
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009366 let s:treecurpos= winsaveview()
9367" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9368
9369 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009370" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9371" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009372
9373 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009374 let curline= substitute(getline('.'),"\t -->.*$",'','')
9375 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009376" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009377 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009378" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9379 elseif curline =~ '@$'
9380" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9381 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9382" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009383 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009384" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009385 let treedir= ""
9386 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009387
9388 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9390" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009391" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009392 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009393" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009394 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009395" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9396 sil! NetrwKeepj %d _
9397" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009398 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009399" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009400" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009401 endif
9402
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009403" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009404 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9405" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009406
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009407 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9408" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9409" let newdir = w:netrw_treetop.'/'.potentialdir
9410" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9411" let treedir = s:NetrwTreePath(newdir)
9412" let w:netrw_treetop = newdir
9413" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9414" else
9415" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009416 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009417" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009418 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009419
9420 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009421 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009422" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009423
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009424" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009425 return treedir
9426endfun
9427
9428" ---------------------------------------------------------------------
9429" s:NetrwTreeDisplay: recursive tree display {{{2
9430fun! s:NetrwTreeDisplay(dir,depth)
9431" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9432
9433 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009434 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009435
9436 " install ../ and shortdir
9437 if a:depth == ""
9438 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009439" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009440 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009441 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009442 if a:dir == w:netrw_treetop
9443 let shortdir= a:dir
9444 else
9445 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9446 endif
9447 call setline(line("$")+1,a:depth.shortdir)
9448 else
9449 let shortdir= substitute(a:dir,'^.*/','','e')
9450 call setline(line("$")+1,a:depth.shortdir.'/')
9451 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009453 " append a / to dir if its missing one
9454 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009455
9456 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009457 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459
Bram Moolenaar85850f32019-07-19 22:05:51 +02009460 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9461 if g:netrw_hide == 1
9462 " hide given patterns
9463 let listhide= split(g:netrw_list_hide,',')
9464" call Decho("listhide=".string(listhide))
9465 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009466 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009467 endfor
9468
9469 elseif g:netrw_hide == 2
9470 " show given patterns (only)
9471 let listhide= split(g:netrw_list_hide,',')
9472" call Decho("listhide=".string(listhide))
9473 let entries=[]
9474 for entry in w:netrw_treedict[dir]
9475 for pat in listhide
9476 if entry =~ pat
9477 call add(entries,entry)
9478 break
9479 endif
9480 endfor
9481 endfor
9482 let w:netrw_treedict[dir]= entries
9483 endif
9484 if depth != ""
9485 " always remove "." and ".." entries when there's depth
9486 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9487 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9488 endif
9489
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009490" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009491 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009492 if dir =~ '/$'
9493 let direntry= substitute(dir.entry,'[@/]$','','e')
9494 else
9495 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9496 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009497" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009498 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009499" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009500 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009501 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009502" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9503 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9504 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9505" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009506 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009507 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009509 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009510 endif
9511 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009512" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009513
Bram Moolenaar446cb832008-06-24 21:56:24 +00009514" call Dret("NetrwTreeDisplay")
9515endfun
9516
9517" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009518" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9519fun! s:NetrwRefreshTreeDict(dir)
9520" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009521 if !exists("w:netrw_treedict")
9522" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9523 return
9524 endif
9525
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009526 for entry in w:netrw_treedict[a:dir]
9527 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9528" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9529
9530 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9531" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9532 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009533 let liststar = s:NetrwGlob(direntry,'*',1)
9534 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009535 let w:netrw_treedict[direntry] = liststar + listdotstar
9536" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9537
9538 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9539" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9540 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009541 let liststar = s:NetrwGlob(direntry.'/','*',1)
9542 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009543 let w:netrw_treedict[direntry]= liststar + listdotstar
9544" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9545
9546 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9547" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9548 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009549 let liststar = s:NetrwGlob(direntry.'/','*',1)
9550 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009551" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9552
9553 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009554" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009555 endif
9556 endfor
9557" call Dret("s:NetrwRefreshTreeDict")
9558endfun
9559
9560" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009561" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009562" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009563fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009564 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009565" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009566" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9567" 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>"))
9568" 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 +00009569
9570 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009571 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009572" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009573 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009574 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009575" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009576 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 +02009577" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.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."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009581 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009582 if exists("w:netrw_treetop")
9583 let s:netrw_treetop= w:netrw_treetop
9584 else
9585 let w:netrw_treetop= getcwd()
9586 let s:netrw_treetop= w:netrw_treetop
9587 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009588
Bram Moolenaar446cb832008-06-24 21:56:24 +00009589 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009590 " insure that we have a treedict, albeit empty
9591" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009592 let w:netrw_treedict= {}
9593 endif
9594
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009595 " update the dictionary for the current directory
9596" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009597" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009598 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009599 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009600" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009601 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009602
9603 " if past banner, record word
9604 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9605 let fname= expand("<cword>")
9606 else
9607 let fname= ""
9608 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009609" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9610" 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 +00009611
9612 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009613" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009614 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009615" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009616
9617 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9618 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009619" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009620 1d
9621 endwhile
9622
Bram Moolenaar13600302014-05-22 18:26:40 +02009623 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009624
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009625" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009626 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009627 endif
9628endfun
9629
9630" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009631" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009632" Normally, treetop is w:netrw_treetop, but a
9633" user of the function ( netrw#SetTreetop() )
9634" wipes that out prior to calling this function
9635fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009636" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9637 if line(".") < w:netrw_bannercnt + 2
9638 let treedir= a:treetop
9639 if treedir !~ '/$'
9640 let treedir= treedir.'/'
9641 endif
9642" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9643 return treedir
9644 endif
9645
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009646 let svpos = winsaveview()
9647" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009648 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009649" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009650 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009651" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9652 let curline= getline('.')
9653" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9654 if curline =~ '/$'
9655" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9656 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9657" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9658 elseif curline =~ '@\s\+-->'
9659" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9660 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9661 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9662" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009663 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009664" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009665 let treedir= ""
9666 endif
9667 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9669" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009670 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9671 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9672 let treedir= dirname.treedir
9673 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009674" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009675 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009676" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009677 if a:treetop =~ '/$'
9678 let treedir= a:treetop.treedir
9679 else
9680 let treedir= a:treetop.'/'.treedir
9681 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009682" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009683 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009684" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009685" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9686 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009687" call Dret("s:NetrwTreePath <".treedir.">")
9688 return treedir
9689endfun
9690
9691" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009692" s:NetrwWideListing: {{{2
9693fun! s:NetrwWideListing()
9694
9695 if w:netrw_liststyle == s:WIDELIST
9696" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9697 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009698 " cpf: characters per filename
9699 " fpl: filenames per line
9700 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009701 setl ma noro
Bram Moolenaar91359012019-11-30 17:57:03 +01009702 let keepa= @a
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009703" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009704 let b:netrw_cpf= 0
9705 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009706 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009707 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9708 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009709 else
Bram Moolenaar91359012019-11-30 17:57:03 +01009710 let @a= keepa
Bram Moolenaar446cb832008-06-24 21:56:24 +00009711" call Dret("NetrwWideListing")
9712 return
9713 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009714 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009715 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009716" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009717
9718 " determine qty files per line (fpl)
9719 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9720 if w:netrw_fpl <= 0
9721 let w:netrw_fpl= 1
9722 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009723" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724
9725 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009726 " fpc: files per column of wide listing
9727 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009728 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009729 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9730 let newcolstart = w:netrw_bannercnt + fpc
9731 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009732" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009733 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009734" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009735 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009736 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009737 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009738 while line("$") >= newcolstart
9739 if newcolend > line("$") | let newcolend= line("$") | endif
9740 let newcolqty= newcolend - newcolstart
9741 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009742 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009743 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009744 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009745 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009746 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009747 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009748 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009749 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009750 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009751 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009752" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009753 if @* != keepregstar | sil! let @* = keepregstar | endif
9754 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009755 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009756 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9757 NetrwKeepj call histdel("/",-1)
9758 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9759 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009760" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009761 exe "setl ".g:netrw_bufsettings
Bram Moolenaar91359012019-11-30 17:57:03 +01009762 let @a= keepa
Bram Moolenaar85850f32019-07-19 22:05:51 +02009763" 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 +00009764" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009765 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009766 else
9767 if hasmapto("w","n")
9768 sil! nunmap <buffer> w
9769 endif
9770 if hasmapto("b","n")
9771 sil! nunmap <buffer> b
9772 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009773 endif
9774
9775endfun
9776
9777" ---------------------------------------------------------------------
9778" s:PerformListing: {{{2
9779fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009780" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9781" 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 +02009782" 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>"))
9783 sil! NetrwKeepj %d _
9784" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009785
Bram Moolenaar15146672011-10-20 22:22:38 +02009786 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009787" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009788 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009789
Bram Moolenaar85850f32019-07-19 22:05:51 +02009790 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009791 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009792" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009793
9794" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009795" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796" endif " Decho
9797
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009798" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009799 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9800 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009801" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9802 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009803 endif
9804
9805 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009806 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009807
9808 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009809 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009810" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009811 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009812 if exists("g:netrw_pchk")
9813 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9814 " failure detections.
9815 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009816 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009817 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9818 endif
9819 if exists("g:netrw_pchk")
9820 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9821 else
9822 let curdir= b:netrw_curdir
9823 endif
9824 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9825 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9826 else
9827 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009828 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009829 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009830 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009831 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009832" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009833 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009834 let w:netrw_bannercnt= 1
9835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009836" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9837" 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 +00009838
Bram Moolenaar85850f32019-07-19 22:05:51 +02009839 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009840 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009841 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 let sortby= sortby." reversed"
9843 endif
9844
9845 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009846 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009847" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009848 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009849" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009850 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009851 NetrwKeepj put ='\" Sorted by '.sortby
9852 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009853 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9854 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009855" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009856 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009857 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009858 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9859 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009860 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009861" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009862" 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 +00009863 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009864
Bram Moolenaar85850f32019-07-19 22:05:51 +02009865 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009866 if g:netrw_banner
9867 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009868" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009869 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009870 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009871 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009872 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009873 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009874 endif
9875 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009877" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009878 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009879 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009880 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009881
9882 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009883 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009884" 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 +01009885 if g:netrw_list_hide != "" && g:netrw_hide
9886 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009887 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009888 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009889 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009890 endif
9891 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009892 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009893 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009894
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895" 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 +01009896 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009898 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009899" 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 +01009900 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009901 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009902" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903" 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 +00009904 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009905
9906 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009907 if g:netrw_banner
9908 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009909 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009910" 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 +01009911" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009912" 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 +01009913 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009914
Bram Moolenaar446cb832008-06-24 21:56:24 +00009915 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009917 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009918 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009919 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009920 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009921 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009922" 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 +01009923" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9924 return
9925 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009926 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009927
9928 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009929 if !exists("w:netrw_bannercnt")
9930 let w:netrw_bannercnt= 0
9931 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009932" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9933" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9934" 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 +01009935
Bram Moolenaar5c736222010-01-06 20:54:52 +01009936 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009937" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009938" 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 +00009939 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009940 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009942 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009944
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009945 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009946 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009947" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009948 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949
Bram Moolenaar5c736222010-01-06 20:54:52 +01009950 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009951" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009952 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009953 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009954 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955 else
9956 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009957 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009958 endif
9959 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009960
Bram Moolenaar446cb832008-06-24 21:56:24 +00009961 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009962" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009963 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9964 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009965
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009966 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009967 " exten: sort by extension
9968 " The histdel(...,-1) calls remove the last search from the search history
9969" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009970 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9971 NetrwKeepj call histdel("/",-1)
9972 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9973 NetrwKeepj call histdel("/",-1)
9974 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9975 NetrwKeepj call histdel("/",-1)
9976 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9977" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009978 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009979 " normal direction sorting
9980 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9981 else
9982 " reverse direction sorting
9983 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9984 endif
9985 endif
9986 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9987 NetrwKeepj call histdel("/",-1)
9988
Bram Moolenaar446cb832008-06-24 21:56:24 +00009989 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009990 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009991" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009992 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009993" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009994 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009997 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009998 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009999" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010000 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10001 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010002 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010003 endif
10004
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010005 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010006" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010007 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010008 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010009 call histdel("/",-1)
10010 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010011 endif
10012 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010014
10015 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010016" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10017" 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 +010010018 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010019" 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 +010010020 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021" 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 +000010022
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010023 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010024 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010025" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010026 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010027 endif
10028
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010029 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010030 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10032 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010033 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10035 else
10036" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10037" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10038" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10039" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010040 endif
10041
10042 " record previous current directory
10043 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010044" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045
10046 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010047" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10048" 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 +010010049 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010050" 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 +020010051 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010052" 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 +000010053
10054 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010055" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010056 exe "setl ".g:netrw_bufsettings
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#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010058 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010059" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010060 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10061 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010062" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010063" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010064
Bram Moolenaar8d043172014-01-23 14:24:41 +010010065 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010066" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10067" 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 +010010068" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10069 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010070 unlet s:treecurpos
10071 endif
10072
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010073" 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>"))
10074" 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 +000010075" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10076endfun
10077
10078" ---------------------------------------------------------------------
10079" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010080fun! s:SetupNetrwStatusLine(statline)
10081" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10082
10083 if !exists("s:netrw_setup_statline")
10084 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010085" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010086
10087 if !exists("s:netrw_users_stl")
10088 let s:netrw_users_stl= &stl
10089 endif
10090 if !exists("s:netrw_users_ls")
10091 let s:netrw_users_ls= &laststatus
10092 endif
10093
10094 " set up User9 highlighting as needed
10095 let keepa= @a
10096 redir @a
10097 try
10098 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010100 if &bg == "dark"
10101 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10102 else
10103 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10104 endif
10105 endtry
10106 redir END
10107 let @a= keepa
10108 endif
10109
10110 " set up status line (may use User9 highlighting)
10111 " insure that windows have a statusline
10112 " make sure statusline is displayed
10113 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010114 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010116 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010117
10118" call Dret("SetupNetrwStatusLine : stl=".&stl)
10119endfun
10120
Bram Moolenaar85850f32019-07-19 22:05:51 +020010121" =========================================
10122" Remote Directory Browsing Support: {{{1
10123" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010124
10125" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010126" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10127" This function assumes that a long listing will be received. Size, time,
10128" and reverse sorts will be requested of the server but not otherwise
10129" enforced here.
10130fun! s:NetrwRemoteFtpCmd(path,listcmd)
10131" 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 +010010132" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010133 " sanity check: {{{3
10134 if !exists("w:netrw_method")
10135 if exists("b:netrw_method")
10136 let w:netrw_method= b:netrw_method
10137 else
10138 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10139" call Dret("NetrwRemoteFtpCmd")
10140 return
10141 endif
10142 endif
10143
10144 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10145 let ffkeep= &ff
10146 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010147" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010148
10149 " clear off any older non-banner lines " {{{3
10150 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010151" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10152 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010153
10154 ".........................................
10155 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10156 " ftp + <.netrc>: Method #2
10157 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010158 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010159 endif
10160 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010161 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010162" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010163 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010164 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010165" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010166 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010167" 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>"))
10168 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 +010010169 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010170" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10171 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 +010010172 endif
10173
10174 ".........................................
10175 elseif w:netrw_method == 3 " {{{3
10176 " ftp + machine,id,passwd,filename: Method #3
10177 setl ff=unix
10178 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010179 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010180 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010181 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010182 endif
10183
10184 " handle userid and password
10185 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010187 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10188 call NetUserPass("ftp:".host)
10189 endif
10190 if exists("g:netrw_uid") && g:netrw_uid != ""
10191 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010192 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010193 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010194 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010195 endif
10196 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010197 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010198 endif
10199 endif
10200
10201 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010202 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010203 endif
10204 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010205 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010206" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010207 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010208 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010209
10210 " perform ftp:
10211 " -i : turns off interactive prompting from ftp
10212 " -n unix : DON'T use <.netrc>, even though it exists
10213 " -n win32: quit being obnoxious about password
10214 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010215" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010216 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010217" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010218" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10219" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010220 endif
10221
10222 ".........................................
10223 elseif w:netrw_method == 9 " {{{3
10224 " sftp username@machine: Method #9
10225 " s:netrw_sftp_cmd
10226 setl ff=unix
10227
10228 " restore settings
10229 let &ff= ffkeep
10230" call Dret("NetrwRemoteFtpCmd")
10231 return
10232
10233 ".........................................
10234 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010235 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010236 endif
10237
10238 " cleanup for Windows " {{{3
10239 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010240 sil! NetrwKeepj %s/\r$//e
10241 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010242 endif
10243 if a:listcmd == "dir"
10244 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010245 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10246 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10247 NetrwKeepj call histdel("/",-1)
10248 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010249 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 +010010250 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10251 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010252 endif
10253 endif
10254
10255 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10256 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010257 exe 'NetrwKeepj '.w:netrw_bannercnt
10258 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010259 endif
10260 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010261 exe 'NetrwKeepj '.w:netrw_bannercnt
10262 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010263 endif
10264
10265 " restore settings " {{{3
10266 let &ff= ffkeep
10267" call Dret("NetrwRemoteFtpCmd")
10268endfun
10269
10270" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010271" s:NetrwRemoteListing: {{{2
10272fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010273" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010274
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10276 let w:netrw_bannercnt= s:bannercnt
10277 endif
10278 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10279 let w:netrw_bannercnt= s:bannercnt
10280 endif
10281
Bram Moolenaar446cb832008-06-24 21:56:24 +000010282 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010283
Bram Moolenaar446cb832008-06-24 21:56:24 +000010284 " sanity check:
10285 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010286" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010287 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010288" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010289 if !exists("g:netrw_quiet")
10290 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10291 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010292 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010293" call Dret("s:NetrwRemoteListing -1")
10294 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010295 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010296
Bram Moolenaar8d043172014-01-23 14:24:41 +010010297 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010298" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010299 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010300 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010301 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 +000010302 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010303 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 +000010304 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010305 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010306
Bram Moolenaar85850f32019-07-19 22:05:51 +020010307 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010308" call Dret("s:NetrwRemoteListing -1")
10309 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010310 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010311" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010312
Bram Moolenaar446cb832008-06-24 21:56:24 +000010313 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010314" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010315 let w:netrw_method= b:netrw_method
10316 endif
10317
Bram Moolenaar13600302014-05-22 18:26:40 +020010318 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010319 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010320" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010321 let s:method = "ftp"
10322 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010323 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010324 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010325 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010326 let listcmd= g:netrw_ftp_sizelist_cmd
10327 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010328" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010329 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010330" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010331
Bram Moolenaara6878372014-03-22 21:02:50 +010010332 " report on missing file or directory messages
10333 if search('[Nn]o such file or directory\|Failed to change directory')
10334 let mesg= getline(".")
10335 if exists("w:netrw_bannercnt")
10336 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010337 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010338 setl noma
10339 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010340 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010341 call netrw#ErrorMsg(s:WARNING,mesg,96)
10342" call Dret("s:NetrwRemoteListing : -1")
10343 return -1
10344 endif
10345
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010346 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 +000010347 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010348" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010349 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010350
10351 " cleanup
10352 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010353 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10354 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010355 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010356 sil! NetrwKeepj %s/\r$//e
10357 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010358
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010359 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010360 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010361 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010362 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010363" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010364 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010365" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010366 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010367 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010368 exe "sil! NetrwKeepj ".line1
10369 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010370
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010371" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010372 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010373" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010374 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10375 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010377" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010378 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10379 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10380 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10381 NetrwKeepj call histdel("/",-1)
10382 NetrwKeepj call histdel("/",-1)
10383 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010384 endif
10385 endif
10386
Bram Moolenaar13600302014-05-22 18:26:40 +020010387 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010389" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010391" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010392 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010393" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10394 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010395 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010396 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10397 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10398 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10399 NetrwKeepj call histdel("/",-1)
10400 NetrwKeepj call histdel("/",-1)
10401 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010403 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10404 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010405 endif
10406 else
10407 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010408" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010409 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010410 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10412 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10413" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010414 endif
10415 endif
10416
10417 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010418 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010419" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010420 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10421 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010422 endif
10423 endif
10424
10425 if w:netrw_liststyle == s:LONGLIST
10426 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010427" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010428
10429 if s:method == "ftp"
10430 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010431 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010432 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010433 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010434 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010435 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010436 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010437 sil! NetrwKeepj 1
10438 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 let line2= line(".")
10440 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010441 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010442 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010443 endif
10444 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010445 exe "sil! NetrwKeepj ".line1
10446 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 endif
10448
10449 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010451 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 +000010452 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010453" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010454 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010455 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010456 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10457 NetrwKeepj call histdel("/",-1)
10458 NetrwKeepj call histdel("/",-1)
10459 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 endif
10461 endif
10462
10463" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010464" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010465" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010466
10467" call Dret("s:NetrwRemoteListing 0")
10468 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010469endfun
10470
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471" ---------------------------------------------------------------------
10472" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10473fun! s:NetrwRemoteRm(usrhost,path) range
10474" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010475" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010476 let svpos= winsaveview()
10477" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010478
10479 let all= 0
10480 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10481 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010482" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483 for fname in s:netrwmarkfilelist_{bufnr("%")}
10484 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010485 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010487 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010488 let all= 1
10489 endif
10490 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010491 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010492
10493 else
10494 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010495" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010496
10497 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010498 let keepsol = &l:sol
10499 setl nosol
10500 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501
10502 " remove multiple files and directories
10503 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010504 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010506 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010507 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010508 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010509 let all= 1
10510 endif
10511 let ctr= ctr + 1
10512 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010513 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 endif
10515
10516 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010517" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010518 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010519" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10520 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521
10522" call Dret("s:NetrwRemoteRm")
10523endfun
10524
10525" ---------------------------------------------------------------------
10526" s:NetrwRemoteRmFile: {{{2
10527fun! s:NetrwRemoteRmFile(path,rmfile,all)
10528" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10529
10530 let all= a:all
10531 let ok = ""
10532
10533 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10534 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010535" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 if !all
10537 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010538" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010539 call inputsave()
10540 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10541 call inputrestore()
10542 echohl NONE
10543 if ok == ""
10544 let ok="no"
10545 endif
10546 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010547 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010548 let all= 1
10549 endif
10550 endif
10551
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010552 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010553" 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 +000010554 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010555" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010556 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010557 if path =~ '^\a\{3,}://'
10558 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010559 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010560 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010561 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10562 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010563" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010564 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010565" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010566 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010567 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010568 let ok="q"
10569 else
10570 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010571" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10572" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10573" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010574 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010575 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010576 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010577 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010579" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010581 if v:shell_error != 0
10582 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010583 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 +010010584 else
10585 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10586 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010587 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010588 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010589 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010590" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010591 endif
10592 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010593 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010594" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010595 endif
10596
10597 else
10598 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010599" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 if !all
10601 call inputsave()
10602 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10603 call inputrestore()
10604 if ok == ""
10605 let ok="no"
10606 endif
10607 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010608 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010609 let all= 1
10610 endif
10611 endif
10612
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010613 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010614 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010615 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616 else
10617 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010618 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10619" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010620 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010621" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010622
10623 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010624" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10625 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10626" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010627 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010628" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010629
10630 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010631 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010632 endif
10633 endif
10634 endif
10635
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010636 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010637" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010638 endif
10639 endif
10640
10641" call Dret("s:NetrwRemoteRmFile ".ok)
10642 return ok
10643endfun
10644
10645" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010646" s:NetrwRemoteRename: rename a remote file or directory {{{2
10647fun! s:NetrwRemoteRename(usrhost,path) range
10648" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10649
10650 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010651 let svpos = winsaveview()
10652" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 let ctr = a:firstline
10654 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10655
10656 " rename files given by the markfilelist
10657 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10658 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 if exists("subfrom")
10661 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010662" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010663 else
10664 call inputsave()
10665 let newname= input("Moving ".oldname." to : ",oldname)
10666 call inputrestore()
10667 if newname =~ '^s/'
10668 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10669 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10670 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010671" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010672 endif
10673 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010674
Bram Moolenaar446cb832008-06-24 21:56:24 +000010675 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010676 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010677 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010678 let oldname= s:ShellEscape(a:path.oldname)
10679 let newname= s:ShellEscape(a:path.newname)
10680" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010681 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010682 endif
10683
10684 endfor
10685 call s:NetrwUnMarkFile(1)
10686
10687 else
10688
10689 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010690 let keepsol= &l:sol
10691 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010692 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010693 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010694
10695 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010697
10698 call inputsave()
10699 let newname= input("Moving ".oldname." to : ",oldname)
10700 call inputrestore()
10701
10702 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10703 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10704 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010705 let oldname= s:ShellEscape(a:path.oldname)
10706 let newname= s:ShellEscape(a:path.newname)
10707" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010708 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709 endif
10710
10711 let ctr= ctr + 1
10712 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010713 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010714 endif
10715
10716 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010717 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010718" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10719 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010720
10721" call Dret("NetrwRemoteRename")
10722endfun
10723
Bram Moolenaar85850f32019-07-19 22:05:51 +020010724" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010725" Local Directory Browsing Support: {{{1
10726" ==========================================
10727
10728" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010729" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010730" Should accept: file://localhost/etc/fstab
10731" file:///etc/fstab
10732" file:///c:/WINDOWS/clock.avi
10733" file:///c|/WINDOWS/clock.avi
10734" file://localhost/c:/WINDOWS/clock.avi
10735" file://localhost/c|/WINDOWS/clock.avi
10736" file://c:/foo.txt
10737" file:///c:/foo.txt
10738" 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 +020010739fun! netrw#FileUrlEdit(fname)
10740" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010741 let fname = a:fname
10742 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010743" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010744 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010745" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010746 endif
10747 if (has("win32") || has("win95") || has("win64") || has("win16"))
10748 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010749" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010750 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010751" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010752 endif
10753 endif
10754 let fname2396 = netrw#RFC2396(fname)
10755 let fname2396e= fnameescape(fname2396)
10756 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10757 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010758" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010759 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010760" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010761 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10762 endif
10763 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010764
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10766" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010767 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010768 exe 'NetrwKeepj keepalt edit '.plainfname
10769 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10770
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" 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 +020010772" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010773 exe "sil doau BufReadPost ".fname2396e
10774endfun
10775
10776" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010777" netrw#LocalBrowseCheck: {{{2
10778fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010779 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010780 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10781 "
10782 " unfortunate interaction -- split window debugging can't be used here, must use
10783 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10784 " another call to LocalBrowseCheck() when attempts to write
10785 " to the DBG buffer are made.
10786 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010787 " The &ft == "netrw" test was installed because the BufEnter event
10788 " would hit when re-entering netrw windows, creating unexpected
10789 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010790" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010791" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010792" 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 +020010793" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010794" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10795" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010796
Bram Moolenaar97d62492012-11-15 21:28:22 +010010797 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010798 if isdirectory(s:NetrwFile(a:dirname))
10799" 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 +010010800
Bram Moolenaar97d62492012-11-15 21:28:22 +010010801 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010802" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10803" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010804 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010805
Bram Moolenaar446cb832008-06-24 21:56:24 +000010806 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010807" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010808 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010809
Bram Moolenaar5c736222010-01-06 20:54:52 +010010810 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010811" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010812 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010813 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010814 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010815" 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 +010010816" call Dret("netrw#LocalBrowseCheck")
10817 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010818 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010819
Bram Moolenaar85850f32019-07-19 22:05:51 +020010820 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010821 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10822 " AND IF the listing style is not a tree listing
10823 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010824" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010825 let ibuf = 1
10826 let buflast = bufnr("$")
10827 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010828 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10829 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830 endif
10831 let ibuf= ibuf + 1
10832 endwhile
10833 endif
10834 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010835" 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>"))
10836" 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 +000010837 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010838" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010839endfun
10840
10841" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010842" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010843" performed any shell command. The idea is to cause all local-browsing
10844" buffers to be refreshed after a user has executed some shell command,
10845" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010846fun! s:LocalBrowseRefresh()
10847" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010848" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10849" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010850
Bram Moolenaar446cb832008-06-24 21:56:24 +000010851 " determine which buffers currently reside in a tab
10852 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010853" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010854 return
10855 endif
10856 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010857" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010858 return
10859 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010860 if exists("s:netrw_events") && s:netrw_events == 1
10861 " s:LocalFastBrowser gets called (indirectly) from a
10862 let s:netrw_events= 2
10863" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10864 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010865 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010866 let itab = 1
10867 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010868 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010869 while itab <= tabpagenr("$")
10870 let buftablist = buftablist + tabpagebuflist()
10871 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010872 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010873 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010874" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10875" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010876 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10877 " | refresh any netrw window
10878 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010879 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010880 let ibl = 0
10881 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010882" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010883 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10884 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010885 " (ibuf not shown in a current window AND
10886 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10888 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010889 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010890" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010891 continue
10892 elseif index(tabpagebuflist(),ibuf) != -1
10893 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010894" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010895 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010896 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010897 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10898 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10899 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10900 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010901" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010902 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10903 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10904 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010905 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010906 endif
10907 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010908" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010909 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010910" call Decho("restore window: win_gotoid(".curwinid.")")
10911 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010912 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010913
Bram Moolenaara6878372014-03-22 21:02:50 +010010914" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010915endfun
10916
10917" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010918" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10919"
10920" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010921" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010922" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10923" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010924" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010925"
10926" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10927" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010928" (re-using a buffer may not be as accurate)
10929"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010930" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010931" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10932" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10933" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10934" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010935fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010936" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10937" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10938" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10939" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010940
10941 " initialize browselist, a list of buffer numbers that the local browser has used
10942 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010943" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010944 let s:netrw_browselist= []
10945 endif
10946
10947 " append current buffer to fastbrowse list
10948 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010949" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010950 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010951" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010952 endif
10953
10954 " enable autocmd events to handle refreshing/removing local browser buffers
10955 " If local browse buffer is currently showing: refresh it
10956 " If local browse buffer is currently hidden : wipe it
10957 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10958 " =1 : medium speed, re-use directory listing for remote only
10959 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010960 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10961 let s:netrw_events= 1
10962 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010963 au!
10964 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010965" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010966 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010967 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010968" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010969 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010970 endif
10971 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010972
10973 " user must have changed fastbrowse to its fast setting, so remove
10974 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010975 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010976" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010977 unlet s:netrw_events
10978 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010979 au!
10980 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010981 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010982 endif
10983
Bram Moolenaar85850f32019-07-19 22:05:51 +020010984" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010985endfun
10986
10987" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010988" s:LocalListing: does the job of "ls" for local directories {{{2
10989fun! s:LocalListing()
10990" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010991" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10992" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10993" 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 +010010994
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010995" 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
10996" 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
10997" 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 +010010998
10999 " get the list of files contained in the current directory
11000 let dirname = b:netrw_curdir
11001 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011002 let filelist = s:NetrwGlob(dirname,"*",0)
11003 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011004" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011005
11006 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011007" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011008 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11009 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011010" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011011 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011012" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011013 endif
11014
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011015" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011016" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011017" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011018
11019 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11020 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11021 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011022" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11023" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011024 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011025" 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 +010011026
11027 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011028" call Decho(" ",'~'.expand("<slnum>"))
11029" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011030
11031 if getftype(filename) == "link"
11032 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011033" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011034 let pfile= filename."@"
11035
11036 elseif getftype(filename) == "socket"
11037 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011038" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011039 let pfile= filename."="
11040
11041 elseif getftype(filename) == "fifo"
11042 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011043" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011044 let pfile= filename."|"
11045
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011046 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011047 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011048" call Decho("indicate <".filename."> is a directory 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 exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011052 if (has("win32") || has("win95") || has("win64") || has("win16"))
11053 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11054 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011055" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011056 let pfile= filename."*"
11057 else
11058 " normal file
11059 let pfile= filename
11060 endif
11061 elseif executable(filename)
11062 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011063" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011064 let pfile= filename."*"
11065 else
11066 " normal file
11067 let pfile= filename
11068 endif
11069
11070 else
11071 " normal file
11072 let pfile= filename
11073 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011074" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011075
11076 if pfile =~ '//$'
11077 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011078" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011079 endif
11080 let pfile= strpart(pfile,dirnamelen)
11081 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011082" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11083" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011084
11085 if w:netrw_liststyle == s:LONGLIST
11086 let sz = getfsize(filename)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011087 let fsz = strpart(" ",1,15-strlen(sz)).sz
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011088 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011089 let sz= s:NetrwHumanReadable(sz)
11090 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011091 let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011092 let pfile = longfile.sz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011093" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011094 endif
11095
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011096 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011097 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011098 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011099" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011100" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011101 let t = getftime(filename)
11102 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaar91359012019-11-30 17:57:03 +010011103" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011104 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011105 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011106
11107 elseif g:netrw_sort_by =~ "^s"
11108 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011109" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011110" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011111 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011112 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011113 let sz= s:NetrwHumanReadable(sz)
11114 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011115 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011117 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011118 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011119
11120 else
11121 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011122" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011123" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011124 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011125 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011126" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011127 endfor
11128
11129 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011130 sil! NetrwKeepj g/^$/d
11131 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011132 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011133" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011134 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11135
11136" call Dret("s:LocalListing")
11137endfun
11138
11139" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011140" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11141fun! s:NetrwLocalExecute(cmd)
11142" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11143 let ykeep= @@
11144 " sanity check
11145 if !executable(a:cmd)
11146 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11147 let @@= ykeep
11148" call Dret("s:NetrwLocalExecute")
11149 return
11150 endif
11151
11152 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011154 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011155" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011156
11157 " strip any ansi escape sequences off
11158 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11159
11160 " show user the result(s)
11161 echomsg result
11162 let @@= ykeep
11163
11164" call Dret("s:NetrwLocalExecute")
11165endfun
11166
11167" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011168" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011169fun! s:NetrwLocalRename(path) range
11170" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11171
11172 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011173 let ykeep = @@
11174 let ctr = a:firstline
11175 let svpos = winsaveview()
11176 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011177" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011178
11179 " rename files given by the markfilelist
11180 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11181 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011182" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011183 if exists("subfrom")
11184 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011185" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011186 else
11187 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011188 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011189 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011190 if newname =~ ''
11191 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11192 let newname = substitute(newname,'^.*','','')
11193 elseif newname =~ ''
11194 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11195 let newname = substitute(newname,'[^/]*','','')
11196 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011197 if newname =~ '^s/'
11198 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11199 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011200" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011201 let newname = substitute(oldname,subfrom,subto,'')
11202 endif
11203 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011204 if !all && filereadable(newname)
11205 call inputsave()
11206 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11207 call inputrestore()
11208 if response == "all"
11209 let all= 1
11210 elseif response != "y" && response != "yes"
11211 " refresh the directory
11212" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11213 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11214" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11215 NetrwKeepj call winrestview(svpos)
11216 let @@= ykeep
11217" call Dret("NetrwLocalRename")
11218 return
11219 endif
11220 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011221 call rename(oldname,newname)
11222 endfor
11223 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011224
Bram Moolenaar97d62492012-11-15 21:28:22 +010011225 else
11226
11227 " attempt to rename files/directories
11228 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011229 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011230
11231 " sanity checks
11232 if line(".") < w:netrw_bannercnt
11233 let ctr= ctr + 1
11234 continue
11235 endif
11236 let curword= s:NetrwGetWord()
11237 if curword == "./" || curword == "../"
11238 let ctr= ctr + 1
11239 continue
11240 endif
11241
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011242 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011243 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011244" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011245
11246 call inputsave()
11247 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11248 call inputrestore()
11249
11250 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011251" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011252
11253 let ctr= ctr + 1
11254 endwhile
11255 endif
11256
11257 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011258" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011259 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011260" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11261 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011262 let @@= ykeep
11263
11264" call Dret("NetrwLocalRename")
11265endfun
11266
11267" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011268" s:NetrwLocalRm: {{{2
11269fun! s:NetrwLocalRm(path) range
11270" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011271" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011272
11273 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011275 let ret = 0
11276 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011277 let svpos = winsaveview()
11278" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011279
11280 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11281 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011282" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011283 for fname in s:netrwmarkfilelist_{bufnr("%")}
11284 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011285 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011286 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011287 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011288 let all= 1
11289 endif
11290 endfor
11291 call s:NetrwUnMarkFile(1)
11292
11293 else
11294 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011295" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011296
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011297 let keepsol= &l:sol
11298 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011299 let ctr = a:firstline
11300 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011301 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011302
11303 " sanity checks
11304 if line(".") < w:netrw_bannercnt
11305 let ctr= ctr + 1
11306 continue
11307 endif
11308 let curword= s:NetrwGetWord()
11309 if curword == "./" || curword == "../"
11310 let ctr= ctr + 1
11311 continue
11312 endif
11313 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011314 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011315 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011316 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011317 let all= 1
11318 endif
11319 let ctr= ctr + 1
11320 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011321 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011322 endif
11323
11324 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011325" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011326 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011327 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011328" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11329 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011330 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011331 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011332
11333" call Dret("s:NetrwLocalRm")
11334endfun
11335
11336" ---------------------------------------------------------------------
11337" s:NetrwLocalRmFile: remove file fname given the path {{{2
11338" Give confirmation prompt unless all==1
11339fun! s:NetrwLocalRmFile(path,fname,all)
11340" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011341
Bram Moolenaar446cb832008-06-24 21:56:24 +000011342 let all= a:all
11343 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011344 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011345 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11346" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011347
11348 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11349 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011350" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011351 if !all
11352 echohl Statement
11353 call inputsave()
11354 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11355 call inputrestore()
11356 echohl NONE
11357 if ok == ""
11358 let ok="no"
11359 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011360" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011361 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011362" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011363 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011364 let all= 1
11365 endif
11366 endif
11367
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011368 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011369 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011370" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011371 endif
11372
11373 else
11374 " attempt to remove directory
11375 if !all
11376 echohl Statement
11377 call inputsave()
11378 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11379 call inputrestore()
11380 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11381 if ok == ""
11382 let ok="no"
11383 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011384 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011385 let all= 1
11386 endif
11387 endif
11388 let rmfile= substitute(rmfile,'[\/]$','','e')
11389
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011390 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +020011391 if v:version < 704 || (v:version == 704 && !has("patch1107"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011392" " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
11393 call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
11394" " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011395
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011396 if v:shell_error != 0
11397" " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11398 let errcode= s:NetrwDelete(rmfile)
11399" " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011400
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011401 if errcode != 0
11402 if has("unix")
11403" " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11404 call system("rm ".s:ShellEscape(rmfile))
11405 if v:shell_error != 0 && !exists("g:netrw_quiet")
11406 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
11407 let ok="no"
11408 endif
11409 elseif !exists("g:netrw_quiet")
11410 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011411 let ok="no"
11412 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011413 endif
11414 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011415 else
11416 if delete(rmfile,"d")
11417 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
11418 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011419 endif
11420 endif
11421 endif
11422
11423" call Dret("s:NetrwLocalRmFile ".ok)
11424 return ok
11425endfun
11426
Bram Moolenaar85850f32019-07-19 22:05:51 +020011427" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011428" Support Functions: {{{1
11429
Bram Moolenaar488c6512005-08-11 20:09:58 +000011430" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011431" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11432" 0: marked file list of current buffer
11433" 1: marked file target
11434fun! netrw#Access(ilist)
11435 if a:ilist == 0
11436 if exists("s:netrwmarkfilelist_".bufnr('%'))
11437 return s:netrwmarkfilelist_{bufnr('%')}
11438 else
11439 return "no-list-buf#".bufnr('%')
11440 endif
11441 elseif a:ilist == 1
11442 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011443 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011444endfun
11445
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011446" ---------------------------------------------------------------------
11447" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11448fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011449 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450endfun
11451
Bram Moolenaara6878372014-03-22 21:02:50 +010011452" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011453" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11454" I expect this function to be used in
11455" :PChkAssert netrw#Expose("netrwmarkfilelist")
11456" for example.
11457fun! netrw#Expose(varname)
11458" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011459 if exists("s:".a:varname)
11460 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011461" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011462 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011463" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011464 if type(retval) == 3
11465 let retval = copy(retval)
11466 let i = 0
11467 while i < len(retval)
11468 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11469 let i = i + 1
11470 endwhile
11471 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011472" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011473 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011474 else
11475" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011476 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011477 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011478" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011479 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011480 endif
11481
11482" call Dret("netrw#Expose ".string(retval))
11483 return retval
11484endfun
11485
11486" ---------------------------------------------------------------------
11487" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11488fun! netrw#Modify(varname,newvalue)
11489" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11490 exe "let s:".a:varname."= ".string(a:newvalue)
11491" call Dret("netrw#Modify")
11492endfun
11493
11494" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011495" netrw#RFC2396: converts %xx into characters {{{2
11496fun! netrw#RFC2396(fname)
11497" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11498 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11499" call Dret("netrw#RFC2396 ".fname)
11500 return fname
11501endfun
11502
11503" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011504" netrw#UserMaps: supports user-specified maps {{{2
11505" see :help function()
11506"
11507" g:Netrw_UserMaps is a List with members such as:
11508" [[keymap sequence, function reference],...]
11509"
11510" The referenced function may return a string,
11511" refresh : refresh the display
11512" -other- : this string will be executed
11513" or it may return a List of strings.
11514"
11515" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011516" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011517" Related functions:
11518" netrw#Expose(varname) -- see s:varname variables
11519" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11520" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11521fun! netrw#UserMaps(islocal)
11522" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11523" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11524
11525 " set up usermaplist
11526 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11527" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11528 for umap in g:Netrw_UserMaps
11529" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11530" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11531 " if umap[0] is a string and umap[1] is a string holding a function name
11532 if type(umap[0]) == 1 && type(umap[1]) == 1
11533" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11534 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11535 else
11536 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11537 endif
11538 endfor
11539 endif
11540" call Dret("netrw#UserMaps")
11541endfun
11542
11543" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011544" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11545fun! netrw#WinPath(path)
11546" call Dfunc("netrw#WinPath(path<".a:path.">)")
11547 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11548 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011549 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011550 " remove trailing slash (Win95)
11551 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11552 " remove escaped spaces
11553 let path = substitute(path, '\ ', ' ', 'g')
11554 " convert slashes to backslashes
11555 let path = substitute(path, '/', '\', 'g')
11556 else
11557 let path= a:path
11558 endif
11559" call Dret("netrw#WinPath <".path.">")
11560 return path
11561endfun
11562
11563" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011564" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11565" cb : bl2mf=0 add marked files to buffer list
11566" cB : bl2mf=1 use bufferlist to mark files
11567" (mnemonic: cb = copy (marked files) to buffer list)
11568fun! s:NetrwBadd(islocal,bl2mf)
11569" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11570 if a:bl2mf
11571 " cB: add buffer list to marked files
11572 redir => bufl
11573 ls
11574 redir END
11575 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11576 for fname in bufl
11577 call s:NetrwMarkFile(a:islocal,fname)
11578 endfor
11579 else
11580 " cb: add marked files to buffer list
11581 for fname in s:netrwmarkfilelist_{bufnr("%")}
11582" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11583 exe "badd ".fnameescape(fname)
11584 endfor
11585 let curbufnr = bufnr("%")
11586 let curdir = s:NetrwGetCurdir(a:islocal)
11587 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11588 endif
11589" call Dret("s:NetrwBadd")
11590endfun
11591
11592" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011593" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11594fun! s:ComposePath(base,subdir)
11595" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11596
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011597 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011598" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011599 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011600 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011601 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011602 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011603 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011604 endif
11605
Bram Moolenaar85850f32019-07-19 22:05:51 +020011606 " COMBAK: test on windows with changing to root directory: :e C:/
11607 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011608" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011609 let ret= a:subdir
11610
Bram Moolenaar85850f32019-07-19 22:05:51 +020011611 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011612" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011613 if a:base =~ '[/\\]$'
11614 let ret= a:base.a:subdir
11615 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011616 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011617 endif
11618
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011619 elseif a:base =~ '^\a\{3,}://'
11620" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011621 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11622 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11623 if a:subdir == '../'
11624 if curpath =~ '[^/]/[^/]\+/$'
11625 let curpath= substitute(curpath,'[^/]\+/$','','')
11626 else
11627 let curpath=""
11628 endif
11629 let ret= urlbase.curpath
11630 else
11631 let ret= urlbase.curpath.a:subdir
11632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011633" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11634" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11635" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011636
11637 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011638" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011639 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11640 if a:base =~ '^//'
11641 " keeping initial '//' for the benefit of network share listing support
11642 let ret= '/'.ret
11643 endif
11644 let ret= simplify(ret)
11645 endif
11646
11647" call Dret("s:ComposePath ".ret)
11648 return ret
11649endfun
11650
11651" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011652" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11653" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11654fun! s:DeleteBookmark(fname)
11655" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11656 call s:MergeBookmarks()
11657
11658 if exists("g:netrw_bookmarklist")
11659 let indx= index(g:netrw_bookmarklist,a:fname)
11660 if indx == -1
11661 let indx= 0
11662 while indx < len(g:netrw_bookmarklist)
11663 if g:netrw_bookmarklist[indx] =~ a:fname
11664 call remove(g:netrw_bookmarklist,indx)
11665 let indx= indx - 1
11666 endif
11667 let indx= indx + 1
11668 endwhile
11669 else
11670 " remove exact match
11671 call remove(g:netrw_bookmarklist,indx)
11672 endif
11673 endif
11674
11675" call Dret("s:DeleteBookmark")
11676endfun
11677
11678" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011679" s:FileReadable: o/s independent filereadable {{{2
11680fun! s:FileReadable(fname)
11681" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11682
11683 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011684 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011685 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011687 endif
11688
11689" call Dret("s:FileReadable ".ret)
11690 return ret
11691endfun
11692
11693" ---------------------------------------------------------------------
11694" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11695" Places correct suffix on end of temporary filename,
11696" using the suffix provided with fname
11697fun! s:GetTempfile(fname)
11698" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11699
11700 if !exists("b:netrw_tmpfile")
11701 " get a brand new temporary filename
11702 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011703" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011704
Bram Moolenaarc236c162008-07-13 17:41:49 +000011705 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011706" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011707
Bram Moolenaar9964e462007-05-05 17:54:07 +000011708 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011709 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11710" 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 +010011711 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011712" call Dret("s:GetTempfile getcwd<".getcwd().">")
11713 return ""
11714 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011715
Bram Moolenaar9964e462007-05-05 17:54:07 +000011716 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011717 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011718" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011719
Bram Moolenaar9964e462007-05-05 17:54:07 +000011720 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011721 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011722 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011723 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011724 if !exists("+shellslash") || !&ssl
11725 let tmpfile = substitute(tmpfile,'/','\','g')
11726 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011727 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011728 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011729 endif
11730 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011731" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011732 else
11733 " re-use temporary filename
11734 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011735" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011736 endif
11737
11738 " use fname's suffix for the temporary file
11739 if a:fname != ""
11740 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011741" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011742 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011743 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011744 elseif a:fname =~ '.txz$'
11745 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011746 else
11747 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11748 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011749" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011750 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011751" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011752 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011753" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011754 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11755 endif
11756 endif
11757
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011758" 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 +000011759" call Dret("s:GetTempfile <".tmpfile.">")
11760 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011761endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011762
11763" ---------------------------------------------------------------------
11764" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011765" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011766fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011767" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011768 if s:user == ""
11769 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11770 else
11771 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11772 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011773 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011774 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011775 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011776 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011777 else
11778 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11779 endif
11780" call Dret("s:MakeSshCmd <".sshcmd.">")
11781 return sshcmd
11782endfun
11783
11784" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011785" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11786fun! s:MakeBookmark(fname)
11787" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11788
11789 if !exists("g:netrw_bookmarklist")
11790 let g:netrw_bookmarklist= []
11791 endif
11792
11793 if index(g:netrw_bookmarklist,a:fname) == -1
11794 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011795 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011796 call add(g:netrw_bookmarklist,a:fname.'/')
11797 elseif a:fname !~ '/'
11798 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11799 else
11800 call add(g:netrw_bookmarklist,a:fname)
11801 endif
11802 call sort(g:netrw_bookmarklist)
11803 endif
11804
11805" call Dret("s:MakeBookmark")
11806endfun
11807
11808" ---------------------------------------------------------------------
11809" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11810fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011811" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011812 " get bookmarks from .netrwbook file
11813 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011814 if filereadable(s:NetrwFile(savefile))
11815" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011816 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011817" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011818 NetrwKeepj call delete(savefile)
11819 endif
11820" call Dret("s:MergeBookmarks")
11821endfun
11822
11823" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011824" s:NetrwBMShow: {{{2
11825fun! s:NetrwBMShow()
11826" call Dfunc("s:NetrwBMShow()")
11827 redir => bmshowraw
11828 menu
11829 redir END
11830 let bmshowlist = split(bmshowraw,'\n')
11831 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011832 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011833 if bmshowfuncs != []
11834 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011835 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011836 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011837 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011839 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011840" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11841endfun
11842
11843" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011844" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011845fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011846 if !exists("w:netrw_liststyle")
11847 let w:netrw_liststyle= g:netrw_liststyle
11848 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011849" 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 +020011850
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011851" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11852
Bram Moolenaaradc21822011-04-01 18:03:16 +020011853 if &ft != "netrw"
11854 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11855 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011856" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011857
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011858 elseif g:netrw_cursor == 8
11859 if w:netrw_liststyle == s:WIDELIST
11860 setl cursorline
11861 setl cursorcolumn
11862 else
11863 setl cursorline
11864 endif
11865 elseif g:netrw_cursor == 7
11866 setl cursorline
11867 elseif g:netrw_cursor == 6
11868 if w:netrw_liststyle == s:WIDELIST
11869 setl cursorline
11870 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011871 elseif g:netrw_cursor == 4
11872 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011873" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011874 setl cursorline
11875 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011876
11877 elseif g:netrw_cursor == 3
11878 " thin-long-tree: cursorline, user's cursorcolumn
11879 " wide : cursorline, cursorcolumn
11880 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011881" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011882 setl cursorline
11883 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011884 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011885" 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 +020011886 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011887 endif
11888
11889 elseif g:netrw_cursor == 2
11890 " thin-long-tree: cursorline, user's cursorcolumn
11891 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011892" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011893 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011894
11895 elseif g:netrw_cursor == 1
11896 " thin-long-tree: user's cursorline, user's cursorcolumn
11897 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011898 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011899" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011900 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011901 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011902" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011903 endif
11904
11905 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011906 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011907" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011908 let &l:cursorline = s:netrw_usercul
11909 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011910 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011911
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011912" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011913" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011914endfun
11915
11916" ---------------------------------------------------------------------
11917" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11918fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011919" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011920 if exists("s:netrw_usercul")
11921 let &l:cursorline = s:netrw_usercul
11922 endif
11923 if exists("s:netrw_usercuc")
11924 let &l:cursorcolumn = s:netrw_usercuc
11925 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011926" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011927" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11928endfun
11929
11930" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011931" s:NetrwDelete: Deletes a file. {{{2
11932" Uses Steve Hall's idea to insure that Windows paths stay
11933" acceptable. No effect on Unix paths.
11934" Examples of use: let result= s:NetrwDelete(path)
11935fun! s:NetrwDelete(path)
11936" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11937
Bram Moolenaar5c736222010-01-06 20:54:52 +010011938 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011939 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
11940 if exists("+shellslash")
11941 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011942 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011943 let result = delete(path)
11944 let &shellslash = sskeep
11945 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011946" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011947 let result= delete(path)
11948 endif
11949 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011950" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011951 let result= delete(path)
11952 endif
11953 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011954 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011955 endif
11956
11957" call Dret("s:NetrwDelete ".result)
11958 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011959endfun
11960
11961" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011962" s:NetrwBufRemover: removes a buffer that: {{{2s
11963" has buffer-id > 1
11964" is unlisted
11965" is unnamed
11966" does not appear in any window
11967fun! s:NetrwBufRemover(bufid)
11968" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11969" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11970" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11971" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11972" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11973
11974 if a:bufid > 1 && !buflisted(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
11975" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
11976 exe "bd! ".a:bufid
11977 endif
11978
11979" call Dret("s:NetrwBufRemover")
11980endfun
11981
11982" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011983" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011984fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011985" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011986" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011987
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011988 " Clean out the last buffer:
11989 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11990 " If so, delete it.
11991 call s:NetrwBufRemover(bufnr("$"))
11992
Bram Moolenaar446cb832008-06-24 21:56:24 +000011993 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011994" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011995 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11996 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11997 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11998 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11999 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12000 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12001 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12002 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12003 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12004 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12005 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12006 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12007 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12008 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12009 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12010 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12011
Bram Moolenaar85850f32019-07-19 22:05:51 +020012012 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012013" call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012014 " when tree listing uses file TreeListing... a new buffer is made.
12015 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012016 " COMBAK: this causes a problem, see P43
12017" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012018 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012019 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012020 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012021" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012022 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012023
Bram Moolenaar446cb832008-06-24 21:56:24 +000012024 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012025" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012026 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12027 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12028 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12029 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12030 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12031 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12032 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12033 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12034 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12035 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12036 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12037 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12038 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12039 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12040 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12041 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12042
Bram Moolenaar5c736222010-01-06 20:54:52 +010012043 if a:0 > 0
12044 let b:netrw_curdir= a:1
12045 if b:netrw_curdir =~ '/$'
12046 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012047 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012048 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012049 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012050 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12051 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012052 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012053 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012054 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012055 endif
12056 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012057 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12058 let &l:bexpr = "netrw#BalloonHelp()"
12059 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012060
Bram Moolenaar8d043172014-01-23 14:24:41 +010012061" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012062endfun
12063
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012064" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012065" s:NetrwExe: executes a string using "!" {{{2
12066fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012067" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012068 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012069" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012070 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12071 set shell& shellcmdflag& shellxquote& shellxescape&
12072 set shellquote& shellpipe& shellredir& shellslash&
12073 exe a:cmd
12074 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12075 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012076" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012077 exe a:cmd
12078 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012079 if v:shell_error
12080 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12081 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012082" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012083endfun
12084
12085" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012086" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12087fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012088 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012089" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012090 let curbuf = bufnr("%")
12091 let curwin = winnr()
12092 let iwin = 1
12093 while iwin <= winnr("$")
12094 exe iwin."wincmd w"
12095 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12096 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12097 let winvars= w:
12098 break
12099 endif
12100 let iwin= iwin + 1
12101 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012102 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012103 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012104" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012105 for k in keys(winvars)
12106 let w:{k}= winvars[k]
12107 endfor
12108 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012109" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012110 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012111endfun
12112
Bram Moolenaara6878372014-03-22 21:02:50 +010012113" ---------------------------------------------------------------------
12114" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012115" Returns: 0=success
12116" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012117fun! s:NetrwLcd(newdir)
12118" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012119" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012120
Bram Moolenaar85850f32019-07-19 22:05:51 +020012121 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012122 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012123 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012124 catch /^Vim\%((\a\+)\)\=:E344/
12125 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12126 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012127 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012128 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12129 " forward slashes by earlier code; so check for both.
12130 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
12131 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12132 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012133 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012134 endif
12135 endif
12136 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012137 let err472= 1
12138 endtry
12139
12140 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012141 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12142 if exists("w:netrw_prvdir")
12143 let a:newdir= w:netrw_prvdir
12144 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012145 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012146" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012147 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012148" 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 +010012149 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012150 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012151" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12152 return -1
12153 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012154
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012155" call Decho("getcwd <".getcwd().">")
12156" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012157" call Dret("s:NetrwLcd 0")
12158 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012159endfun
12160
Bram Moolenaar9964e462007-05-05 17:54:07 +000012161" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012162" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12163" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12164fun! s:NetrwSaveWordPosn()
12165" call Dfunc("NetrwSaveWordPosn()")
12166 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12167" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12168endfun
12169
12170" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012171" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12172" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12173fun! s:NetrwHumanReadable(sz)
12174" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12175
12176 if g:netrw_sizestyle == 'h'
12177 if a:sz >= 1000000000
12178 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12179 elseif a:sz >= 10000000
12180 let sz = printf("%d",a:sz/1000000)."m"
12181 elseif a:sz >= 1000000
12182 let sz = printf("%.1f",a:sz/1000000.0)."m"
12183 elseif a:sz >= 10000
12184 let sz = printf("%d",a:sz/1000)."k"
12185 elseif a:sz >= 1000
12186 let sz = printf("%.1f",a:sz/1000.0)."k"
12187 else
12188 let sz= a:sz
12189 endif
12190
12191 elseif g:netrw_sizestyle == 'H'
12192 if a:sz >= 1073741824
12193 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12194 elseif a:sz >= 10485760
12195 let sz = printf("%d",a:sz/1048576)."M"
12196 elseif a:sz >= 1048576
12197 let sz = printf("%.1f",a:sz/1048576.0)."M"
12198 elseif a:sz >= 10240
12199 let sz = printf("%d",a:sz/1024)."K"
12200 elseif a:sz >= 1024
12201 let sz = printf("%.1f",a:sz/1024.0)."K"
12202 else
12203 let sz= a:sz
12204 endif
12205
12206 else
12207 let sz= a:sz
12208 endif
12209
12210" call Dret("s:NetrwHumanReadable ".sz)
12211 return sz
12212endfun
12213
12214" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012215" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12216" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12217fun! s:NetrwRestoreWordPosn()
12218" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012219 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012220" call Dret("NetrwRestoreWordPosn")
12221endfun
12222
12223" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012224" s:RestoreBufVars: {{{2
12225fun! s:RestoreBufVars()
12226" call Dfunc("s:RestoreBufVars()")
12227
12228 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12229 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12230 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12231 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12232 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12233 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12234
12235" call Dret("s:RestoreBufVars")
12236endfun
12237
12238" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012239" s:RemotePathAnalysis: {{{2
12240fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012241" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012242
Bram Moolenaara6878372014-03-22 21:02:50 +010012243 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012244 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012245 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012246 let s:user = substitute(a:dirname,dirpat,'\3','')
12247 let s:machine = substitute(a:dirname,dirpat,'\4','')
12248 let s:port = substitute(a:dirname,dirpat,'\5','')
12249 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012250 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012251 if s:machine =~ '@'
12252 let dirpat = '^\(.*\)@\(.\{-}\)$'
12253 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12254 let s:machine = substitute(s:machine,dirpat,'\2','')
12255 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012256
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012257" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12258" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12259" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12260" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12261" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12262" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012263
12264" call Dret("s:RemotePathAnalysis")
12265endfun
12266
12267" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012268" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12269" Returns status
12270" Runs system() on
12271" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012272" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012273fun! s:RemoteSystem(cmd)
12274" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12275 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012276 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 +000012277 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012278 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012279 else
12280 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12281 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12282 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012283 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012284 else
12285 let cmd= cmd.' '
12286 endif
12287 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012288" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012289 let ret= system(cmd)
12290 endif
12291" call Dret("s:RemoteSystem ".ret)
12292 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012293endfun
12294
12295" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012296" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012297fun! s:RestoreWinVars()
12298" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012299 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012300 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12301 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12302 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12303 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12304 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12305 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12306 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12307 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12308 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12309 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12310 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12311 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012312 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12313 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012314 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12315 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12316 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12317" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012318endfun
12319
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012320" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012321" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12322"
12323" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12324" is true) and a command, :Rexplore, which call this function.
12325"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012326" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012327"
12328" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012329fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012330 if exists("s:netrwdrag")
12331 return
12332 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012333" 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 +010012334" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12335" 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 +010012336
12337 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012338 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012339" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012340 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012341 unlet w:netrw_rexfile
12342" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012343 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012344" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012345" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12346" 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 +020012347 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012348
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012349 " ---------------------------
12350 " :Rex issued while in a file
12351 " ---------------------------
12352
Bram Moolenaara6878372014-03-22 21:02:50 +010012353 " record current file so :Rex can return to it from netrw
12354 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012355" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012356
12357 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012358" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012359 return
12360 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012361" 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 +020012362 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012363 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012364 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012365 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012366 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012367 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012368 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012369 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012370 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012371" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12372 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012373" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12374 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012375 if exists("s:rexposn_".bufnr('%'))
12376 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012377 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012378 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012379" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012380 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012381
Bram Moolenaar85850f32019-07-19 22:05:51 +020012382 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12383 if exists("s:explore_match")
12384 exe "2match netrwMarkFile /".s:explore_match."/"
12385 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012386 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012387
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012388" 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 +010012389" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012390endfun
12391
12392" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012393" s:SaveBufVars: save selected b: variables to s: variables {{{2
12394" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012395fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012396" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012397
12398 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12399 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12400 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12401 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12402 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12403 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12404
12405" call Dret("s:SaveBufVars")
12406endfun
12407
12408" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012409" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12410fun! s:SavePosn(posndict)
12411" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12412
Bram Moolenaar85850f32019-07-19 22:05:51 +020012413 if !exists("a:posndict[bufnr('%')]")
12414 let a:posndict[bufnr("%")]= []
12415 endif
12416" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12417 call add(a:posndict[bufnr("%")],winsaveview())
12418" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012419
12420" call Dret("s:SavePosn posndict")
12421 return a:posndict
12422endfun
12423
12424" ---------------------------------------------------------------------
12425" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12426fun! s:RestorePosn(posndict)
12427" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012428 if exists("a:posndict")
12429 if has_key(a:posndict,bufnr("%"))
12430" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12431 let posnlen= len(a:posndict[bufnr("%")])
12432 if posnlen > 0
12433 let posnlen= posnlen - 1
12434" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12435 call winrestview(a:posndict[bufnr("%")][posnlen])
12436 call remove(a:posndict[bufnr("%")],posnlen)
12437" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12438 endif
12439 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012440 endif
12441" call Dret("s:RestorePosn")
12442endfun
12443
12444" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012445" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012446fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012447" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012448 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12449 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12450 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12451 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12452 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12453 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12454 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12455 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12456 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12457 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12458 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12459 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12460 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12461 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12462 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12463 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12464 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12465 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12466" call Dret("s:SaveWinVars")
12467endfun
12468
12469" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012470" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012471" To allow separate windows to have their own activities, such as
12472" Explore **/pattern, several variables have been made window-oriented.
12473" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012474" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012475" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012476fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012477" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012478 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12479 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12480 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12481 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12482 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12483 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12484 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12485 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12486 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12487 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12488" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012489endfun
12490
12491" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012492" s:SetRexDir: set directory for :Rexplore {{{2
12493fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012494" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012495 let w:netrw_rexdir = a:dirname
12496 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012497 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012498" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12499" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012500" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012501" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012502" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012503endfun
12504
12505" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012506" s:ShowLink: used to modify thin and tree listings to show links {{{2
12507fun! s:ShowLink()
12508" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012509" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12510" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012511 if exists("b:netrw_curdir")
12512 norm! $?\a
12513 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12514 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012515" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12516" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12517" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12518 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012519 let dirlen = strlen(b:netrw_curdir)
12520 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012521" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012522 endif
12523 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012524" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12525" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012526 setl noro ma
12527 call setline(".",modline)
12528 setl ro noma nomod
12529 endif
12530" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12531endfun
12532
12533" ---------------------------------------------------------------------
12534" s:ShowStyle: {{{2
12535fun! s:ShowStyle()
12536 if !exists("w:netrw_liststyle")
12537 let liststyle= g:netrw_liststyle
12538 else
12539 let liststyle= w:netrw_liststyle
12540 endif
12541 if liststyle == s:THINLIST
12542 return s:THINLIST.":thin"
12543 elseif liststyle == s:LONGLIST
12544 return s:LONGLIST.":long"
12545 elseif liststyle == s:WIDELIST
12546 return s:WIDELIST.":wide"
12547 elseif liststyle == s:TREELIST
12548 return s:TREELIST.":tree"
12549 else
12550 return 'n/a'
12551 endif
12552endfun
12553
12554" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012555" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12556" Solution from Nicolai Weibull, vim docs (:help strlen()),
12557" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012558fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012559" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12560
12561 if v:version >= 703 && exists("*strdisplaywidth")
12562 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012563
Bram Moolenaar8d043172014-01-23 14:24:41 +010012564 elseif type(g:Align_xstrlen) == 1
12565 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12566 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012567
Bram Moolenaar8d043172014-01-23 14:24:41 +010012568 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012569 " number of codepoints (Latin a + combining circumflex is two codepoints)
12570 " (comment from TM, solution from NW)
12571 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012572
Bram Moolenaar8d043172014-01-23 14:24:41 +010012573 elseif g:Align_xstrlen == 2
12574 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012575 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12576 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012577 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012578
Bram Moolenaar8d043172014-01-23 14:24:41 +010012579 elseif g:Align_xstrlen == 3
12580 " virtual length (counting, for instance, tabs as anything between 1 and
12581 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012582 " preceded by lam, one otherwise, etc.)
12583 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012584 let modkeep= &l:mod
12585 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012586 call setline(line("."),a:x)
12587 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012588 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012589 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012590 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012591
Bram Moolenaar446cb832008-06-24 21:56:24 +000012592 else
12593 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012594 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012595 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012596" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012597 return ret
12598endfun
12599
12600" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012601" s:ShellEscape: shellescape(), or special windows handling {{{2
12602fun! s:ShellEscape(s, ...)
12603 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12604 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12605 endif
12606 let f = a:0 > 0 ? a:1 : 0
12607 return shellescape(a:s, f)
12608endfun
12609
12610" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012611" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012612fun! s:TreeListMove(dir)
12613" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012614 let curline = getline('.')
12615 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12616 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12617 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12618 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12619 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12620 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12621" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12622" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12623" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12624" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12625" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12626 " COMBAK : need to handle when on a directory
12627 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012628 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012629 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012630 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012631 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012632" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012633 elseif a:dir == '[]' && nxtline != ''
12634 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012635" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012636 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12637 if nl != 0
12638 NetrwKeepj norm! k
12639 else
12640 NetrwKeepj norm! G
12641 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012642" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012643 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012644 endif
12645
12646" call Dret("s:TreeListMove")
12647endfun
12648
12649" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012650" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12651" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12652" can't be called except via emenu. But due to locale, that menu line may not be called
12653" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12654fun! s:UpdateBuffersMenu()
12655" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012656 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012657 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012658 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012659 catch /^Vim\%((\a\+)\)\=:E/
12660 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012661 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012662 endtry
12663 endif
12664" call Dret("s:UpdateBuffersMenu")
12665endfun
12666
12667" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012668" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012669" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012670fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012671" call Dfunc("s:UseBufWinVars()")
12672 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012673 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12674 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12675 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12676 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12677 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12678 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12679 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12680 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12681 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 +000012682" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012683endfun
12684
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012685" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012686" s:UserMaps: supports user-defined UserMaps {{{2
12687" * calls a user-supplied funcref(islocal,curdir)
12688" * interprets result
12689" See netrw#UserMaps()
12690fun! s:UserMaps(islocal,funcname)
12691" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12692
12693 if !exists("b:netrw_curdir")
12694 let b:netrw_curdir= getcwd()
12695 endif
12696 let Funcref = function(a:funcname)
12697 let result = Funcref(a:islocal)
12698
12699 if type(result) == 1
12700 " if result from user's funcref is a string...
12701" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12702 if result == "refresh"
12703" call Decho("refreshing display",'~'.expand("<slnum>"))
12704 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12705 elseif result != ""
12706" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12707 exe result
12708 endif
12709
12710 elseif type(result) == 3
12711 " if result from user's funcref is a List...
12712" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12713 for action in result
12714 if action == "refresh"
12715" call Decho("refreshing display",'~'.expand("<slnum>"))
12716 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12717 elseif action != ""
12718" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12719 exe action
12720 endif
12721 endfor
12722 endif
12723
12724" call Dret("s:UserMaps")
12725endfun
12726
Bram Moolenaar85850f32019-07-19 22:05:51 +020012727" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012728" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012729" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012730let &cpo= s:keepcpo
12731unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012732
Bram Moolenaar85850f32019-07-19 22:05:51 +020012733" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012734" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012735" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012736" vim:ts=8 fdm=marker