blob: ac1d2684769a07a5d39ba851cfa81161f0543373 [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 Moolenaar5ef1c6a2019-11-10 22:09:11 +01003" Date: Nov 06, 2019
4" Version: 166
Bram Moolenaarff034192013-04-24 18:51:19 +02005" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-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 Moolenaaraa3b15d2016-04-21 08:53:19 +020016"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000017"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000018" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" (James 1:22 RSV)
20" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000021" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000022if &cp || exists("g:loaded_netrw")
23 finish
24endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020025
26" Check that vim has patches that netrw requires.
27" Patches needed for v7.4: 1557, and 213.
28" (netrw will benefit from vim's having patch#656, too)
29let s:needspatches=[1557,213]
30if exists("s:needspatches")
31 for ptch in s:needspatches
32 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
33 if !exists("s:needpatch{ptch}")
34 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
35 endif
36 let s:needpatch{ptch}= 1
37 finish
38 endif
39 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020040endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020041
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010042let g:loaded_netrw = "v166"
Bram Moolenaar9964e462007-05-05 17:54:07 +000043if !exists("s:NOTE")
44 let s:NOTE = 0
45 let s:WARNING = 1
46 let s:ERROR = 2
47endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000048
Bram Moolenaar1afcace2005-11-25 19:54:28 +000049let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010050setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020051"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010052"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010053"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000055" ======================
56" Netrw Variables: {{{1
57" ======================
58
Bram Moolenaar071d4272004-06-13 20:20:40 +000059" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020060" netrw#ErrorMsg: {{{2
61" 0=note = s:NOTE
62" 1=warning = s:WARNING
63" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010064" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
65" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
66" (this function can optionally take a list of messages)
Bram Moolenaar85850f32019-07-19 22:05:51 +020067" Mar 21, 2017 : max errnum currently is 105
Bram Moolenaar5b435d62012-04-05 17:33:26 +020068fun! netrw#ErrorMsg(level,msg,errnum)
69" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
70
71 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020072" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020073 return
74 endif
75
76 if a:level == 1
77 let level= "**warning** (netrw) "
78 elseif a:level == 2
79 let level= "**error** (netrw) "
80 else
81 let level= "**note** (netrw) "
82 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010083" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020084
85 if g:netrw_use_errorwindow
86 " (default) netrw creates a one-line window to show error/warning
87 " messages (reliably displayed)
88
Bram Moolenaare0fa3742016-02-20 15:47:01 +010089 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +020090 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010091" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020092
93 " getting messages out reliably is just plain difficult!
94 " This attempt splits the current window, creating a one line window.
95 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010096" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020097 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010098" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020099 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100100 if type(a:msg) == 3
101 for msg in a:msg
102 NetrwKeepj call setline(line("$")+1,level.msg)
103 endfor
104 else
105 NetrwKeepj call setline(line("$")+1,level.a:msg)
106 endif
107 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200108 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100109" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200110 bo 1split
111 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200112 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200113 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100114 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100115" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200116 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100117 if type(a:msg) == 3
118 for msg in a:msg
119 NetrwKeepj call setline(line("$")+1,level.msg)
120 endfor
121 else
122 NetrwKeepj call setline(line("$"),level.a:msg)
123 endif
124 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200125 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100126" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200127 if &fo !~ '[ta]'
128 syn clear
129 syn match netrwMesgNote "^\*\*note\*\*"
130 syn match netrwMesgWarning "^\*\*warning\*\*"
131 syn match netrwMesgError "^\*\*error\*\*"
132 hi link netrwMesgWarning WarningMsg
133 hi link netrwMesgError Error
134 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100135" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200136 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137
138 else
139 " (optional) netrw will show messages using echomsg. Even if the
140 " message doesn't appear, at least it'll be recallable via :messages
141" redraw!
142 if a:level == s:WARNING
143 echohl WarningMsg
144 elseif a:level == s:ERROR
145 echohl Error
146 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100147
148 if type(a:msg) == 3
149 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100150 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100151 endfor
152 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100153 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100154 endif
155
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100156" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200157 echohl None
158 endif
159
160" call Dret("netrw#ErrorMsg")
161endfun
162
163" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100164" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100165" Loosely, varname = value.
166fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100167" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100168 if !exists(a:varname)
169 if type(a:value) == 0
170 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200171 elseif type(a:value) == 1 && a:value =~ '^[{[]'
172 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100173 elseif type(a:value) == 1
174 exe "let ".a:varname."="."'".a:value."'"
175 else
176 exe "let ".a:varname."=".a:value
177 endif
178 endif
179endfun
180
181" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000182" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200183call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000184if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100185 call s:NetrwInit("s:THINLIST",0)
186 call s:NetrwInit("s:LONGLIST",1)
187 call s:NetrwInit("s:WIDELIST",2)
188 call s:NetrwInit("s:TREELIST",3)
189 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000190endif
191
192" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200193" Default option values: {{{2
194let g:netrw_localcopycmdopt = ""
195let g:netrw_localcopydircmdopt = ""
196let g:netrw_localmkdiropt = ""
197let g:netrw_localmovecmdopt = ""
198let g:netrw_localrmdiropt = ""
199
200" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000201" Default values for netrw's global protocol variables {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +0200202call s:NetrwInit("g:netrw_use_errorwindow",1)
203
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000204if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100205 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000206 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100207 elseif executable("curl")
208 let g:netrw_dav_cmd = "curl"
209 else
210 let g:netrw_dav_cmd = ""
211 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000212endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000213if !exists("g:netrw_fetch_cmd")
214 if executable("fetch")
215 let g:netrw_fetch_cmd = "fetch -o"
216 else
217 let g:netrw_fetch_cmd = ""
218 endif
219endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100220if !exists("g:netrw_file_cmd")
221 if executable("elinks")
222 call s:NetrwInit("g:netrw_file_cmd","elinks")
223 elseif executable("links")
224 call s:NetrwInit("g:netrw_file_cmd","links")
225 endif
226endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000227if !exists("g:netrw_ftp_cmd")
228 let g:netrw_ftp_cmd = "ftp"
229endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200230let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200231if !exists("g:netrw_ftp_options")
232 let g:netrw_ftp_options= "-i -n"
233endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000234if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100235 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100236 let g:netrw_http_cmd = "wget"
237 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100238 elseif executable("curl")
239 let g:netrw_http_cmd = "curl"
240 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200241 elseif executable("elinks")
242 let g:netrw_http_cmd = "elinks"
243 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000244 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100245 let g:netrw_http_cmd = "fetch"
246 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200247 elseif executable("links")
248 let g:netrw_http_cmd = "links"
249 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000250 else
251 let g:netrw_http_cmd = ""
252 endif
253endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100254call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100255call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100256call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
257call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200258call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200259if !exists("g:netrw_scp_cmd")
260 if executable("scp")
261 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
262 elseif executable("pscp")
263 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable('c:\private.ppk')
264 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -i c:\private.ppk')
265 else
266 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
267 endif
268 else
269 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
270 endif
271endif
272
Bram Moolenaar5c736222010-01-06 20:54:52 +0100273call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
274call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000275
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000276if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000277 \ && exists("g:netrw_use_nt_rcp")
278 \ && g:netrw_use_nt_rcp
279 \ && executable( $SystemRoot .'/system32/rcp.exe')
280 let s:netrw_has_nt_rcp = 1
281 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000282else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000283 let s:netrw_has_nt_rcp = 0
284 let s:netrw_rcpmode = ''
285endif
286
287" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000288" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000289" Cygwin Detection ------- {{{3
290if !exists("g:netrw_cygwin")
291 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100292 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000293 let g:netrw_cygwin= 1
294 else
295 let g:netrw_cygwin= 0
296 endif
297 else
298 let g:netrw_cygwin= 0
299 endif
300endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000301" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100302call s:NetrwInit("g:netrw_alto" , &sb)
303call s:NetrwInit("g:netrw_altv" , &spr)
304call s:NetrwInit("g:netrw_banner" , 1)
305call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200306call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100307call s:NetrwInit("g:netrw_chgwin" , -1)
308call s:NetrwInit("g:netrw_compress" , "gzip")
309call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200310if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
311 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
312 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000313endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200314call s:NetrwInit("g:netrw_cursor" , 2)
315let s:netrw_usercul = &cursorline
316let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar8d043172014-01-23 14:24:41 +0100317call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000318" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200319call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200320call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200321call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100322call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200323call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100324call s:NetrwInit("g:netrw_fastbrowse" , 1)
325call 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 +0000326if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000327 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
328 let g:netrw_ftp_list_cmd = "ls -lF"
329 let g:netrw_ftp_timelist_cmd = "ls -tlF"
330 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000331 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000332 let g:netrw_ftp_list_cmd = "dir"
333 let g:netrw_ftp_timelist_cmd = "dir"
334 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000335 endif
336endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100337call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000338" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100339call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000340if !exists("g:netrw_ignorenetrc")
341 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
342 let g:netrw_ignorenetrc= 1
343 else
344 let g:netrw_ignorenetrc= 0
345 endif
346endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000348if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000349 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000350 if (has("win32") || has("win95") || has("win64") || has("win16")) && filereadable("c:\\private.ppk")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200351 " provide a pscp-based listing command
Bram Moolenaar9964e462007-05-05 17:54:07 +0000352 let g:netrw_scp_cmd ="pscp -i C:\\private.ppk"
353 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100354 if exists("g:netrw_list_cmd_options")
355 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
356 else
357 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
358 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000359 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200360 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100361 if exists("g:netrw_list_cmd_options")
362 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
363 else
364 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
365 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000366 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100367" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000368 let g:netrw_list_cmd= ""
369 endif
370endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100371call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000372" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200373if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200374 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200375 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
376endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100377if !exists("g:netrw_localcmdshell")
378 let g:netrw_localcmdshell= ""
379endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000380if !exists("g:netrw_localcopycmd")
381 if has("win32") || has("win95") || has("win64") || has("win16")
382 if g:netrw_cygwin
383 let g:netrw_localcopycmd= "cp"
384 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200385 let g:netrw_localcopycmd = expand("$COMSPEC")
386 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000387 endif
388 elseif has("unix") || has("macunix")
389 let g:netrw_localcopycmd= "cp"
390 else
391 let g:netrw_localcopycmd= ""
392 endif
393endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100394if !exists("g:netrw_localcopydircmd")
395 if has("win32") || has("win95") || has("win64") || has("win16")
396 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200397 let g:netrw_localcopydircmd = "cp"
398 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100399 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200400 let g:netrw_localcopydircmd = expand("$COMSPEC")
401 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100402 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200403 elseif has("unix")
404 let g:netrw_localcopydircmd = "cp"
405 let g:netrw_localcopydircmdopt= " -R"
406 elseif has("macunix")
407 let g:netrw_localcopydircmd = "cp"
408 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100409 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200410 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100411 endif
412endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200413if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100414 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200415 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
416endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200417if has("win32") || has("win95") || has("win64") || has("win16")
418 if g:netrw_cygwin
419 call s:NetrwInit("g:netrw_localmkdir","mkdir")
420 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200421 let g:netrw_localmkdir = expand("$COMSPEC")
422 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200423 endif
424else
425 call s:NetrwInit("g:netrw_localmkdir","mkdir")
426endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200427call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200428if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200429 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200430 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
431endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000432if !exists("g:netrw_localmovecmd")
433 if has("win32") || has("win95") || has("win64") || has("win16")
434 if g:netrw_cygwin
435 let g:netrw_localmovecmd= "mv"
436 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200437 let g:netrw_localmovecmd = expand("$COMSPEC")
438 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000439 endif
440 elseif has("unix") || has("macunix")
441 let g:netrw_localmovecmd= "mv"
442 else
443 let g:netrw_localmovecmd= ""
444 endif
445endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200446if v:version < 704 || (v:version == 704 && !has("patch1107"))
447 " 1109 provides for delete(tmpdir,"d") which is what will be used
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100448 if exists("g:netrw_local_rmdir")
449 let g:netrw_localrmdir= g:netrw_local_rmdir
450 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_rmdir is deprecated in favor of g:netrw_localrmdir",86)
451 endif
452 if has("win32") || has("win95") || has("win64") || has("win16")
453 if g:netrw_cygwin
454 call s:NetrwInit("g:netrw_localrmdir","rmdir")
455 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200456 let g:netrw_localrmdir = expand("$COMSPEC")
457 let g:netrw_localrmdiropt= " /c rmdir"
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100458 endif
459 else
460 call s:NetrwInit("g:netrw_localrmdir","rmdir")
461 endif
Bram Moolenaar13600302014-05-22 18:26:40 +0200462endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100463call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
464" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000465if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000466 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000467endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000468if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000469 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
470endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000471" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100472call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
473call s:NetrwInit("g:netrw_maxfilenamelen", 32)
474call s:NetrwInit("g:netrw_menu" , 1)
475call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200476call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100477call s:NetrwInit("g:netrw_retmap" , 0)
478if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
479 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
480elseif has("win32") || has("win95") || has("win64") || has("win16")
481 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
482else
483 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000484endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100485call s:NetrwInit("g:netrw_preview" , 0)
486call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100487call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100488call s:NetrwInit("g:netrw_sshport" , "-p")
489call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
490call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
491call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100492call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
493" Default values - q-s ---------- {{{3
494call s:NetrwInit("g:netrw_quickhelp",0)
495let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100496 \ "(create new) %:file d:directory",
497 \ "(windows split&open) o:horz v:vert p:preview",
498 \ "i:style qf:file info O:obtain r:reverse",
499 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
500 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
501 \ "(history) qb:list u:go up U:go down",
502 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100503" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
504call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100505if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
506 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
507else
508 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
509endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
511call s:NetrwInit("g:netrw_sort_options" , "")
512call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000513if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100514 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200515 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100516 else
517 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000518 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000519endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520call s:NetrwInit("g:netrw_special_syntax" , 0)
521call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200522call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100523call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100524call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000525" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100526call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200527if !exists("g:netrw_xstrlen")
528 if exists("g:Align_xstrlen")
529 let g:netrw_xstrlen= g:Align_xstrlen
530 elseif exists("g:drawit_xstrlen")
531 let g:netrw_xstrlen= g:drawit_xstrlen
532 elseif &enc == "latin1" || !has("multi_byte")
533 let g:netrw_xstrlen= 0
534 else
535 let g:netrw_xstrlen= 1
536 endif
537endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100538call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100539call s:NetrwInit("g:netrw_win95ftp",1)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200540call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100541call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200542if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000543" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000544" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200546if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaarff034192013-04-24 18:51:19 +0200547 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200548else
Bram Moolenaarff034192013-04-24 18:51:19 +0200549 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200550endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200551call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100552call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
553call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100554if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100555 let s:treedepthstring= "│ "
556else
557 let s:treedepthstring= "| "
558endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200559call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000560
561" BufEnter event ignored by decho when following variable is true
562" Has a side effect that doau BufReadPost doesn't work, so
563" files read by network transfer aren't appropriately highlighted.
564"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565
Bram Moolenaaradc21822011-04-01 18:03:16 +0200566" ======================
567" Netrw Initialization: {{{1
568" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200569if 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 +0100570" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100571 let &l:bexpr = "netrw#BalloonHelp()"
572 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100573 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
574 au VimEnter * let s:initbeval= &beval
575"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100576" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
577" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
578" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
579" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
580" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
581" 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 +0200582endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200583au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200584
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200585if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100586 com! -nargs=* NetrwKeepj keepj <args>
587else
588 let g:netrw_keepj= ""
589 com! -nargs=* NetrwKeepj <args>
590endif
591
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000592" ==============================
593" Netrw Utility Functions: {{{1
594" ==============================
595
Bram Moolenaaradc21822011-04-01 18:03:16 +0200596" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100597" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100598if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100599" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100600 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100601 if &ft != "netrw"
602 return ""
603 endif
604 if !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
605 let mesg= ""
606 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
607 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
608 elseif getline(v:beval_lnum) =~ '^"\s*/'
609 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
610 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100611 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100612 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
613 let mesg = "S: edit sorting sequence"
614 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
615 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
616 elseif v:beval_text == "Quick" || v:beval_text == "Help"
617 let mesg = "Help: press <F1>"
618 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
619 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
620 else
621 let mesg= ""
622 endif
623 return mesg
624 endfun
625"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100626" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
627" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
628" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
629" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
630" 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 +0200631endif
632
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200634" netrw#Explore: launch the local browser in the directory of the current file {{{2
635" indx: == -1: Nexplore
636" == -2: Pexplore
637" == +: this is overloaded:
638" * If Nexplore/Pexplore is in use, then this refers to the
639" indx'th item in the w:netrw_explore_list[] of items which
640" matched the */pattern **/pattern *//pattern **//pattern
641" * If Hexplore or Vexplore, then this will override
642" g:netrw_winsize to specify the qty of rows or columns the
643" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100644" 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 +0200645" dosplit==1: the window will be split before running the local browser
646" style == 0: Explore style == 1: Explore!
647" == 2: Hexplore style == 3: Hexplore!
648" == 4: Vexplore style == 5: Vexplore!
649" == 6: Texplore
650fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100651" 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 +0100652" 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 +0200653 if !exists("b:netrw_curdir")
654 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100655" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200656 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100657
658 " record current file for Rexplore's benefit
659 if &ft != "netrw"
660 let w:netrw_rexfile= expand("%:p")
661 endif
662
663 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200664 let curdir = simplify(b:netrw_curdir)
665 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200666 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
667 let curdir= substitute(curdir,'\','/','g')
668 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100669" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100670
671 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
672 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
673 " try Explore again.
674 if a:0 > 0
675" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100676 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
677 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
678 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
679 \ '~'.expand("<slnum>"))
680 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
681" call Decho("re-trying Explore with <".substitute(a:1,'\\\(\s\)','\1','g').">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100682 call netrw#Explore(a:indx,a:dosplit,a:style,substitute(a:1,'\\\(\s\)','\1','g'))
683" call Dret("netrw#Explore : returning from retry")
684 return
685" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100686" call Decho("retry not needed",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100687 endif
688 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200689
690 " save registers
Bram Moolenaara6878372014-03-22 21:02:50 +0100691 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100692" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100693 sil! let keepregstar = @*
694 sil! let keepregplus = @+
695 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200696 sil! let keepregslash= @/
697
Bram Moolenaar8d043172014-01-23 14:24:41 +0100698 " if dosplit
699 " -or- file has been modified AND file not hidden when abandoned
700 " -or- Texplore used
701 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100702" 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 +0200703 call s:SaveWinVars()
704 let winsz= g:netrw_winsize
705 if a:indx > 0
706 let winsz= a:indx
707 endif
708
709 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100710" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200711 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200712 if winsz == 0|let winsz= ""|endif
713 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100714" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200715
716 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100717" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200718 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200719 if winsz == 0|let winsz= ""|endif
720 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100721" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200722
723 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100724" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200725 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200726 if winsz == 0|let winsz= ""|endif
727 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100728" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200729
730 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100731" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200732 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200733 if winsz == 0|let winsz= ""|endif
734 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100735" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200736
737 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100738" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200739 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200740 if winsz == 0|let winsz= ""|endif
741 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100742" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200743
744 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100745" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200746 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200747 if winsz == 0|let winsz= ""|endif
748 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100749" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200750
751 elseif a:style == 6 " Texplore
752 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100753" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200754 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100755" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200756 call s:RestoreBufVars()
757 endif
758 call s:RestoreWinVars()
759" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100760" 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 +0200761 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100762 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200763
764 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100765" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200766 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100767" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200768 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100769" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100771" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200772 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
773 if dirname !~ '/$'
774 let dirname= dirname."/"
775 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200781 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100782" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200783 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= a:1
788 endif
789 else
790 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 call s:NetrwClearExplore()
793" call Dret("netrw#Explore : cleared list")
794 return
795 endif
796
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 if dirname =~ '\.\./\=$'
799 let dirname= simplify(fnamemodify(dirname,':p:h'))
800 elseif dirname =~ '\.\.' || dirname == '.'
801 let dirname= simplify(fnamemodify(dirname,':p'))
802 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804
805 if dirname =~ '^\*//'
806 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100807" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
809 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100810" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
812
813 elseif dirname =~ '^\*\*//'
814 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100815" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200816 let pattern= substitute(dirname,'^\*\*//','','')
817 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100818" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200819
820 elseif dirname =~ '/\*\*/'
821 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
824 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
825 let b:netrw_curdir = prefixdir
826 else
827 let b:netrw_curdir= getcwd().'/'.prefixdir
828 endif
829 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
830 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
832" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200833
834 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200835 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200836 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100837" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838
839 elseif dirname=~ '^\*\*/'
840 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
841 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100842" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200843
844 else
845 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100846" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200847 endif
848
849 if starpat == 0 && a:indx >= 0
850 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100851" 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 +0200852 if dirname == ""
853 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100854" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200856 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200857 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200858 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200859 if dirname == ""
860 let dirname= getcwd()
861 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100862 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100863 " depending on whether backslashes have been converted to forward slashes by earlier code).
864 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200865 let dirname= b:netrw_curdir."/".dirname
866 endif
867 elseif dirname !~ '^/'
868 let dirname= b:netrw_curdir."/".dirname
869 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200871 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100872" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
873" 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 +0200874 endif
875 if exists("w:netrw_bannercnt")
876 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
877 " If one wants to return the same place in the netrw window, use :Rex instead.
878 exe w:netrw_bannercnt
879 endif
880
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100881" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200882 " ---------------------------------------------------------------------
883 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
884" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100885" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200886" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100887" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200888" endif
889 " ---------------------------------------------------------------------
890
891 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
892 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
893 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
894 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
895 elseif a:indx <= 0
896 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100897" 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 +0200898 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100899" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200900 let s:didstarstar= 1
901 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
902 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
903 endif
904
905 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100906" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200907 if !exists("w:netrw_explore_indx")
908 let w:netrw_explore_indx= 0
909 endif
910
911 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100912" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200913
914 if indx == -1
915 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200917 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100918 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaara6878372014-03-22 21:02:50 +0100919 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100920" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100921 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +0200922 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +0100923 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200924 sil! let @/ = keepregslash
925" call Dret("netrw#Explore")
926 return
927 endif
928 let indx= w:netrw_explore_indx
929 if indx < 0 | let indx= 0 | endif
930 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
931 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100932" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
934 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100935" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 endwhile
937 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100938" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200939
940 elseif indx == -2
941 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100942" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200943 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100944 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaara6878372014-03-22 21:02:50 +0100945 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100946" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100947 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +0200948 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +0100949 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200950 sil! let @/ = keepregslash
951" call Dret("netrw#Explore")
952 return
953 endif
954 let indx= w:netrw_explore_indx
955 if indx < 0 | let indx= 0 | endif
956 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
957 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100958" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 while indx >= 0 && curfile == w:netrw_explore_list[indx]
960 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100961" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200962 endwhile
963 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100964" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200965
966 else
967 " Explore -- initialize
968 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100969" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100970 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200971 let w:netrw_explore_indx= 0
972 if !exists("b:netrw_curdir")
973 let b:netrw_curdir= getcwd()
974 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100975" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200976
977 " switch on starpat to build the w:netrw_explore_list of files
978 if starpat == 1
979 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
981" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200982 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100983 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200984 catch /^Vim\%((\a\+)\)\=:E480/
985 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
986" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
987 return
988 endtry
989 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
990 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
991
992 elseif starpat == 2
993 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100994" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
995" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200996 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100997 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 catch /^Vim\%((\a\+)\)\=:E480/
999 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1000 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001001 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001002" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001003 sil! let @* = keepregstar
1004 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01001005 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001006 sil! let @/ = keepregslash
1007" call Dret("netrw#Explore : no files matched pattern")
1008 return
1009 endtry
1010 let s:netrw_curdir = b:netrw_curdir
1011 let w:netrw_explore_list = getqflist()
1012 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1013 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1014
1015 elseif starpat == 3
1016 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001017" 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 +02001018 let filepat= substitute(dirname,'^\*/','','')
1019 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001020" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1021" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001022 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1023 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1024
1025 elseif starpat == 4
1026 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001027" 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 +02001028 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1029 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1030 endif " switch on starpat to build w:netrw_explore_list
1031
1032 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001033" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1034" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001035
1036 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001037 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaara6878372014-03-22 21:02:50 +01001038 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001039" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001040 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001041 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01001042 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001043 sil! let @/ = keepregslash
1044" call Dret("netrw#Explore : no files matched")
1045 return
1046 endif
1047 endif " if indx ... endif
1048
1049 " NetrwStatusLine support - for exploring support
1050 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001051" 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 +02001052
1053 " wrap the indx around, but issue a note
1054 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001055" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001056 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1057 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001058 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001059 endif
1060
1061 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001062" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001063 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001064" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001065
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001066" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001067 call netrw#LocalBrowseCheck(newdir)
1068 if !exists("w:netrw_liststyle")
1069 let w:netrw_liststyle= g:netrw_liststyle
1070 endif
1071 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001072 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001073 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001074 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 endif
1076 let w:netrw_explore_mtchcnt = indx + 1
1077 let w:netrw_explore_bufnr = bufnr("%")
1078 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001079 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001080" 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 +02001081
1082 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001085 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 +02001086 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001087 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001088" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001089 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001090 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01001091 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001092 sil! let @/ = keepregslash
1093" call Dret("netrw#Explore : missing +path_extra")
1094 return
1095 endif
1096
1097 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001098" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001099 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1100 sil! unlet w:netrw_treedict
1101 sil! unlet w:netrw_treetop
1102 endif
1103 let newdir= dirname
1104 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001105 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001106 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001107 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 endif
1109 endif
1110
1111 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001112" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1113" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001114 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001115" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001116 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001117 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001118" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001119 let s:explore_prvdir = b:netrw_curdir
1120 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001121 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 if b:netrw_curdir !~ '/$'
1123 let dirlen= dirlen + 1
1124 endif
1125 let prvfname= ""
1126 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001127" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001128 if fname =~ '^'.b:netrw_curdir
1129 if s:explore_match == ""
1130 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1131 else
1132 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1133 endif
1134 elseif fname !~ '^/' && fname != prvfname
1135 if s:explore_match == ""
1136 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1137 else
1138 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1139 endif
1140 endif
1141 let prvfname= fname
1142 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001143" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001144 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1145 exe "2match netrwMarkFile /".s:explore_match."/"
1146 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001147 endif
1148 echo "<s-up>==Pexplore <s-down>==Nexplore"
1149 else
1150 2match none
1151 if exists("s:explore_match") | unlet s:explore_match | endif
1152 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1153 echo " "
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001154" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001155 endif
1156
Bram Moolenaara6878372014-03-22 21:02:50 +01001157 " since Explore may be used to initialize netrw's browser,
1158 " there's no danger of a late FocusGained event on initialization.
1159 " Consequently, set s:netrw_events to 2.
1160 let s:netrw_events= 2
1161 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001162" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001163 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001164 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01001165 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001166 sil! let @/ = keepregslash
1167" call Dret("netrw#Explore : @/<".@/.">")
1168endfun
1169
1170" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001171" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001172fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001173" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001174 let curwin= winnr()
1175
Bram Moolenaara6878372014-03-22 21:02:50 +01001176 if a:0 > 0 && a:1 != ""
1177 " if a netrw window is already on the left-side of the tab
1178 " and a directory has been specified, explore with that
1179 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001180" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001181 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001182" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001183 exe "1wincmd w"
1184 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001185" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001186 exe "Explore ".fnameescape(a1)
1187 exe curwin."wincmd w"
1188 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001189" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001190 unlet t:netrw_lexposn
1191 endif
1192" call Dret("netrw#Lexplore")
1193 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001194 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 exe curwin."wincmd w"
1196 else
1197 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001198" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001199 endif
1200
Bram Moolenaar8d043172014-01-23 14:24:41 +01001201 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001202 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001203 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001204" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001205 else
1206 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001207" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001209" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210
1211 if lexwinnr > 0
1212 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001213" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214 exe lexwinnr."wincmd w"
1215 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001216 let t:netrw_lexposn = winsaveview()
1217" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001218" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001219 close
1220 if lexwinnr < curwin
1221 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001222 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223 if lexwinnr != curwin
1224 exe curwin."wincmd w"
1225 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001226 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001227" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001228
1229 else
1230 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001231" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001232 exe "1wincmd w"
1233 let keep_altv = g:netrw_altv
1234 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001235 if a:count != 0
1236 let netrw_winsize = g:netrw_winsize
1237 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001238 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001240" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001241 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 +02001242" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001243 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001244" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001245 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001246 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001247 elseif curfile =~ '^\a\{3,}://'
1248" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001249 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001250 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001251" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001252 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001253 endif
1254 if a:count != 0
1255 let g:netrw_winsize = netrw_winsize
1256 endif
1257 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001258 let g:netrw_altv = keep_altv
1259 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001260" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1261" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001263" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001264" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1265 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 unlet t:netrw_lexposn
1267 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001268 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001269
1270 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001271 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272 if a:rightside
1273 let g:netrw_chgwin= 1
1274 else
1275 let g:netrw_chgwin= 2
1276 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001277" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001278 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001279
Bram Moolenaar8d043172014-01-23 14:24:41 +01001280" call Dret("netrw#Lexplore")
1281endfun
1282
1283" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001284" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001285" supports :NetrwClean -- remove netrw from first directory on runtimepath
1286" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001287fun! netrw#Clean(sys)
1288" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001289
1290 if a:sys
1291 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1292 else
1293 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1294 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001295" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001296 let diddel= 0
1297 let diddir= ""
1298
1299 if choice == 1
1300 for dir in split(&rtp,',')
1301 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001302" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001303 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1304 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1305 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1306 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1307 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1308 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 +00001309 let diddir= dir
1310 let diddel= diddel + 1
1311 if !a:sys|break|endif
1312 endif
1313 endfor
1314 endif
1315
1316 echohl WarningMsg
1317 if diddel == 0
1318 echomsg "netrw is either not installed or not removable"
1319 elseif diddel == 1
1320 echomsg "removed one copy of netrw from <".diddir.">"
1321 else
1322 echomsg "removed ".diddel." copies of netrw"
1323 endif
1324 echohl None
1325
Bram Moolenaara6878372014-03-22 21:02:50 +01001326" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001327endfun
1328
Bram Moolenaar5c736222010-01-06 20:54:52 +01001329" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001330" netrw#MakeTgt: make a target out of the directory name provided {{{2
1331fun! netrw#MakeTgt(dname)
1332" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1333 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001334 let svpos = winsaveview()
1335" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001336 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1337" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001338 if s:netrwmftgt_islocal
1339 let netrwmftgt= simplify(a:dname)
1340 else
1341 let netrwmftgt= a:dname
1342 endif
1343 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1344 " re-selected target, so just clear it
1345 unlet s:netrwmftgt s:netrwmftgt_islocal
1346 else
1347 let s:netrwmftgt= netrwmftgt
1348 endif
1349 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001350 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001351 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001352" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1353 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001354" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001355endfun
1356
Bram Moolenaara6878372014-03-22 21:02:50 +01001357" ---------------------------------------------------------------------
1358" netrw#Obtain: {{{2
1359" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001360" islocal=0 obtain from remote source
1361" =1 obtain from local source
1362" fname : a filename or a list of filenames
1363" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001364fun! netrw#Obtain(islocal,fname,...)
1365" 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 +02001366 " NetrwStatusLine support - for obtaining support
1367
1368 if type(a:fname) == 1
1369 let fnamelist= [ a:fname ]
1370 elseif type(a:fname) == 3
1371 let fnamelist= a:fname
1372 else
1373 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 +01001374" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001375 return
1376 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001377" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001378 if a:0 > 0
1379 let tgtdir= a:1
1380 else
1381 let tgtdir= getcwd()
1382 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001383" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001384
1385 if exists("b:netrw_islocal") && b:netrw_islocal
1386 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001387" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001388 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1389 let topath= s:ComposePath(tgtdir,"")
1390 if (has("win32") || has("win95") || has("win64") || has("win16"))
1391 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001392" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001393 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001394" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001395 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001396 if v:shell_error != 0
1397 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 +01001398" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001399 return
1400 endif
1401 endfor
1402 else
1403 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001404" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1405 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1406" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001407 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 if v:shell_error != 0
1409 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 +01001410" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 return
1412 endif
1413 endif
1414 elseif !exists("b:netrw_curdir")
1415 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1416 else
1417 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1418 endif
1419
1420 else
1421 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001422" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001423 if type(a:fname) == 1
1424 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1425 endif
1426 call s:NetrwMethod(b:netrw_curdir)
1427
1428 if b:netrw_method == 4
1429 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001430" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001431 if exists("g:netrw_port") && g:netrw_port != ""
1432 let useport= " ".g:netrw_scpport." ".g:netrw_port
1433 else
1434 let useport= ""
1435 endif
1436 if b:netrw_fname =~ '/'
1437 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1438 else
1439 let path= ""
1440 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001441 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001442 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 +02001443
1444 elseif b:netrw_method == 2
1445 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001446" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001447 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001448 let tmpbufnr= bufnr("%")
1449 setl ff=unix
1450 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001451 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001452" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001453 endif
1454
1455 if exists("b:netrw_fname") && b:netrw_fname != ""
1456 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001457" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001458 endif
1459
1460 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001461 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001463 endif
1464 for fname in fnamelist
1465 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001466" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001467 endfor
1468 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001469 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 +02001470 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001472 endif
1473 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1474 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1475 let debugkeep= &debug
1476 setl debug=msg
1477 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1478 let &debug= debugkeep
1479 endif
1480
1481 elseif b:netrw_method == 3
1482 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001484 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001485 let tmpbufnr= bufnr("%")
1486 setl ff=unix
1487
1488 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001489 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001491 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001492 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001493" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001494 endif
1495
1496 if exists("g:netrw_uid") && g:netrw_uid != ""
1497 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001498 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001499" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001500 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001501 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001502 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001503" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001504 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001505 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001506" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001507 endif
1508 endif
1509
1510 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 endif
1514
1515 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001516 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001517" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001518 endif
1519
1520 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
1524
1525 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001526 NetrwKeepj put =g:netrw_ftpextracmd
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 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533
1534 " perform ftp:
1535 " -i : turns off interactive prompting from ftp
1536 " -n unix : DON'T use <.netrc>, even though it exists
1537 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001538 NetrwKeepj norm! 1Gdd
1539 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001540 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1541 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001542" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001543 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001544 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001545 endif
1546 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001547
1548 elseif b:netrw_method == 9
1549 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001550" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001551 if a:fname =~ '/'
1552 let localfile= substitute(a:fname,'^.*/','','')
1553 else
1554 let localfile= a:fname
1555 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001556 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 +02001557
Bram Moolenaarff034192013-04-24 18:51:19 +02001558 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001559 " probably a badly formed url; protocol not recognized
1560" call Dret("netrw#Obtain : unsupported method")
1561 return
1562
1563 else
1564 " protocol recognized but not supported for Obtain (yet?)
1565 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001566 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001567 endif
1568" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001569 return
1570 endif
1571
1572 " restore status line
1573 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001574 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001575 endif
1576
1577 endif
1578
1579 " cleanup
1580 if exists("tmpbufnr")
1581 if bufnr("%") != tmpbufnr
1582 exe tmpbufnr."bw!"
1583 else
1584 q!
1585 endif
1586 endif
1587
Bram Moolenaara6878372014-03-22 21:02:50 +01001588" call Dret("netrw#Obtain")
1589endfun
1590
1591" ---------------------------------------------------------------------
1592" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1593fun! netrw#Nread(mode,fname)
1594" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001595 let svpos= winsaveview()
1596" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001597 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001598" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1599 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001600
1601 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1602 if exists("w:netrw_bannercnt")
1603 " start with cursor just after the banner
1604 exe w:netrw_bannercnt
1605 endif
1606 endif
1607" call Dret("netrw#Nread")
1608endfun
1609
1610" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001611" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1612" Options get restored by s:NetrwOptionsRestore()
1613"
1614" Option handling:
1615" * save user's options (s:NetrwOptionsSave)
1616" * set netrw-safe options (s:NetrwOptionsSafe)
1617" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1618" * restore user's options (s:netrwOPtionsRestore)
1619" - restore a user option when != safe option (s:NetrwRestoreSetting)
1620" vt: (variable type) normally its either "w:" or "s:"
1621fun! s:NetrwOptionsSave(vt)
1622" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1623" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
1624" 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>"))
1625
1626 if !exists("{a:vt}netrw_optionsave")
1627 let {a:vt}netrw_optionsave= 1
1628 else
1629" call Dret("s:NetrwOptionsSave : options already saved")
1630 return
1631 endif
1632" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1633
1634 " Save current settings and current directory
1635" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1636 let s:yykeep = @@
1637 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1638 let {a:vt}netrw_aikeep = &l:ai
1639 let {a:vt}netrw_awkeep = &l:aw
1640 let {a:vt}netrw_bhkeep = &l:bh
1641 let {a:vt}netrw_blkeep = &l:bl
1642 let {a:vt}netrw_btkeep = &l:bt
1643 let {a:vt}netrw_bombkeep = &l:bomb
1644 let {a:vt}netrw_cedit = &cedit
1645 let {a:vt}netrw_cikeep = &l:ci
1646 let {a:vt}netrw_cinkeep = &l:cin
1647 let {a:vt}netrw_cinokeep = &l:cino
1648 let {a:vt}netrw_comkeep = &l:com
1649 let {a:vt}netrw_cpokeep = &l:cpo
1650 let {a:vt}netrw_diffkeep = &l:diff
1651 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001652 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1653 let {a:vt}netrw_ffkeep = &l:ff
1654 endif
1655 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1656 let {a:vt}netrw_gdkeep = &l:gd " gdefault
1657 let {a:vt}netrw_hidkeep = &l:hidden
1658 let {a:vt}netrw_imkeep = &l:im
1659 let {a:vt}netrw_iskkeep = &l:isk
1660 let {a:vt}netrw_lskeep = &l:ls
1661 let {a:vt}netrw_makeep = &l:ma
1662 let {a:vt}netrw_magickeep = &l:magic
1663 let {a:vt}netrw_modkeep = &l:mod
1664 let {a:vt}netrw_nukeep = &l:nu
1665 let {a:vt}netrw_rnukeep = &l:rnu
1666 let {a:vt}netrw_repkeep = &l:report
1667 let {a:vt}netrw_rokeep = &l:ro
1668 let {a:vt}netrw_selkeep = &l:sel
1669 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001670 if !g:netrw_use_noswf
1671 let {a:vt}netrw_swfkeep = &l:swf
1672 endif
1673 let {a:vt}netrw_tskeep = &l:ts
1674 let {a:vt}netrw_twkeep = &l:tw " textwidth
1675 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1676 let {a:vt}netrw_wrapkeep = &l:wrap
1677 let {a:vt}netrw_writekeep = &l:write
1678
1679 " save a few selected netrw-related variables
1680" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1681 if g:netrw_keepdir
1682 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001683" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 endif
1685 if has("clipboard")
1686 sil! let {a:vt}netrw_starkeep = @*
1687 sil! let {a:vt}netrw_pluskeep = @+
1688 endif
1689 sil! let {a:vt}netrw_slashkeep= @/
1690
1691" 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>"))
1692" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1693endfun
1694
1695" ---------------------------------------------------------------------
1696" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1697" Use s:NetrwSaveOptions() to save user settings
1698" Use s:NetrwOptionsRestore() to restore user settings
1699fun! s:NetrwOptionsSafe(islocal)
1700" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1701" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1702" 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>"))
1703 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1704 call s:NetrwSetSafeSetting("&l:ai",0)
1705 call s:NetrwSetSafeSetting("&l:aw",0)
1706 call s:NetrwSetSafeSetting("&l:bl",0)
1707 call s:NetrwSetSafeSetting("&l:bomb",0)
1708 if a:islocal
1709 call s:NetrwSetSafeSetting("&l:bt","nofile")
1710 else
1711 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1712 endif
1713 call s:NetrwSetSafeSetting("&l:ci",0)
1714 call s:NetrwSetSafeSetting("&l:cin",0)
1715 call s:NetrwSetSafeSetting("&l:bh","hide")
1716 call s:NetrwSetSafeSetting("&l:cino","")
1717 call s:NetrwSetSafeSetting("&l:com","")
1718 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1719 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1720 setl fo=nroql2
1721 call s:NetrwSetSafeSetting("&l:hid",0)
1722 call s:NetrwSetSafeSetting("&l:im",0)
1723 setl isk+=@ isk+=* isk+=/
1724 call s:NetrwSetSafeSetting("&l:magic",1)
1725 if g:netrw_use_noswf
1726 call s:NetrwSetSafeSetting("swf",0)
1727 endif
1728 call s:NetrwSetSafeSetting("&l:report",10000)
1729 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1730 call s:NetrwSetSafeSetting("&l:spell",0)
1731 call s:NetrwSetSafeSetting("&l:tw",0)
1732 call s:NetrwSetSafeSetting("&l:wig","")
1733 setl cedit&
1734 call s:NetrwCursor()
1735
1736 " allow the user to override safe options
1737" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1738 if &ft == "netrw"
1739" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1740 keepalt NetrwKeepj doau FileType netrw
1741 endif
1742
1743" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1744" 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>"))
1745" call Dret("s:NetrwOptionsSafe")
1746endfun
1747
1748" ---------------------------------------------------------------------
1749" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1750fun! s:NetrwOptionsRestore(vt)
1751" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001752" 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 +01001753 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001754" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001755" 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>"))
1756" 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 +02001757" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001758 return
1759 endif
1760 unlet {a:vt}netrw_optionsave
1761
1762 if exists("+acd")
1763 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001764" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001765 let curdir = getcwd()
1766 let &l:acd = {a:vt}netrw_acdkeep
1767 unlet {a:vt}netrw_acdkeep
1768 if &l:acd
1769 call s:NetrwLcd(curdir)
1770 endif
1771 endif
1772 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001773 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1774 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1775 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1776 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1777 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1778 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1779 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1780 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1781 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1782 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1783 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1784 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1785 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1786 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1787 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001788 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001789 call s:NetrwRestoreSetting(a:vt."netrw_fokeep","&l:fo")
1790 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep","&l:gd")
1791 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep","&l:hidden")
1792 call s:NetrwRestoreSetting(a:vt."netrw_imkeep","&l:im")
1793 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep","&l:isk")
1794 call s:NetrwRestoreSetting(a:vt."netrw_lskeep","&l:ls")
1795 call s:NetrwRestoreSetting(a:vt."netrw_makeep","&l:ma")
1796 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
1797 call s:NetrwRestoreSetting(a:vt."netrw_modkeep","&l:mod")
1798 call s:NetrwRestoreSetting(a:vt."netrw_nukeep","&l:nu")
1799 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep","&l:rnu")
1800 call s:NetrwRestoreSetting(a:vt."netrw_repkeep","&l:report")
1801 call s:NetrwRestoreSetting(a:vt."netrw_rokeep","&l:ro")
1802 call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1803 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
1804 call s:NetrwRestoreSetting(a:vt."netrw_twkeep","&l:tw")
1805 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep","&l:wig")
1806 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep","&l:wrap")
1807 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1808 call s:NetrwRestoreSetting("s:yykeep","@@")
1809 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1810 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1811 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1812 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1813
Bram Moolenaara6878372014-03-22 21:02:50 +01001814 if exists("{a:vt}netrw_swfkeep")
1815 if &directory == ""
1816 " user hasn't specified a swapfile directory;
1817 " netrw will temporarily set the swapfile directory
1818 " to the current directory as returned by getcwd().
1819 let &l:directory= getcwd()
1820 sil! let &l:swf = {a:vt}netrw_swfkeep
1821 setl directory=
1822 unlet {a:vt}netrw_swfkeep
1823 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001824 if !g:netrw_use_noswf
1825 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1826 sil! let &l:swf= {a:vt}netrw_swfkeep
1827 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001828 unlet {a:vt}netrw_swfkeep
1829 endif
1830 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001831 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001832 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1833 if exists("{a:vt}netrw_dirkeep")
1834 call s:NetrwLcd(dirkeep)
1835 unlet {a:vt}netrw_dirkeep
1836 endif
1837 endif
1838 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001839" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001840 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1841 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001842 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001843 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001844
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001845" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1846" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1847" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1848" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1849" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001850 " Moved the filetype detect here from NetrwGetFile() because remote files
1851 " were having their filetype detect-generated settings overwritten by
1852 " NetrwOptionRestore.
1853 if &ft != "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001854" call Decho("filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001855 filetype detect
1856 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001857" 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 +02001858" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001859endfun
1860
1861" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001862" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1863" but only when the options' value and the safe setting differ
1864" Doing this means that netrw will not come up as having changed a
1865" setting last when it really didn't actually change it.
1866"
1867" Called from s:NetrwOptionsSafe
1868" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1869fun! s:NetrwSetSafeSetting(setting,safesetting)
1870" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001871
Bram Moolenaar85850f32019-07-19 22:05:51 +02001872 if a:setting =~ '^&'
1873" call Decho("fyi: a:setting starts with &")
1874 exe "let settingval= ".a:setting
1875" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001876
Bram Moolenaar85850f32019-07-19 22:05:51 +02001877 if settingval != a:safesetting
1878" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1879 if type(a:safesetting) == 0
1880 exe "let ".a:setting."=".a:safesetting
1881 elseif type(a:safesetting) == 1
1882 exe "let ".a:setting."= '".a:safesetting."'"
1883 else
1884 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1885 endif
1886 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001887 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001888
Bram Moolenaar85850f32019-07-19 22:05:51 +02001889" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001890endfun
1891
1892" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001893" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1894" but only if the setting value differs from the associated keepvar.
1895" Doing this means that netrw will not come up as having changed a
1896" setting last when it really didn't actually change it.
1897"
1898" Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
1899" keepvars are set up by s:NetrwOptionsSave
1900fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001901""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001902
Bram Moolenaar85850f32019-07-19 22:05:51 +02001903 " typically called from s:NetrwOptionsRestore
1904 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1905 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1906 " Restores option (if different) from a keepvar
1907 if exists(a:keepvar)
1908 exe "let keepvarval= ".a:keepvar
1909 exe "let setting= ".a:setting
1910
1911"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1912"" call Decho("fyi: keepvarval=".keepvarval)
1913"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1914
1915 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001916"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001917 if type(a:setting) == 0
1918 exe "let ".a:setting."= ".keepvarval
1919 elseif type(a:setting) == 1
1920 exe "let ".a:setting."= '".keepvarval."'"
1921 else
1922 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1923 endif
1924 endif
1925
1926 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001927 endif
1928
Bram Moolenaar85850f32019-07-19 22:05:51 +02001929"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001930endfun
1931
1932" ---------------------------------------------------------------------
1933" NetrwStatusLine: {{{2
1934fun! NetrwStatusLine()
1935
1936" vvv NetrwStatusLine() debugging vvv
1937" let g:stlmsg=""
1938" if !exists("w:netrw_explore_bufnr")
1939" let g:stlmsg="!X<explore_bufnr>"
1940" elseif w:netrw_explore_bufnr != bufnr("%")
1941" let g:stlmsg="explore_bufnr!=".bufnr("%")
1942" endif
1943" if !exists("w:netrw_explore_line")
1944" let g:stlmsg=" !X<explore_line>"
1945" elseif w:netrw_explore_line != line(".")
1946" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1947" endif
1948" if !exists("w:netrw_explore_list")
1949" let g:stlmsg=" !X<explore_list>"
1950" endif
1951" ^^^ NetrwStatusLine() debugging ^^^
1952
1953 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")
1954 " restore user's status line
1955 let &stl = s:netrw_users_stl
1956 let &laststatus = s:netrw_users_ls
1957 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1958 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1959 return ""
1960 else
1961 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1962 endif
1963endfun
1964
Bram Moolenaar85850f32019-07-19 22:05:51 +02001965" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001966" Netrw Transfer Functions: {{{1
1967" ===============================
1968
Bram Moolenaar071d4272004-06-13 20:20:40 +00001969" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001970" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001971" mode: =0 read remote file and insert before current line
1972" =1 read remote file and insert after current line
1973" =2 replace with remote file
1974" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001975fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001976" 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 +00001977
Bram Moolenaar5c736222010-01-06 20:54:52 +01001978 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001979 call s:NetrwOptionsSave("w:")
1980 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001981 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001982 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1983 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1984 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001985" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001986
Bram Moolenaar5c736222010-01-06 20:54:52 +01001987 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001988 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001989 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001990 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001991 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001992 elseif a:mode == 2 " replace with remote file
1993 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001994 elseif a:mode == 3 " skip read of file (leave as temporary)
1995 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001996 else
1997 exe a:mode
1998 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001999 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002000 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002001" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002002
Bram Moolenaar5c736222010-01-06 20:54:52 +01002003 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002004 let tmpfile= s:GetTempfile("")
2005 if tmpfile == ""
2006" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002007 return
2008 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002009
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002010 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002011
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002012 " attempt to repeat with previous host-file-etc
2013 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002014" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002015 let choice = b:netrw_lastfile
2016 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002017
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002018 else
2019 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002020" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002021
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002022 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002023 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002024 echomsg 'NetRead Usage:'
2025 echomsg ':Nread machine:path uses rcp'
2026 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2027 echomsg ':Nread "machine id password path" uses ftp'
2028 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2029 echomsg ':Nread fetch://machine/path uses fetch'
2030 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2031 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002032 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002033 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002034 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2035 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2036 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2037 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002038 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002039 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002040
Bram Moolenaar9964e462007-05-05 17:54:07 +00002041 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002042 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002043" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002044 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002045 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002046 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002047 else
2048 " case "... ... ..."
2049 let choice = strpart(choice,1,strlen(choice)-1)
2050 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002051
Bram Moolenaar9964e462007-05-05 17:54:07 +00002052 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 let wholechoice = wholechoice . " " . choice
2054 let ichoice = ichoice + 1
2055 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002056 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002057 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002058 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002059" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002060 return
2061 endif
2062 let choice= a:{ichoice}
2063 endwhile
2064 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2065 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 endif
2067 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002068
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002069" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002070 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071
Bram Moolenaar5c736222010-01-06 20:54:52 +01002072 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002073 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002074 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002075" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002076 return
2077 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002078 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaar8d043172014-01-23 14:24:41 +01002080 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002081" 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 +02002082 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002083" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002084 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002085" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002087 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002088
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002090 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002091 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002092 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2093 echo "(netrw) Processing your read request..."
2094 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002095
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002096 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002097 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002098 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002099" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002100 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002101 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002102 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002103 " ER: the tmpfile is full path: rcp sees C:\... as host C
2104 if s:netrw_has_nt_rcp == 1
2105 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2106 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2107 else
2108 " Any way needed it machine contains a '.'
2109 let uid_machine = g:netrw_machine .'.'. $USERNAME
2110 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2113 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2114 else
2115 let uid_machine = g:netrw_machine
2116 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002118 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 +00002119 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002120 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002121
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002122 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002123 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002124 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002125" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002126 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002127 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002128 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002129 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002130 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002131" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002132 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002133 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002134" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002135 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002136 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002138 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002139 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 +00002140 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002141 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002142 endif
2143 " 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 +00002144 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002145 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002146 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002147 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002148 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002149 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002150 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002152 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2153 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002154 q!
2155 endif
2156 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002157 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002159
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002160 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002161 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2163 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002164" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002165 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002166 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002167 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002168 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002170 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002171" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002172 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002173 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002174" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002175 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002176
Bram Moolenaar97d62492012-11-15 21:28:22 +01002177 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002178 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002179 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002180" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002181 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002182 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002183 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002184" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002185 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002186 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002187" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002188 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002189 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002190
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002191 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002192 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002195 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002196 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002198 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002199 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002200" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002201
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002202 " perform ftp:
2203 " -i : turns off interactive prompting from ftp
2204 " -n unix : DON'T use <.netrc>, even though it exists
2205 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002206 NetrwKeepj norm! 1Gdd
2207 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2209 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002210" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002211 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002212 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002213 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002214 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002215 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002216 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002217 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002218
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002220 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002221 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002222" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002224 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 else
2226 let useport= ""
2227 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002228 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2229 " This is workaround to avoid mis-handle windows local-path:
2230 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2231 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2232 else
2233 let tmpfile_get = tmpfile
2234 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002235 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 +00002236 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002238
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002240 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002241 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002242" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002243 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002244 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002245 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002246 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002247" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002248 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002250
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002251 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2252 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002253" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002254 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255 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 +00002256 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257 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 +00002258 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002259 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002260
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002262 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002264 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2265 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002266" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2267" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2268 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 +00002269 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002271 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 endif
2273 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002274" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002275 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002276
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002278 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002279 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002280" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002281
Bram Moolenaar5c736222010-01-06 20:54:52 +01002282 if !executable(g:netrw_dav_cmd)
2283 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2284" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2285 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002287 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002288 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 +01002289 else
2290 " Construct execution string (four lines) which will be passed through filter
2291 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2292 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002293 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002294 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002295 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002296 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002297 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002298 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002299 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002300 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002301 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002302 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2303 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002304
Bram Moolenaar5c736222010-01-06 20:54:52 +01002305 " perform cadaver operation:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002306 NetrwKeepj norm! 1Gdd
2307 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002308 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002309 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002310 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002311 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002312
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002313 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002314 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002315 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002316" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002317 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 +00002318 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002319 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002320
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002321 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002322 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002324 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002327 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002328 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002329 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002330" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002331 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002332 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002333 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002334 let netrw_option= "http"
2335 else
2336 let netrw_option= "ftp"
2337 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002338" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002339
Bram Moolenaar446cb832008-06-24 21:56:24 +00002340 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002341 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 +00002342 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002343 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 +00002344 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002345
Bram Moolenaar446cb832008-06-24 21:56:24 +00002346 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002348" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002349 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002350
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002351 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002353 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002354" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2355 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 +00002356 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002357 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002358
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002359 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002360 " NetRead: (file) NetRead Method #10 {{{3
2361 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002362" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2363 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002364 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2365 let b:netrw_lastfile = choice
2366
2367 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002369 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002370 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002371 endif
2372 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002373
Bram Moolenaar5c736222010-01-06 20:54:52 +01002374 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002375 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002376" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002377 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002378 unlet b:netrw_fname
2379 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002380 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 +01002381" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002382 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002383 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002384 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002385
Bram Moolenaar9964e462007-05-05 17:54:07 +00002386" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387endfun
2388
2389" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002390" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002391fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002392" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002393
Bram Moolenaar5c736222010-01-06 20:54:52 +01002394 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002395 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002396 call s:NetrwOptionsSave("w:")
2397 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002398
Bram Moolenaar5c736222010-01-06 20:54:52 +01002399 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002400 let tmpfile= s:GetTempfile("")
2401 if tmpfile == ""
2402" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002403 return
2404 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002405
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 if a:0 == 0
2407 let ichoice = 0
2408 else
2409 let ichoice = 1
2410 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002411
Bram Moolenaar9964e462007-05-05 17:54:07 +00002412 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002413" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002414 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002415 " For binary writes, always write entire file.
2416 " (line numbers don't really make sense for that).
2417 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002418" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002419 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002420 elseif g:netrw_cygwin
2421 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002422 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002423" 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 +01002424 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002425 else
2426 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002427" 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 +01002428 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002429 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002430
Bram Moolenaar9964e462007-05-05 17:54:07 +00002431 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002432 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002433 " on the temporary file's name. Deletion of the temporary file during
2434 " cleanup then causes an error message.
2435 0file!
2436 endif
2437
Bram Moolenaar5c736222010-01-06 20:54:52 +01002438 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002440
Bram Moolenaar9964e462007-05-05 17:54:07 +00002441 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 " attempt to repeat with previous host-file-etc
2443 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002444" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 let choice = b:netrw_lastfile
2446 let ichoice= ichoice + 1
2447 else
2448 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002449
Bram Moolenaar8d043172014-01-23 14:24:41 +01002450 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002451 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002452 echomsg 'NetWrite Usage:"'
2453 echomsg ':Nwrite machine:path uses rcp'
2454 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2455 echomsg ':Nwrite "machine id password path" uses ftp'
2456 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2457 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2458 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2459 echomsg ':Nwrite rcp://machine/path uses rcp'
2460 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2461 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2462 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002463 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002464 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002466 elseif match(choice,"^\"") != -1
2467 if match(choice,"\"$") != -1
2468 " case "..."
2469 let choice=strpart(choice,1,strlen(choice)-2)
2470 else
2471 " case "... ... ..."
2472 let choice = strpart(choice,1,strlen(choice)-1)
2473 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002474
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002475 while match(choice,"\"$") == -1
2476 let wholechoice= wholechoice . " " . choice
2477 let ichoice = ichoice + 1
2478 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002479 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002480 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002481 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002483 return
2484 endif
2485 let choice= a:{ichoice}
2486 endwhile
2487 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2488 endif
2489 endif
2490 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002491 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002492" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002493
Bram Moolenaar9964e462007-05-05 17:54:07 +00002494 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002495 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002496 if !exists("b:netrw_method") || b:netrw_method < 0
2497" call Dfunc("netrw#NetWrite : unsupported method")
2498 return
2499 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002500
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002501 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002502 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002503 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002504 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2505 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002506" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002507 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002508
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002510 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002511 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002512" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 if s:netrw_has_nt_rcp == 1
2514 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2515 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2516 else
2517 let uid_machine = g:netrw_machine .'.'. $USERNAME
2518 endif
2519 else
2520 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2521 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2522 else
2523 let uid_machine = g:netrw_machine
2524 endif
2525 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002526 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 +00002527 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002528
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002529 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002530 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002531 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002532" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002533 let netrw_fname = b:netrw_fname
2534
2535 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2536 let bhkeep = &l:bh
2537 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002538 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002539 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002540
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002541" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002542 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002543 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002544" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002545 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002546 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002547" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002548 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002549 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002550" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002552 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 +00002553 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002554" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2555 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002556 endif
2557 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2558 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002559 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002560 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002561 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002562 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002564
2565 " remove enew buffer (quietly)
2566 let filtbuf= bufnr("%")
2567 exe curbuf."b!"
2568 let &l:bh = bhkeep
2569 exe filtbuf."bw!"
2570
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002572
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002573 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002574 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002575 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002576 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002577" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002578 let netrw_fname = b:netrw_fname
2579 let bhkeep = &l:bh
2580
2581 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2582 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002583 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002584 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002585 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002586
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002587 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002588 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002590 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002591 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002592" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002593 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002594 if exists("g:netrw_uid") && g:netrw_uid != ""
2595 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002596 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002597" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002598 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002599 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002600 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002602 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002603 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002605 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002606 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002607 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002609 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002610 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002612 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002613 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002615 " save choice/id/password for future use
2616 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002617
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002618 " perform ftp:
2619 " -i : turns off interactive prompting from ftp
2620 " -n unix : DON'T use <.netrc>, even though it exists
2621 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002622 NetrwKeepj norm! 1Gdd
2623 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002624 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2625 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002626 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002627 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002628 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 let mod=1
2630 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002631
2632 " remove enew buffer (quietly)
2633 let filtbuf= bufnr("%")
2634 exe curbuf."b!"
2635 let &l:bh= bhkeep
2636 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002637
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002638 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002640 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002641" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002642 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002643 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002644 else
2645 let useport= ""
2646 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002647 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 +00002648 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002649
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002651 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002652 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002653" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002654 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2655 if executable(curl)
2656 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002657 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 +01002658 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002659 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002660 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002661
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002662 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002663 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002664 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002665" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002666
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002667 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002668 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2669 let bhkeep = &l:bh
2670
2671 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2672 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002673 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002675
Bram Moolenaarff034192013-04-24 18:51:19 +02002676 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002677 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002678 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002681 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002682 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002683 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002684 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002685 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002686
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002687 " perform cadaver operation:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002688 NetrwKeepj norm! 1Gdd
2689 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002690
2691 " remove enew buffer (quietly)
2692 let filtbuf= bufnr("%")
2693 exe curbuf."b!"
2694 let &l:bh = bhkeep
2695 exe filtbuf."bw!"
2696
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002697 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002698
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002700 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002701 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002702" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002703 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 +00002704 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002705
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002706 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002707 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002708 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002709" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002710 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2712 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2713 else
2714 let uid_machine = g:netrw_machine
2715 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002716
2717 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2718 let bhkeep = &l:bh
2719 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002720 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002721 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002722
Bram Moolenaarff034192013-04-24 18:51:19 +02002723 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002724 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002725" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002726 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002727 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002728 let filtbuf= bufnr("%")
2729 exe curbuf."b!"
2730 let &l:bh = bhkeep
2731 exe filtbuf."bw!"
2732 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002733
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002734 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002735 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002736 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002737 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002738 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002739 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002740 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002741
Bram Moolenaar5c736222010-01-06 20:54:52 +01002742 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002743" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002744 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002745" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002746 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002747 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002748 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002749
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002750 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002751 " restore modifiability; usually equivalent to set nomod
2752 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002753" 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 +02002754 elseif !exists("leavemod")
2755 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002756" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002757 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002758" 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 +00002759 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002760
Bram Moolenaar9964e462007-05-05 17:54:07 +00002761" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002762endfun
2763
2764" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002765" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002766" uses NetRead to get a copy of the file into a temporarily file,
2767" then sources that file,
2768" then removes that file.
2769fun! netrw#NetSource(...)
2770" call Dfunc("netrw#NetSource() a:0=".a:0)
2771 if a:0 > 0 && a:1 == '?'
2772 " give help
2773 echomsg 'NetSource Usage:'
2774 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2775 echomsg ':Nsource fetch://machine/path uses fetch'
2776 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002777 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002778 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2779 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2780 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2781 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2782 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002783 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002784 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002785 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002786 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002788 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002789" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002790 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002791" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002792 if delete(s:netrw_tmpfile)
2793 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2794 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002795 unlet s:netrw_tmpfile
2796 else
2797 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2798 endif
2799 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002800 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002801 endif
2802" call Dret("netrw#NetSource")
2803endfun
2804
Bram Moolenaar8d043172014-01-23 14:24:41 +01002805" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002806" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2807" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002808fun! netrw#SetTreetop(iscmd,...)
2809" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2810" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002811
Bram Moolenaar85850f32019-07-19 22:05:51 +02002812 " iscmd==0: netrw#SetTreetop called using gn mapping
2813 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2814" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002815 " clear out the current tree
2816 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002817" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002818 let inittreetop= w:netrw_treetop
2819 unlet w:netrw_treetop
2820 endif
2821 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002823 unlet w:netrw_treedict
2824 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002825" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002826
Bram Moolenaar85850f32019-07-19 22:05:51 +02002827 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002828 let treedir= s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002829" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002830 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002831 if isdirectory(s:NetrwFile(a:1))
2832" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002833 let treedir= a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002834 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar8d043172014-01-23 14:24:41 +01002835 let treedir= b:netrw_curdir."/".a:1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002836" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002837 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002838 " normally the cursor is left in the message window.
2839 " However, here this results in the directory being listed in the message window, which is not wanted.
2840 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002841 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002842 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaara6878372014-03-22 21:02:50 +01002843 let treedir= "."
Bram Moolenaar8d043172014-01-23 14:24:41 +01002844 endif
2845 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002846" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002847
2848 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002849 let islocal= expand("%") !~ '^\a\{3,}://'
2850" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002851
2852 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002853 if islocal
2854 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2855 else
2856 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2857 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002858
Bram Moolenaara6878372014-03-22 21:02:50 +01002859" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002860endfun
2861
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002863" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002864" readcmd == %r : replace buffer with newly read file
2865" == 0r : read file at top of buffer
2866" == r : read file after current line
2867" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002868fun! s:NetrwGetFile(readcmd, tfile, method)
2869" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002870
2871 " readcmd=='t': simply do nothing
2872 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002873" 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 +01002874" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002875 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002876 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002877
Bram Moolenaar9964e462007-05-05 17:54:07 +00002878 " get name of remote filename (ie. url and all)
2879 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002880" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002881
Bram Moolenaar9964e462007-05-05 17:54:07 +00002882 if exists("*NetReadFixup")
2883 " for the use of NetReadFixup (not otherwise used internally)
2884 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002885 endif
2886
Bram Moolenaar9964e462007-05-05 17:54:07 +00002887 if a:readcmd[0] == '%'
2888 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002890
2891 " rename the current buffer to the temp file (ie. tfile)
2892 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002893 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002894 else
2895 let tfile= a:tfile
2896 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002897 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002898
2899 " edit temporary file (ie. read the temporary file in)
2900 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002902 call zip#Browse(tfile)
2903 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002904" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002905 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002906 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002908 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002909 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002911 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002912 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002913" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002914 call tar#Browse(tfile)
2915 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002916" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002917 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002918 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002919" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002920 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002921 endif
2922
2923 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002925
Bram Moolenaar97d62492012-11-15 21:28:22 +01002926 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002927 " Note that isk must not include a "/" for scripts.vim
2928 " to process this detection correctly.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002929" call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002930 let iskkeep= &l:isk
2931 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002932 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002933" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002934 let line1 = 1
2935 let line2 = line("$")
2936
Bram Moolenaar8d043172014-01-23 14:24:41 +01002937 elseif !&ma
2938 " 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 +01002939 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002940" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002941 return
2942
Bram Moolenaar9964e462007-05-05 17:54:07 +00002943 elseif s:FileReadable(a:tfile)
2944 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002945" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002946 let curline = line(".")
2947 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002948" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002949 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002950 let line1= curline + 1
2951 let line2= line("$") - lastline + 1
2952
2953 else
2954 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002955" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2956" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002957 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002958" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002959 return
2960 endif
2961
2962 " User-provided (ie. optional) fix-it-up command
2963 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002964" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002965 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002966" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 endif
2969
Bram Moolenaaradc21822011-04-01 18:03:16 +02002970 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002971 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002972 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002973 endif
2974
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" 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 +00002976
2977 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002978" redraw!
2979
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" 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 +00002981" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002982endfun
2983
Bram Moolenaar9964e462007-05-05 17:54:07 +00002984" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002985" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002986" Input:
2987" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2988" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" b:netrw_method= 1: rcp
2990" 2: ftp + <.netrc>
2991" 3: ftp + machine, id, password, and [path]filename
2992" 4: scp
2993" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002994" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002995" 7: rsync
2996" 8: fetch
2997" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002998" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002999" g:netrw_machine= hostname
3000" b:netrw_fname = filename
3001" g:netrw_port = optional port number (for ftp)
3002" g:netrw_choice = copy of input url (choice)
3003fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003004" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003005
Bram Moolenaar251e1912011-06-19 05:09:16 +02003006 " sanity check: choice should have at least three slashes in it
3007 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3008 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3009 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003010" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003011 return
3012 endif
3013
Bram Moolenaar5c736222010-01-06 20:54:52 +01003014 " record current g:netrw_machine, if any
3015 " curmachine used if protocol == ftp and no .netrc
3016 if exists("g:netrw_machine")
3017 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003018" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003019 else
3020 let curmachine= "N O T A HOST"
3021 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003022 if exists("g:netrw_port")
3023 let netrw_port= g:netrw_port
3024 endif
3025
3026 " insure that netrw_ftp_cmd starts off every method determination
3027 " with the current g:netrw_ftp_cmd
3028 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003029
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003030 " initialization
3031 let b:netrw_method = 0
3032 let g:netrw_machine = ""
3033 let b:netrw_fname = ""
3034 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003035 let g:netrw_choice = a:choice
3036
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003037 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003038 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003039 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3040 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003041 " rcpurm : rcp://[user@]host/filename Use rcp
3042 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003043 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003044 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003045 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003046 " rsyncurm : rsync://host[:port]/path Use rsync
3047 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3048 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003049 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003050 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3051 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003052 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3053 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003054 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003055 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003056 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003057 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003058 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003059 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003060 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003061 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003062
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003063" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003064 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003065 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003066 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003067" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003068 let b:netrw_method = 1
3069 let userid = substitute(a:choice,rcpurm,'\1',"")
3070 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3071 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003072 if userid != ""
3073 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003075
Bram Moolenaaradc21822011-04-01 18:03:16 +02003076 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003077 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003078" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003079 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003080 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3081 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3082 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003083
Bram Moolenaar15146672011-10-20 22:22:38 +02003084 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003085 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003086" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003087 let b:netrw_method = 5
3088 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3089 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003090 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003091
Bram Moolenaaradc21822011-04-01 18:03:16 +02003092 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003093 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003094" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003095 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003096 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003097 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3098 else
3099 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3100 endif
3101 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003102
Bram Moolenaaradc21822011-04-01 18:03:16 +02003103 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003105" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 let b:netrw_method = 7
3107 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3108 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003109
Bram Moolenaaradc21822011-04-01 18:03:16 +02003110 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003112" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003113 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3115 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3116 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003117" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003118 if userid != ""
3119 let g:netrw_uid= userid
3120 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003121
Bram Moolenaaradc21822011-04-01 18:03:16 +02003122 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003123 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003124 call NetUserPass("ftp:".g:netrw_machine)
3125 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003126 " if there's a change in hostname, require password re-entry
3127 unlet s:netrw_passwd
3128 endif
3129 if exists("netrw_port")
3130 unlet netrw_port
3131 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003132 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003133
Bram Moolenaar446cb832008-06-24 21:56:24 +00003134 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 let b:netrw_method = 3
3136 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003137 let host= substitute(g:netrw_machine,'\..*$','','')
3138 if exists("s:netrw_hup[host]")
3139 call NetUserPass("ftp:".host)
3140
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003141 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003142" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3143" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003144 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003145 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003146" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003147 endif
3148 let b:netrw_method= 2
3149 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003150" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 let b:netrw_method= 2
3152 else
3153 if !exists("g:netrw_uid") || g:netrw_uid == ""
3154 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003155 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003157 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003158 endif
3159 let b:netrw_method= 3
3160 endif
3161 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003162
Bram Moolenaaradc21822011-04-01 18:03:16 +02003163 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003165" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003166 let b:netrw_method = 8
3167 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3168 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3169 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3170 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003171
Bram Moolenaaradc21822011-04-01 18:03:16 +02003172 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003173 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003174" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003176 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3177 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003178 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003179 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003180 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003181
Bram Moolenaaradc21822011-04-01 18:03:16 +02003182 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003184" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003185 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003186 let b:netrw_method = 3
3187 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3188 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003189
Bram Moolenaar9964e462007-05-05 17:54:07 +00003190 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003191 let b:netrw_method = 2
3192 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3193 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3194 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003195
Bram Moolenaaradc21822011-04-01 18:03:16 +02003196 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003197 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003198" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003199 let b:netrw_method = 9
3200 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3201 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003202
Bram Moolenaaradc21822011-04-01 18:03:16 +02003203 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003204 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003205" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003206 let b:netrw_method = 1
3207 let userid = substitute(a:choice,rcphf,'\2',"")
3208 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3209 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003210" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3211" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3212" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3213" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003214 if userid != ""
3215 let g:netrw_uid= userid
3216 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003217
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003218 " Method#10: file://user@hostname/...path-to-file {{{3
3219 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003220" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003221 let b:netrw_method = 10
3222 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003223" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003224
Bram Moolenaaradc21822011-04-01 18:03:16 +02003225 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003226 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003227 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003228 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003229 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003232 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003233
Bram Moolenaar81695252004-12-29 20:58:21 +00003234 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003235 " remove any leading [:#] from port number
3236 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3237 elseif exists("netrw_port")
3238 " retain port number as implicit for subsequent ftp operations
3239 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003240 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003241
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003242" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3243" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3244" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3245" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003246" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003247" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003248" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003249" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003250" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003251" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003252" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003253" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255
3256" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003257" NetReadFixup: this sort of function is typically written by the user {{{2
3258" to handle extra junk that their system's ftp dumps
3259" into the transfer. This function is provided as an
3260" example and as a fix for a Windows 95 problem: in my
3261" experience, win95's ftp always dumped four blank lines
3262" at the end of the transfer.
3263if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3264 fun! NetReadFixup(method, line1, line2)
3265" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003266
3267 " sanity checks -- attempt to convert inputs to integers
3268 let method = a:method + 0
3269 let line1 = a:line1 + 0
3270 let line2 = a:line2 + 0
3271 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3272" call Dret("NetReadFixup")
3273 return
3274 endif
3275
Bram Moolenaar9964e462007-05-05 17:54:07 +00003276 if method == 3 " ftp (no <.netrc>)
3277 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003278 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003279 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003280 call histdel("/",-1)
3281 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003282 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003283
Bram Moolenaar9964e462007-05-05 17:54:07 +00003284" call Dret("NetReadFixup")
3285 endfun
3286endif
3287
3288" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003289" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003290" Usage: :call NetUserPass() -- will prompt for userid and password
3291" :call NetUserPass("uid") -- will prompt for password
3292" :call NetUserPass("uid","password") -- sets global userid and password
3293" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3294" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295fun! NetUserPass(...)
3296
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003297" call Dfunc("NetUserPass() a:0=".a:0)
3298
3299 if !exists('s:netrw_hup')
3300 let s:netrw_hup= {}
3301 endif
3302
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003304 " case: no input arguments
3305
3306 " change host and username if not previously entered; get new password
3307 if !exists("g:netrw_machine")
3308 let g:netrw_machine= input('Enter hostname: ')
3309 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003311 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312 let g:netrw_uid= input('Enter username: ')
3313 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003314 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003315 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003316
3317 " set up hup database
3318 let host = substitute(g:netrw_machine,'\..*$','','')
3319 if !exists('s:netrw_hup[host]')
3320 let s:netrw_hup[host]= {}
3321 endif
3322 let s:netrw_hup[host].uid = g:netrw_uid
3323 let s:netrw_hup[host].passwd = s:netrw_passwd
3324
3325 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003326 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003327
3328 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003329 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003330 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003331" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003332 let host = substitute(a:1,'^ftp:','','')
3333 let host = substitute(host,'\..*','','')
3334 if exists("s:netrw_hup[host]")
3335 let g:netrw_uid = s:netrw_hup[host].uid
3336 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003337" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3338" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003339 else
3340 let g:netrw_uid = input("Enter UserId: ")
3341 let s:netrw_passwd = inputsecret("Enter Password: ")
3342 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003343
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003344 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003345 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003346" 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 +02003347 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003348 if g:netrw_machine =~ '[0-9.]\+'
3349 let host= g:netrw_machine
3350 else
3351 let host= substitute(g:netrw_machine,'\..*$','','')
3352 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003353 else
3354 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003355 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003356 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003357" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003358 if exists("g:netrw_passwd")
3359 " ask for password if one not previously entered
3360 let s:netrw_passwd= g:netrw_passwd
3361 else
3362 let s:netrw_passwd = inputsecret("Enter Password: ")
3363 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003364 endif
3365
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003366" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003367 if exists("host")
3368 if !exists('s:netrw_hup[host]')
3369 let s:netrw_hup[host]= {}
3370 endif
3371 let s:netrw_hup[host].uid = g:netrw_uid
3372 let s:netrw_hup[host].passwd = s:netrw_passwd
3373 endif
3374
3375 elseif a:0 == 2
3376 let g:netrw_uid = a:1
3377 let s:netrw_passwd = a:2
3378
3379 elseif a:0 == 3
3380 " enter hostname, user-id, and password into the hup dictionary
3381 let host = substitute(a:1,'^\a\+:','','')
3382 let host = substitute(host,'\..*$','','')
3383 if !exists('s:netrw_hup[host]')
3384 let s:netrw_hup[host]= {}
3385 endif
3386 let s:netrw_hup[host].uid = a:2
3387 let s:netrw_hup[host].passwd = a:3
3388 let g:netrw_uid = s:netrw_hup[host].uid
3389 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003390" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3391" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003393
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003394" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396
Bram Moolenaar85850f32019-07-19 22:05:51 +02003397" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003398" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003399" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003401" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003402" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3403fun! s:ExplorePatHls(pattern)
3404" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3405 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003406" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003407 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003408" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003409 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3410" call Dret("s:ExplorePatHls repat<".repat.">")
3411 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003412endfun
3413
3414" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003415" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003416" 0: (user: <mb>) bookmark current directory
3417" 1: (user: <gb>) change to the bookmarked directory
3418" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003419" 3: (browsing) records current directory history
3420" 4: (user: <u>) go up (previous) directory, using history
3421" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003422" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003423fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003424" 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 +02003425 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3426" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3427 return
3428 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003429
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003430 let ykeep = @@
3431 let curbufnr = bufnr("%")
3432
Bram Moolenaar9964e462007-05-05 17:54:07 +00003433 if a:chg == 0
3434 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003435" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003436 if exists("s:netrwmarkfilelist_{curbufnr}")
3437 call s:NetrwBookmark(0)
3438 echo "bookmarked marked files"
3439 else
3440 call s:MakeBookmark(a:curdir)
3441 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003442 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003443
3444 elseif a:chg == 1
3445 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003447 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003448" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003449 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003450 else
3451 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3452 endif
3453
3454 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003455" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003456 let didwork= 0
3457 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003458" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003459 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003460" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003461 let cnt= 1
3462 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003463" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003464 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003465 let didwork = 1
3466 let cnt = cnt + 1
3467 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003468 endif
3469
3470 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003471 " Note: history is saved only when PerformListing is done;
3472 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3473 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003474 let first = 1
3475 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003476 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003477 while ( first || cnt != g:netrw_dirhistcnt )
3478" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003479 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003480" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003481 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003482 let didwork= 1
3483 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003484 let histcnt = histcnt + 1
3485 let first = 0
3486 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003487 if cnt < 0
3488 let cnt= cnt + g:netrw_dirhistmax
3489 endif
3490 endwhile
3491 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003492 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003493 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003494 if didwork
3495 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3496 endif
3497
3498 elseif a:chg == 3
3499 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003500" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003501 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 +02003502 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003503 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3504 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003505 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003506" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003507 endif
3508
3509 elseif a:chg == 4
3510 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003511" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003512 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003513 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3514 if g:netrw_dirhistcnt < 0
3515 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003516 endif
3517 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003518 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003519 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003520 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3521" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003522 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003523 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003524" call Decho("setl ma noro",'~'.expand("<slnum>"))
3525 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003526 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003527" call Decho("setl nomod",'~'.expand("<slnum>"))
3528" 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 +00003529 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003530" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3531 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003532 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003533 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003534 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003535 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003536 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003537 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003538 echo "Sorry, no predecessor directory exists yet"
3539 endif
3540
3541 elseif a:chg == 5
3542 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003543" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003544 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003545 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3546 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3547" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003548 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003549" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003550 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003551 sil! NetrwKeepj %d _
3552" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3553" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003554 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003555" 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 +02003556 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003557" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3558 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003559 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003560 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3561 if g:netrw_dirhistcnt < 0
3562 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003563 endif
3564 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003565 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003566 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003567 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003568 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003569 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003570
3571 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003572" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003573 if exists("s:netrwmarkfilelist_{curbufnr}")
3574 call s:NetrwBookmark(1)
3575 echo "removed marked files from bookmarks"
3576 else
3577 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003578 let iremove = v:count
3579 let dremove = g:netrw_bookmarklist[iremove - 1]
3580" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003581 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003582" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3583 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3584 echo "removed ".dremove." from g:netrw_bookmarklist"
3585" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003586 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003587" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003588 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003589 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003590 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003591 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003592" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003593endfun
3594
3595" ---------------------------------------------------------------------
3596" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003597" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003598" Sister function: s:NetrwBookHistSave()
3599fun! s:NetrwBookHistRead()
3600" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003601 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003602" 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 +02003603 return
3604 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003605 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606
3607 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003608 if !exists("s:netrw_initbookhist")
3609 let home = s:NetrwHome()
3610 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003611 if filereadable(s:NetrwFile(savefile))
3612" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003613 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003614 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003615
3616 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003617 if g:netrw_dirhistmax > 0
3618 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003619 if filereadable(s:NetrwFile(savefile))
3620" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003621 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003622 endif
3623 let s:netrw_initbookhist= 1
3624 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003625 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003626 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003627
Bram Moolenaar97d62492012-11-15 21:28:22 +01003628 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003629" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3630" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003631" call Dret("s:NetrwBookHistRead")
3632endfun
3633
3634" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003635" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003636" Sister function: s:NetrwBookHistRead()
3637" I used to do this via viminfo but that appears to
3638" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003639" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3640" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003641" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003642fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003643" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003644 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003645" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003646 return
3647 endif
3648
Bram Moolenaar5c736222010-01-06 20:54:52 +01003649 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003650" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003651 1split
3652 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003653" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003654 if g:netrw_use_noswf
3655 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3656 else
3657 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3658 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003659 setl nocin noai noci magic nospell nohid wig= noaw
3660 setl ma noro write
3661 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003662 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003663
Bram Moolenaar85850f32019-07-19 22:05:51 +02003664 " rename enew'd file: .netrwhist -- no attempt to merge
3665 " record dirhistmax and current dirhistcnt
3666 " save history
3667" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003668 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003669 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003670 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3671 if g:netrw_dirhistmax > 0
3672 let lastline = line("$")
3673 let cnt = g:netrw_dirhistcnt
3674 let first = 1
3675 while ( first || cnt != g:netrw_dirhistcnt )
3676 let lastline= lastline + 1
3677 if exists("g:netrw_dirhist_{cnt}")
3678 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3679" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3680 endif
3681 let first = 0
3682 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3683 if cnt < 0
3684 let cnt= cnt + g:netrw_dirhistmax
3685 endif
3686 endwhile
3687 exe "sil! w! ".savefile
3688" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3689 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003690
Bram Moolenaar85850f32019-07-19 22:05:51 +02003691 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003692 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003694" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003695 " merge and write .netrwbook
3696 let savefile= s:NetrwHome()."/.netrwbook"
3697
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003698 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003700 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 for bdm in booklist
3702 if index(g:netrw_bookmarklist,bdm) == -1
3703 call add(g:netrw_bookmarklist,bdm)
3704 endif
3705 endfor
3706 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003707 endif
3708
3709 " construct and save .netrwbook
3710 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003711 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003713 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003714
3715 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003716 let bgone= bufnr("%")
3717 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003718 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003719
3720" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003721endfun
3722
3723" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003724" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3725" list of the contents of a local or remote directory. It is assumed that the
3726" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3727" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003728" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003729fun! s:NetrwBrowse(islocal,dirname)
3730 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003731" 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 +02003732" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3733" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3734" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003735
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003736 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3737 " This is useful when one edits a local file, then :e ., then :Rex
3738 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3739 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003740" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003741 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003743 " s:NetrwBrowse : initialize history {{{3
3744 if !exists("s:netrw_initbookhist")
3745 NetrwKeepj call s:NetrwBookHistRead()
3746 endif
3747
3748 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003749 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003751" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 else
3753 let dirname= a:dirname
3754 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003755
Bram Moolenaar85850f32019-07-19 22:05:51 +02003756 " repoint t:netrw_lexbufnr if appropriate
3757 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3758" call Decho("set repointlexbufnr to true!")
3759 let repointlexbufnr= 1
3760 endif
3761
3762 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003763 if exists("s:netrw_skipbrowse")
3764 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003765" 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 +01003766" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003767 return
3768 endif
3769 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003770 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003771" call Dret("s:NetrwBrowse : missing shellescape()")
3772 return
3773 endif
3774 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003775 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003776" call Dret("s:NetrwBrowse : missing fnameescape()")
3777 return
3778 endif
3779
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003780 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003781 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003782
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003783 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003784 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3785 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3786" call Decho("clearing marked files",'~'.expand("<slnum>"))
3787 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3788 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003789 endif
3790
3791 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003792 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003793" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3794" 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 +02003795 if s:NetrwLcd(dirname)
3796" call Dret("s:NetrwBrowse : lcd failure")
3797 return
3798 endif
3799 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003800" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003801
Bram Moolenaar5c736222010-01-06 20:54:52 +01003802 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003803 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003804" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003805 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003806" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003807 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003808 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003809 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003810" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003811
3812 " remove any filetype indicator from end of dirname, except for the
3813 " "this is a directory" indicator (/).
3814 " There shouldn't be one of those here, anyway.
3815 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003816" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003817 call s:RemotePathAnalysis(dirname)
3818
3819 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3820 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003821 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003822 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003823" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003824 let b:netrw_curdir = dirname
3825 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003826 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003827 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3828 sil call netrw#NetRead(2,url)
3829 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003830" call Decho("url<".url.">",'~'.expand("<slnum>"))
3831" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3832" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003833 if s:path =~ '.bz2'
3834 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3835 elseif s:path =~ '.gz'
3836 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3837 elseif s:path =~ '.gz'
3838 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3839 else
3840 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3841 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003842 endif
3843
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003844 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003845 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003846 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003847" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003848 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003849" 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 +00003850
Bram Moolenaar446cb832008-06-24 21:56:24 +00003851" call Dret("s:NetrwBrowse : file<".s:fname.">")
3852 return
3853 endif
3854
Bram Moolenaaradc21822011-04-01 18:03:16 +02003855 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856 call s:UseBufWinVars()
3857
3858 " set up some variables {{{3
3859 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003860 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003861 let s:last_sort_by = g:netrw_sort_by
3862
3863 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003865
Bram Moolenaar97d62492012-11-15 21:28:22 +01003866 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003867" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003868 let svpos = winsaveview()
3869" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003870 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003871
Bram Moolenaar446cb832008-06-24 21:56:24 +00003872 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003873 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3874 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3875" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3876" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3877 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3878 else
3879" " call Decho("2match none",'~'.expand("<slnum>"))
3880 2match none
3881 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003882 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003883 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003884 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003885" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003886 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003887" 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 +01003888" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003889 return
3890 endif
3891
3892 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003893" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003894 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003895 if b:netrw_curdir =~ '[/\\]$'
3896 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3897 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003898 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3899 let b:netrw_curdir= b:netrw_curdir."/"
3900 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901 if b:netrw_curdir == ''
3902 if has("amiga")
3903 " On the Amiga, the empty string connotes the current directory
3904 let b:netrw_curdir= getcwd()
3905 else
3906 " under unix, when the root directory is encountered, the result
3907 " from the preceding substitute is an empty string.
3908 let b:netrw_curdir= '/'
3909 endif
3910 endif
3911 if !a:islocal && b:netrw_curdir !~ '/$'
3912 let b:netrw_curdir= b:netrw_curdir.'/'
3913 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003914" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915
3916 " ------------
3917 " (local only) {{{3
3918 " ------------
3919 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003920" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921
3922 " Set up ShellCmdPost handling. Append current buffer to browselist
3923 call s:LocalFastBrowser()
3924
3925 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3926 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003927" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3928" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003930 if s:NetrwLcd(b:netrw_curdir)
3931" call Dret("s:NetrwBrowse : lcd failure")
3932 return
3933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934 endif
3935 endif
3936
3937 " --------------------------------
3938 " remote handling: {{{3
3939 " --------------------------------
3940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003942
Bram Moolenaar97d62492012-11-15 21:28:22 +01003943 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" 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 +02003945 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003946 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003947" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3949 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3950 if dirname !~ '/$'
3951 let dirname= dirname.'/'
3952 endif
3953 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003954" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003955 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003956 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003957" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958 endif
3959
3960 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3961 if dirname !~ dirpat
3962 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003963 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003964 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003965 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003966" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003967 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003968" 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 +00003969" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3970 return
3971 endif
3972 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974 endif " (additional remote handling)
3975
Bram Moolenaar85850f32019-07-19 22:05:51 +02003976 " -------------------------------
3977 " Perform Directory Listing: {{{3
3978 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003979 NetrwKeepj call s:NetrwMaps(a:islocal)
3980 NetrwKeepj call s:NetrwCommands(a:islocal)
3981 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003982
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003983 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003984 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003985" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3986
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987 " If there is a rexposn: restore position with rexposn
3988 " Otherwise : set rexposn
3989 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003990" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
3991 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3992 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3993 NetrwKeepj exe w:netrw_bannercnt
3994 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003995 else
3996 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3997 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003998 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003999 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004001 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004002 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004003
Bram Moolenaar85850f32019-07-19 22:05:51 +02004004 " repoint t:netrw_lexbufnr if appropriate
4005 if exists("repointlexbufnr")
4006 let t:netrw_lexbufnr= bufnr("%")
4007" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4008 endif
4009
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004010 " restore position
4011 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004012" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4013 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004014 endif
4015
Bram Moolenaara6878372014-03-22 21:02:50 +01004016 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004017 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4018 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4020" 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 +02004021" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004022 return
4023endfun
4024
4025" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004026" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4027" may not apply correctly; ie. netrw's idea of the current directory may
4028" differ from vim's. This function insures that netrw's idea of the current
4029" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004030" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004031fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004032" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4033" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4034" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4035" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4036" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004037
4038 " clean up any leading treedepthstring
4039 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4040 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004041" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042 else
4043 let fname= a:fname
4044 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004045
4046 if g:netrw_keepdir
4047 " vim's idea of the current directory possibly may differ from netrw's
4048 if !exists("b:netrw_curdir")
4049 let b:netrw_curdir= getcwd()
4050 endif
4051
4052 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004053 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004055 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004056" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004057 else
4058 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004059 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004060" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004061 endif
4062
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004063 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004064 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004065 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004066" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004067 else
4068 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004069 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004070" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004071 endif
4072 else
4073 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004074 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004075" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4076" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4077" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078 endif
4079
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004081 return ret
4082endfun
4083
4084" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004085" s:NetrwFileInfo: supports qf (query for file information) {{{2
4086fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004087" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004088 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004089 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004090 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004091 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004092 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004093 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004094 let lsopt= "-lsadh --si"
4095 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004096 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004097
4098 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004099 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004100" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004101
Bram Moolenaara6878372014-03-22 21:02:50 +01004102 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004103 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004105
4106 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004107 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004109
Bram Moolenaar446cb832008-06-24 21:56:24 +00004110 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004111" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004114 endif
4115 else
4116 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004117" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4118 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004119 let fname= substitute(a:fname,".$","","")
4120 else
4121 let fname= a:fname
4122 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 let t = getftime(s:NetrwFile(fname))
4124 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004125 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004126 let sz= s:NetrwHumanReadable(sz)
4127 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004128 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4129" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004130 endif
4131 else
4132 echo "sorry, \"qf\" not supported yet for remote files"
4133 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004134 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004135" call Dret("s:NetrwFileInfo")
4136endfun
4137
4138" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004139" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4140fun! s:NetrwFullPath(filename)
4141" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4142 let filename= a:filename
4143 if filename !~ '^/'
4144 let filename= resolve(getcwd().'/'.filename)
4145 endif
4146 if filename != "/" && filename =~ '/$'
4147 let filename= substitute(filename,'/$','','')
4148 endif
4149" " call Dret("s:NetrwFullPath <".filename.">")
4150 return filename
4151endfun
4152
4153" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004154" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004155" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004156" 1=re-used buffer (buffer not cleared)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004157fun! s:NetrwGetBuffer(islocal,dirname)
4158" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159" 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 +02004160" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4161" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004162 let dirname= a:dirname
4163
4164 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004165" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004166 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004167" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004168 let s:netrwbuf= {}
4169 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004170" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4171" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4172
4173 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4174 let bufnum = -1
4175
4176 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4177 if has_key(s:netrwbuf,"NetrwTreeListing")
4178 let bufnum= s:netrwbuf["NetrwTreeListing"]
4179 else
4180 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4181 endif
4182" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4183 if !bufexists(bufnum)
4184 call remove(s:netrwbuf,"NetrwTreeListing"])
4185 let bufnum= -1
4186 endif
4187 elseif bufnr("NetrwTreeListing") != -1
4188 let bufnum= bufnr("NetrwTreeListing")
4189" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4190 else
4191" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4192 let bufnum= -1
4193 endif
4194
4195 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004196 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004197" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004198 if !bufexists(bufnum)
4199 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4200 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004201 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004202
Bram Moolenaar446cb832008-06-24 21:56:24 +00004203 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004204" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004205 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004206 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004207" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4208
4209 " highjack the current buffer if
4210 " it has the desired name
4211 " it is empty
4212" call Decho("deciding if I can highjack the current buffer#".bufnr("%"),'~'.expand("<slnum>"))
4213" call Decho("..dirname<".dirname.">",'~'.expand("<slnum>"))
4214" call Decho("..bufname<".bufname("%").">",'~'.expand("<slnum>"))
4215" call Decho("..getline($)<".getline("$").">",'~'.expand("<slnum>"))
4216 if dirname == bufname("%") && line("$") == 1 && getline("%") == ""
4217" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4218 return 0
4219 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004220
4221 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004222 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004223" 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 +00004224 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004225" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004226 " name the buffer
4227 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4228 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004229" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004230 let w:netrw_treebufnr = bufnr("%")
4231 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004232 if g:netrw_use_noswf
4233 setl nobl bt=nofile noswf
4234 else
4235 setl nobl bt=nofile
4236 endif
4237 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4238 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4239 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4240 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004241" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004242 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004243 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004244 " enter the new buffer into the s:netrwbuf dictionary
4245 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4246" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4247" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004248 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004249" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004250
4251 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004252" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004254 setl ei=all
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004255 if getline(2) =~# '^" Netrw Directory Listing'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004256" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
4257 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004258 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004259" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
4260 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004261 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004262" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004263 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004264 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004265 endif
4266 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004267
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004268 if line("$") <= 1 && getline(1) == ""
4269 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004270 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004271" 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>"))
4272" 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 +01004273" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4274 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004275
Bram Moolenaar97d62492012-11-15 21:28:22 +01004276 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004277" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004278 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004279 sil NetrwKeepj %d _
4280" 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>"))
4281" 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 +01004282" 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 +00004283 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004284
Bram Moolenaar446cb832008-06-24 21:56:24 +00004285 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004286" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4287" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004288 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004289 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004290 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004291" 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>"))
4292" 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 +01004293" 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 +00004294 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004295
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004297" 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>"))
4298" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4299" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004300 return 1
4301 endif
4302 endif
4303
4304 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4305 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4306 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4307 " med 1 D H
4308 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004309" 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 +00004310 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004311 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004312 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004313
4314 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004315" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4316" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4317 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004319" 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>"))
4320" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4321" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004322 return 0
4323endfun
4324
4325" ---------------------------------------------------------------------
4326" s:NetrwGetcwd: get the current directory. {{{2
4327" Change backslashes to forward slashes, if any.
4328" If doesc is true, escape certain troublesome characters
4329fun! s:NetrwGetcwd(doesc)
4330" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4331 let curdir= substitute(getcwd(),'\\','/','ge')
4332 if curdir !~ '[\/]$'
4333 let curdir= curdir.'/'
4334 endif
4335 if a:doesc
4336 let curdir= fnameescape(curdir)
4337 endif
4338" call Dret("NetrwGetcwd <".curdir.">")
4339 return curdir
4340endfun
4341
4342" ---------------------------------------------------------------------
4343" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4344fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004345" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4346" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4347 let keepsol= &l:sol
4348 setl nosol
4349
Bram Moolenaar446cb832008-06-24 21:56:24 +00004350 call s:UseBufWinVars()
4351
4352 " insure that w:netrw_liststyle is set up
4353 if !exists("w:netrw_liststyle")
4354 if exists("g:netrw_liststyle")
4355 let w:netrw_liststyle= g:netrw_liststyle
4356 else
4357 let w:netrw_liststyle= s:THINLIST
4358 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004359" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360 endif
4361
4362 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4363 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004365 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 let dirname= "./"
4367 let curline= getline('.')
4368
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004369 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004370 NetrwKeepj norm! s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004371 let s:netrw_skipbrowse= 1
4372 echo 'Pressing "s" also works'
4373
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004374 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 let s:netrw_skipbrowse= 1
4376 echo 'Press "S" to edit sorting sequence'
4377
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004378 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004379 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004380 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004381
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004382 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004383 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004384 let s:netrw_skipbrowse= 1
4385 echo 'Pressing "a" also works'
4386
4387 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004388 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389 endif
4390
4391 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004392" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004393 NetrwKeepj norm! 0
4394 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004395
4396 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004397" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004398 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004399 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4400
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004401 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004402" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004403 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004404 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004405
4406 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004407" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004408 let dirname= getline('.')
4409
4410 if !exists("b:netrw_cpf")
4411 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004412 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 +01004413 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004414" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004415 endif
4416
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004417" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004418 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004419" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4420" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004422 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004423 else
4424 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004425 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 endif
4427 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004428 let eofname= filestart + b:netrw_cpf + 1
4429 if eofname <= col("$")
4430 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004431 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004432 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004433 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004434 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004435 let dirname = @a
4436 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004437" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004438 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004439" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440 endif
4441
4442 " symlinks are indicated by a trailing "@". Remove it before further processing.
4443 let dirname= substitute(dirname,"@$","","")
4444
4445 " executables are indicated by a trailing "*". Remove it before further processing.
4446 let dirname= substitute(dirname,"\*$","","")
4447
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004448 let &l:sol= keepsol
4449
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450" call Dret("s:NetrwGetWord <".dirname.">")
4451 return dirname
4452endfun
4453
4454" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004455" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4456" g:netrw_bufsettings will be used after the listing is produced.
4457" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458fun! s:NetrwListSettings(islocal)
4459" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004460" 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 +00004461 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004462" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4463 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4464 setl bt=nofile nobl ma nonu nowrap noro nornu
4465 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004466 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004467 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004468 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004469" call Dredir("ls!","s:NetrwListSettings")
4470" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004471 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004472 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004473 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004474 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004476 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004477 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004478" 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 +00004479" call Dret("s:NetrwListSettings")
4480endfun
4481
4482" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004483" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484" islocal=0: remote browsing
4485" =1: local browsing
4486fun! s:NetrwListStyle(islocal)
4487" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004488
Bram Moolenaar97d62492012-11-15 21:28:22 +01004489 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490 let fname = s:NetrwGetWord()
4491 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004492 let svpos = winsaveview()
4493" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004495" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4496" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4497" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004498
Bram Moolenaar85850f32019-07-19 22:05:51 +02004499 " repoint t:netrw_lexbufnr if appropriate
4500 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4501" call Decho("set repointlexbufnr to true!")
4502 let repointlexbufnr= 1
4503 endif
4504
Bram Moolenaar446cb832008-06-24 21:56:24 +00004505 if w:netrw_liststyle == s:THINLIST
4506 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004507" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4509
4510 elseif w:netrw_liststyle == s:LONGLIST
4511 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004513 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4514
4515 elseif w:netrw_liststyle == s:WIDELIST
4516 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004517" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4519
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004520 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004521" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004522 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4523
4524 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004525 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526 let g:netrw_liststyle = s:THINLIST
4527 let w:netrw_liststyle = g:netrw_liststyle
4528 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4529 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004530 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004531" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004532
4533 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004534" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4535 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004536 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004537" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004538 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004539" 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 +00004540
4541 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004542" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004543 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4544 NetrwKeepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004545
Bram Moolenaar85850f32019-07-19 22:05:51 +02004546 " repoint t:netrw_lexbufnr if appropriate
4547 if exists("repointlexbufnr")
4548 let t:netrw_lexbufnr= bufnr("%")
4549" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4550 endif
4551
Bram Moolenaar13600302014-05-22 18:26:40 +02004552 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004553" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4554 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004555 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004556
4557" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4558endfun
4559
4560" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004561" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4562fun! s:NetrwBannerCtrl(islocal)
4563" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4564
Bram Moolenaar97d62492012-11-15 21:28:22 +01004565 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004566 " toggle the banner (enable/suppress)
4567 let g:netrw_banner= !g:netrw_banner
4568
4569 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004570 let svpos= winsaveview()
4571" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004572 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4573
4574 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004575 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4576 let fname= s:NetrwGetWord()
4577 sil NetrwKeepj $
4578 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4579" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4580 if result <= 0 && exists("w:netrw_bannercnt")
4581 exe "NetrwKeepj ".w:netrw_bannercnt
4582 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004583 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004584 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004585" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4586endfun
4587
4588" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004589" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4590"
4591" No bang: enters files/directories into Netrw's bookmark system
4592" No argument and in netrw buffer:
4593" if there are marked files: bookmark marked files
4594" otherwise : bookmark file/directory under cursor
4595" No argument and not in netrw buffer: bookmarks current open file
4596" Has arguments: globs them individually and bookmarks them
4597"
4598" With bang: deletes files/directories from Netrw's bookmark system
4599fun! s:NetrwBookmark(del,...)
4600" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4601 if a:0 == 0
4602 if &ft == "netrw"
4603 let curbufnr = bufnr("%")
4604
4605 if exists("s:netrwmarkfilelist_{curbufnr}")
4606 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004608 let svpos = winsaveview()
4609" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004611 for fname in s:netrwmarkfilelist_{curbufnr}
4612 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4613 endfor
4614 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4615 call s:NetrwUnmarkList(curbufnr,curdir)
4616 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004617" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4618 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004619 else
4620 let fname= s:NetrwGetWord()
4621 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4622 endif
4623
4624 else
4625 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004626" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004627 let fname= expand("%")
4628 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4629 endif
4630
4631 else
4632 " bookmark specified files
4633 " attempts to infer if working remote or local
4634 " by deciding if the current file begins with an url
4635 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004636 let islocal= expand("%") !~ '^\a\{3,}://'
4637" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004638 let i = 1
4639 while i <= a:0
4640 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004641 if v:version > 704 || (v:version == 704 && has("patch656"))
4642 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004643 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004644 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004645 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004646 else
4647 let mbfiles= [a:{i}]
4648 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004649" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004650 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004651" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004652 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4653 endfor
4654 let i= i + 1
4655 endwhile
4656 endif
4657
4658 " update the menu
4659 call s:NetrwBookmarkMenu()
4660
4661" call Dret("s:NetrwBookmark")
4662endfun
4663
4664" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004665" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4666" .2.[cnt] for bookmarks, and
4667" .3.[cnt] for history
4668" (see s:NetrwMenu())
4669fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004670 if !exists("s:netrw_menucnt")
4671 return
4672 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004673" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004674
4675 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004676 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004677 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004678" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004679 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4680 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004681 endif
4682 if !exists("s:netrw_initbookhist")
4683 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004684 endif
4685
4686 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004687 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004688 let cnt= 1
4689 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004690" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004691 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004692
4693 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004694 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004695
4696 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004697 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 +01004698 let cnt= cnt + 1
4699 endfor
4700
4701 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004702
4703 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004704 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004705 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004706 let first = 1
4707 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004708 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004709 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004710 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004711 if exists("g:netrw_dirhist_{cnt}")
4712 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004713" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004714 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4715 endif
4716 let first = 0
4717 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4718 if cnt < 0
4719 let cnt= cnt + g:netrw_dirhistmax
4720 endif
4721 endwhile
4722 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004723
Bram Moolenaar9964e462007-05-05 17:54:07 +00004724 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004725" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004726endfun
4727
4728" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004729" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4730" directory and a new directory name. Also, if the
4731" "new directory name" is actually a file,
4732" NetrwBrowseChgDir() edits the file.
4733fun! s:NetrwBrowseChgDir(islocal,newdir,...)
4734" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004735" 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 +00004736
Bram Moolenaar97d62492012-11-15 21:28:22 +01004737 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004738 if !exists("b:netrw_curdir")
4739 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4740 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004741 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004742" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4743" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004744" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004745" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004746 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004747 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004748" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004749
Bram Moolenaar97d62492012-11-15 21:28:22 +01004750 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004751" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004752 call s:SavePosn(s:netrw_posn)
4753 NetrwKeepj call s:NetrwOptionsSave("s:")
4754 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004755 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004756 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004757 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004758 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004759 endif
4760 let newdir = a:newdir
4761 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004762 let dorestore = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004763" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004764" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004765
4766 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004767" 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 +01004768 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004769" call Decho("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 +01004770 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004771 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004772" 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 +01004773 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004774" 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 +02004775 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004776 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004777 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004778 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004779" 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 +01004780 endif
4781 endif
4782" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004783" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004784 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004785
Bram Moolenaar446cb832008-06-24 21:56:24 +00004786 " set up o/s-dependent directory recognition pattern
4787 if has("amiga")
4788 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004789 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004790 let dirpat= '[\/]$'
4791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004792" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004793
4794 if dirname !~ dirpat
4795 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004796 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004797 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004798" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004799 endif
4800
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004801" 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 +01004802 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004803 " ------------------------------
4804 " NetrwBrowseChgDir: edit a file {{{3
4805 " ------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004806" call Decho('(s:NetrwBrowseChgDir) edit-a-file: case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004807
Bram Moolenaar97d62492012-11-15 21:28:22 +01004808 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004809 let s:rexposn_{bufnr("%")}= winsaveview()
4810" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004811" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4812" 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 +01004813
Bram Moolenaar446cb832008-06-24 21:56:24 +00004814 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004815" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4816" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004817 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004818 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4819" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4820 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821 if dirname =~ '/$'
4822 let dirname= dirname.newdir
4823 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004824 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004825 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004826" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4827" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004828 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004829" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004830 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004831 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004832 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004833 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004834" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004835 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004836 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004837" 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 +02004838 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004839 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004840 if !exists("s:didsplit")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004841" call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004842 if type(g:netrw_browse_split) == 3
4843 " open file in server
4844 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004845" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004846 call s:NetrwServerEdit(a:islocal,dirname)
4847" call Dret("s:NetrwBrowseChgDir")
4848 return
4849 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004850 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004851" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004852 keepalt new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004853 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004854 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004855 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004856 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004857 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004858 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004859" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004860 keepalt rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004861 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004862 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004863 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004864 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004866 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004867" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004868 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004869 if !exists("b:netrw_curdir")
4870 let b:netrw_curdir= getcwd()
4871 endif
4872 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004874 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004875" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004876 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004877 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004878" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004879 return
4880 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004881 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004882 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004883 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004884" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004885 call s:NetrwMenu(0)
4886 " optional change to window
4887 if g:netrw_chgwin >= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004888" call Decho("edit-a-file: changing window to #".g:netrw_chgwin,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004889 if winnr("$")+1 == g:netrw_chgwin
4890 " if g:netrw_chgwin is set to one more than the last window, then
4891 " vertically split the last window to make that window available.
4892 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004893 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004894 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004895 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004896 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004897 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004898 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004899 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004900 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004901 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004902
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 " the point where netrw actually edits the (local) file
4904 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004905 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004907" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004908 " some like c-^ to return to the last edited file
4909 " others like c-^ to return to the netrw buffer
4910 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004911 exe "NetrwKeepj keepalt e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004912 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004913 exe "NetrwKeepj e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004914 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004915" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004916 call s:NetrwCursor()
Bram Moolenaar13600302014-05-22 18:26:40 +02004917 if &hidden || &bufhidden == "hide"
4918 " file came from vim's hidden storage. Don't "restore" options with it.
4919 let dorestore= 0
4920 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004921 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004922" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004923 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004924 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01004925
4926 " handle g:Netrw_funcref -- call external-to-netrw functions
4927 " This code will handle g:Netrw_funcref as an individual function reference
4928 " or as a list of function references. It will ignore anything that's not
4929 " a function reference. See :help Funcref for information about function references.
4930 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004931" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004932 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004933" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004934 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004935 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004936" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004937 for Fncref in g:Netrw_funcref
4938 if type(FncRef) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004939 NetrwKeepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004940 endif
4941 endfor
4942 endif
4943 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004944 endif
4945
4946 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004947 " ----------------------------------------------------
4948 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4949 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004950" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004951 let dirname = newdir
4952 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004953 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004954 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004955
4956 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004957 " ---------------------------------------------
4958 " NetrwBrowseChgDir: refresh the directory list {{{3
4959 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004960" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004961 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004962 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963
4964 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004965 " --------------------------------------
4966 " NetrwBrowseChgDir: go up one directory {{{3
4967 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004968" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004969
4970 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4971 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004972" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4973" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004974 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004975 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004976 endif
4977
4978 if has("amiga")
4979 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004980" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004981 if a:islocal
4982 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4983 let dirname= substitute(dirname,'/$','','')
4984 else
4985 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4986 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004987" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004988
Bram Moolenaar8d043172014-01-23 14:24:41 +01004989 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
4990 " windows
4991 if a:islocal
4992 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4993 if dirname == ""
4994 let dirname= '/'
4995 endif
4996 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004997 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004998 endif
4999 if dirname =~ '^\a:$'
5000 let dirname= dirname.'/'
5001 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005002" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005003
Bram Moolenaar446cb832008-06-24 21:56:24 +00005004 else
5005 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005006" 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 +00005007 if a:islocal
5008 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5009 if dirname == ""
5010 let dirname= '/'
5011 endif
5012 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005013 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005014 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005015" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005016 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005017 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005018 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005019
5020 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005021 " --------------------------------------
5022 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5023 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005024" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5026" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005027 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005028 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005029" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5030 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005031 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005032 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005033" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005034 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005035 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005036" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005037
5038 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005039" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005040 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005041" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005042 let haskey= 1
5043 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005044" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005045 endif
5046
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005047 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005048" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005049 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005050 if has_key(w:netrw_treedict,treedir."/")
5051 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005052" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005053 let haskey = 1
5054 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005055" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005056 endif
5057 endif
5058
5059 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005060" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005061 if !haskey && treedir =~ '/$'
5062 let treedir= substitute(treedir,'/$','','')
5063 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005064" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005065 let haskey = 1
5066 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005067" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068 endif
5069 endif
5070
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005071" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005072 if haskey
5073 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005074" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005075 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005076" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5077" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005078 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005079 else
5080 " go down one directory
5081 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005082" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5083" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005084 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005085 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005086" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005087 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005088
5089 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005090 " ----------------------------------------
5091 " NetrwBrowseChgDir: Go down one directory {{{3
5092 " ----------------------------------------
5093 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005094" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005095 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005096 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005097 endif
5098
Bram Moolenaar97d62492012-11-15 21:28:22 +01005099 " --------------------------------------
5100 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5101 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005102 if dorestore
5103 " dorestore is zero'd when a local file was hidden or bufhidden;
5104 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005106 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005107" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005108" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005109 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005110 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005111" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005112 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5114" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005115 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005116" 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 +02005117 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005118" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5119" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005120 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005121" 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 +02005122 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005123 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005124 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005125 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005126
Bram Moolenaar446cb832008-06-24 21:56:24 +00005127" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5128 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005129endfun
5130
5131" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005132" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5133" for thin, long, and wide: cursor placed just after banner
5134" for tree, keeps cursor on current filename
5135fun! s:NetrwBrowseUpDir(islocal)
5136" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005137 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5138 " this test needed because occasionally this function seems to be incorrectly called
5139 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005140 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005141 " directories.
5142" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5143 return
5144 endif
5145
Bram Moolenaara6878372014-03-22 21:02:50 +01005146 norm! 0
5147 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005148" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005149 let curline= getline(".")
5150 let swwline= winline() - 1
5151 if exists("w:netrw_treetop")
5152 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005153 elseif exists("b:netrw_curdir")
5154 let w:netrw_treetop= b:netrw_curdir
5155 else
5156 let w:netrw_treetop= getcwd()
5157 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005158 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005159 let curfile = getline(".")
5160 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005161 if a:islocal
5162 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5163 else
5164 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5165 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005166" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5167" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5168 if w:netrw_treetop == '/'
5169 keepj call search('^\M'.curfile,"w")
5170 elseif curfile == '../'
5171 keepj call search('^\M'.curfile,"wb")
5172 else
5173" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5174 while 1
5175 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5176 let treepath= s:NetrwTreePath(w:netrw_treetop)
5177" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5178 if treepath == curpath
5179 break
5180 endif
5181 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005182 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005183
Bram Moolenaara6878372014-03-22 21:02:50 +01005184 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005185" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005186 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005187 if exists("b:netrw_curdir")
5188 let curdir= b:netrw_curdir
5189 else
5190 let curdir= expand(getcwd())
5191 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005192 if a:islocal
5193 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5194 else
5195 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5196 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005197 call s:RestorePosn(s:netrw_posn)
5198 let curdir= substitute(curdir,'^.*[\/]','','')
5199 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005200 endif
5201" call Dret("s:NetrwBrowseUpDir")
5202endfun
5203
5204" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005205" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005206" given filename; typically this means given their extension.
5207" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005208fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005209 let use_ctrlo= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005210" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.")")
5211
Bram Moolenaar85850f32019-07-19 22:05:51 +02005212 " if its really just a local directory, then do a "gf" instead
5213 if (a:remote == 0 && isdirectory(a:fname)) || (a:remote == 1 && a:fname =~ '/$' && a:fname !~ '^https\=:')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005214 norm! gf
Bram Moolenaar85850f32019-07-19 22:05:51 +02005215" call Dret("(netrw#BrowseX) did gf instead")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005216 endif
5217
Bram Moolenaar97d62492012-11-15 21:28:22 +01005218 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005219 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005220" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005221
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005222 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5223 let awkeep = &aw
5224 set noaw
5225
Bram Moolenaar5c736222010-01-06 20:54:52 +01005226 " special core dump handler
5227 if a:fname =~ '/core\(\.\d\+\)\=$'
5228 if exists("g:Netrw_corehandler")
5229 if type(g:Netrw_corehandler) == 2
5230 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005231" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005232 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005233 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005234 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005235" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005236 for Fncref in g:Netrw_corehandler
5237 if type(FncRef) == 2
5238 call FncRef(a:fname)
5239 endif
5240 endfor
5241 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005242" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005243 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005244 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005245 let &aw= awkeep
5246" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005247 return
5248 endif
5249 endif
5250
Bram Moolenaar446cb832008-06-24 21:56:24 +00005251 " set up the filename
5252 " (lower case the extension, make a local copy of a remote file)
5253 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5254 if has("win32") || has("win95") || has("win64") || has("win16")
5255 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005256 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005257 if exten =~ "[\\/]"
5258 let exten= ""
5259 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005260" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005261
Bram Moolenaar446cb832008-06-24 21:56:24 +00005262 if a:remote == 1
5263 " create a local copy
Bram Moolenaar46973992017-12-14 19:56:46 +01005264" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005265 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005266 call netrw#NetRead(3,a:fname)
5267 " attempt to rename tempfile
5268 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005269 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005270" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5271" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005272 if s:netrw_tmpfile != newname && newname != ""
5273 if rename(s:netrw_tmpfile,newname) == 0
5274 " renaming succeeded
5275" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5276 let fname= newname
5277 else
5278 " renaming failed
5279" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5280 let fname= s:netrw_tmpfile
5281 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005282 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005283 let fname= s:netrw_tmpfile
5284 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005285 else
Bram Moolenaar46973992017-12-14 19:56:46 +01005286" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005287 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005288 " special ~ handler for local
5289 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005290" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5291 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005292 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005293 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005294" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5295" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005296
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005297 " set up redirection (avoids browser messages)
5298 " by default, g:netrw_suppress_gx_mesg is true
5299 if g:netrw_suppress_gx_mesg
5300 if &srr =~ "%s"
5301 if (has("win32") || has("win95") || has("win64") || has("win16"))
5302 let redir= substitute(&srr,"%s","nul","")
5303 else
5304 let redir= substitute(&srr,"%s","/dev/null","")
5305 endif
5306 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5307 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005308 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005309 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005310 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005311 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005312" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005313
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005314 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005315 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005316" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005317 if g:netrw_browsex_viewer =~ '\s'
5318 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5319 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5320 let oviewer = ''
5321 let cnt = 1
5322 while !executable(viewer) && viewer != oviewer
5323 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5324 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5325 let cnt = cnt + 1
5326 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005327" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005328 endwhile
5329 else
5330 let viewer = g:netrw_browsex_viewer
5331 let viewopt = ""
5332 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005333" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005334 endif
5335
5336 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005337" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005338 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005339" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005340 let ret= netrwFileHandlers#Invoke(exten,fname)
5341
5342 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005343" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005344 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005345 let ret= v:shell_error
5346
5347 elseif has("win32") || has("win64")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005348" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005349 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005350 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005351 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005352 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005353 else
5354 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5355 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005356 let ret= v:shell_error
5357
Bram Moolenaar97d62492012-11-15 21:28:22 +01005358 elseif has("win32unix")
5359 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005360" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005361 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005362" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005363 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005364 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005365" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005366 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005367 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005368" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005369 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005370 else
5371 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5372 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005373 let ret= v:shell_error
5374
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005375 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005376" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005377 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005378 let ret= v:shell_error
5379
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005380 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005381" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005382 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir)
5383 let ret= v:shell_error
5384
Bram Moolenaar85850f32019-07-19 22:05:51 +02005385 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005386" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5387 if a:fname =~ '^https\=://'
5388 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5389 let use_ctrlo= 0
5390" call Decho("(COMBAK) fname<".fname.">")
5391" call Decho("(COMBAK) a:fname<".a:fname.">")
5392 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5393
5394 else
5395 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5396 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005397 let ret= v:shell_error
5398
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005399 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005400" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005401 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402 let ret= v:shell_error
5403
5404 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005405" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005406 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005407 let ret= v:shell_error
5408
5409 else
5410 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005411" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005412 let ret= netrwFileHandlers#Invoke(exten,fname)
5413 endif
5414
5415 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5416 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005417" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418 let ret= netrwFileHandlers#Invoke(exten,fname)
5419 endif
5420
Bram Moolenaarc236c162008-07-13 17:41:49 +00005421 " restoring redraw! after external file handlers
5422 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005423
5424 " cleanup: remove temporary file,
5425 " delete current buffer if success with handler,
5426 " return to prior buffer (directory listing)
5427 " Feb 12, 2008: had to de-activiate removal of
5428 " temporary file because it wasn't getting seen.
5429" if a:remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005430"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005431" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005432" endif
5433
5434 if a:remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005435 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005437 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005438 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005439 if use_ctrlo
5440 exe "sil! NetrwKeepj norm! \<c-o>"
5441 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005442 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005443" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005444 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005445 let @@ = ykeep
5446 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005447
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005448" call Dret("netrw#BrowseX")
5449endfun
5450
5451" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005452" netrw#GX: gets word under cursor for gx support {{{2
5453" See also: netrw#BrowseXVis
5454" netrw#BrowseX
5455fun! netrw#GX()
5456" call Dfunc("netrw#GX()")
5457 if &ft == "netrw"
5458 let fname= s:NetrwGetWord()
5459 else
5460 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5461 endif
5462" call Dret("netrw#GX <".fname.">")
5463 return fname
5464endfun
5465
5466" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005467" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5468fun! netrw#BrowseXVis()
5469" call Dfunc("netrw#BrowseXVis()")
5470 let atkeep = @@
5471 norm! gvy
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005472" call Decho("@@<".@@.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005473 call netrw#BrowseX(@@,netrw#CheckIfRemote(@@))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005474 let @@ = atkeep
5475" call Dret("netrw#BrowseXVis")
5476endfun
5477
5478" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005479" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5480" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5481" to become an unlisted buffer, so in that case don't bwipe it.
5482fun! s:NetrwBufRename(newname)
5483" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5484" call Dredir("ls!","s:NetrwBufRename (before rename)")
5485 let oldbufname= bufname(bufnr("%"))
5486" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5487
5488 if oldbufname != a:newname
5489" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5490 let b:junk= 1
5491" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5492 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
5493" call Dredir("ls!","s:NetrwBufRename (before bwipe)")
5494 let oldbufnr= bufnr(oldbufname)
5495" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5496" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5497 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5498" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5499 exe "bwipe! ".oldbufnr
5500" else " Decho
5501" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
5502 endif
5503" call Dredir("ls!","s:NetrwBufRename (after rename)")
5504" else " Decho
5505" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5506 endif
5507
5508" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5509endfun
5510
5511" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005512" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005513fun! netrw#CheckIfRemote(...)
5514" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5515 if a:0 > 0
5516 let curfile= a:1
5517 else
5518 let curfile= expand("%")
5519 endif
5520" call Decho("curfile<".curfile.">")
5521 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005522" call Dret("netrw#CheckIfRemote 1")
5523 return 1
5524 else
5525" call Dret("netrw#CheckIfRemote 0")
5526 return 0
5527 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005528endfun
5529
5530" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005531" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5532fun! s:NetrwChgPerm(islocal,curdir)
5533" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005534 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005535 call inputsave()
5536 let newperm= input("Enter new permission: ")
5537 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005538 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5539 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5540" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005541 call system(chgperm)
5542 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005543 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005544 endif
5545 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005546 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005547 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005548 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005549" call Dret("s:NetrwChgPerm")
5550endfun
5551
5552" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005553" s:CheckIfKde: checks if kdeinit is running {{{2
5554" Returns 0: kdeinit not running
5555" 1: kdeinit is running
5556fun! s:CheckIfKde()
5557" call Dfunc("s:CheckIfKde()")
5558 " seems kde systems often have gnome-open due to dependencies, even though
5559 " gnome-open's subsidiary display tools are largely absent. Kde systems
5560 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5561 if !exists("s:haskdeinit")
5562 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005563 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005564 if v:shell_error
5565 let s:haskdeinit = 0
5566 endif
5567 else
5568 let s:haskdeinit= 0
5569 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005570" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005571 endif
5572
5573" call Dret("s:CheckIfKde ".s:haskdeinit)
5574 return s:haskdeinit
5575endfun
5576
5577" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005578" s:NetrwClearExplore: clear explore variables (if any) {{{2
5579fun! s:NetrwClearExplore()
5580" call Dfunc("s:NetrwClearExplore()")
5581 2match none
5582 if exists("s:explore_match") |unlet s:explore_match |endif
5583 if exists("s:explore_indx") |unlet s:explore_indx |endif
5584 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5585 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5586 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5587 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5588 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5589 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5590 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5591" redraw!
5592 echo " "
5593 echo " "
5594" call Dret("s:NetrwClearExplore")
5595endfun
5596
5597" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005598" s:NetrwExploreListUniq: {{{2
5599fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005600" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005601
5602 " this assumes that the list is already sorted
5603 let newexplist= []
5604 for member in a:explist
5605 if !exists("uniqmember") || member != uniqmember
5606 let uniqmember = member
5607 let newexplist = newexplist + [ member ]
5608 endif
5609 endfor
5610
Bram Moolenaar15146672011-10-20 22:22:38 +02005611" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005612 return newexplist
5613endfun
5614
5615" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005616" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5617fun! s:NetrwForceChgDir(islocal,newdir)
5618" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005619 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005620 if a:newdir !~ '/$'
5621 " ok, looks like force is needed to get directory-style treatment
5622 if a:newdir =~ '@$'
5623 let newdir= substitute(a:newdir,'@$','/','')
5624 elseif a:newdir =~ '[*=|\\]$'
5625 let newdir= substitute(a:newdir,'.$','/','')
5626 else
5627 let newdir= a:newdir.'/'
5628 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005629" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005630 else
5631 " should already be getting treatment as a directory
5632 let newdir= a:newdir
5633 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005634 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005635 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005636 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005637" call Dret("s:NetrwForceChgDir")
5638endfun
5639
5640" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005641" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005642" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5643" expr : this is the expression to follow the directory. Will use s:ComposePath()
5644" pare =1: remove the current directory from the resulting glob() filelist
5645" =0: leave the current directory in the resulting glob() filelist
5646fun! s:NetrwGlob(direntry,expr,pare)
5647" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005648 if netrw#CheckIfRemote()
5649 keepalt 1sp
5650 keepalt enew
5651 let keep_liststyle = w:netrw_liststyle
5652 let w:netrw_liststyle = s:THINLIST
5653 if s:NetrwRemoteListing() == 0
5654 keepj keepalt %s@/@@
5655 let filelist= getline(1,$)
5656 q!
5657 else
5658 " remote listing error -- leave treedict unchanged
5659 let filelist= w:netrw_treedict[a:direntry]
5660 endif
5661 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005662 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5663 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5664 if a:pare
5665 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5666 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005667 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005668 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5669 if a:pare
5670 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5671 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005672 endif
5673" call Dret("s:NetrwGlob ".string(filelist))
5674 return filelist
5675endfun
5676
5677" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005678" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5679fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005680" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005681 if a:newfile =~ '[/@*=|\\]$'
5682 let newfile= substitute(a:newfile,'.$','','')
5683 else
5684 let newfile= a:newfile
5685 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005686 if a:islocal
5687 call s:NetrwBrowseChgDir(a:islocal,newfile)
5688 else
5689 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5690 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005691" call Dret("s:NetrwForceFile")
5692endfun
5693
5694" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005695" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5696" and switches the hiding mode. The actual hiding is done by
5697" s:NetrwListHide().
5698" g:netrw_hide= 0: show all
5699" 1: show not-hidden files
5700" 2: show hidden files only
5701fun! s:NetrwHide(islocal)
5702" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005703 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005704 let svpos= winsaveview()
5705" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005706
5707 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005708" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5709" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005710
5711 " hide the files in the markfile list
5712 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005713" 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 +00005714 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5715 " remove fname from hiding list
5716 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5717 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5718 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005719" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005720 else
5721 " append fname to hiding list
5722 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5723 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5724 else
5725 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5726 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005727" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005728 endif
5729 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005730 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005731 let g:netrw_hide= 1
5732
5733 else
5734
5735 " switch between show-all/show-not-hidden/show-hidden
5736 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005737 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005738 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005739 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005740 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005741" call Dret("NetrwHide")
5742 return
5743 endif
5744 endif
5745
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005746 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005747" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5748 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005749 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005750" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005751endfun
5752
5753" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005754" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5755fun! s:NetrwHideEdit(islocal)
5756" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5757
5758 let ykeep= @@
5759 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005760 let svpos= winsaveview()
5761" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005762
5763 " get new hiding list from user
5764 call inputsave()
5765 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5766 call inputrestore()
5767 let g:netrw_list_hide= newhide
5768" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5769
5770 " refresh the listing
5771 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5772
5773 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005774" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5775 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005776 let @@= ykeep
5777
5778" call Dret("NetrwHideEdit")
5779endfun
5780
5781" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005782" s:NetrwHidden: invoked by "gh" {{{2
5783fun! s:NetrwHidden(islocal)
5784" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005785 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005786 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005787 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005788" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005789
5790 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005791 " remove .file pattern from hiding list
5792" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005793 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005794 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005795" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005796 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5797 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005798" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005799 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5800 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005801 if g:netrw_list_hide =~ '^,'
5802 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5803 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005804
5805 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005806 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005807" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5808 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005809 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005810" call Dret("s:NetrwHidden")
5811endfun
5812
5813" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005814" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5815fun! s:NetrwHome()
5816 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005817 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005818 else
5819 " go to vim plugin home
5820 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005821 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005822 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005823 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005824 let home= basehome."/.vim"
5825 break
5826 endif
5827 endfor
5828 if home == ""
5829 " just pick the first directory
5830 let home= substitute(&rtp,',.*$','','')
5831 endif
5832 if (has("win32") || has("win95") || has("win64") || has("win16"))
5833 let home= substitute(home,'/','\\','g')
5834 endif
5835 endif
5836 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005837 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005838" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005839 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005840" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005841 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005842 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005843" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005844 call mkdir(home)
5845 endif
5846 endif
5847 let g:netrw_home= home
5848 return home
5849endfun
5850
5851" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005852" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5853fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005854 if exists("s:netrwdrag")
5855 return
5856 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005857 if &ft != "netrw"
5858 return
5859 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005860" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005861
Bram Moolenaar97d62492012-11-15 21:28:22 +01005862 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005863 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005864 while getchar(0) != 0
5865 "clear the input stream
5866 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005867 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005868 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005869 let mouse_lnum = v:mouse_lnum
5870 let wlastline = line('w$')
5871 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005872" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5873" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005874 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5875 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005876 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005877" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5878 return
5879 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005880 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005881 " 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 +01005882 " without this test when its disabled.
5883 " 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 +01005884" 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 +01005885 if v:mouse_col > virtcol('.')
5886 let @@= ykeep
5887" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5888 return
5889 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005890
Bram Moolenaar446cb832008-06-24 21:56:24 +00005891 if a:islocal
5892 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005893 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005894 endif
5895 else
5896 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005897 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898 endif
5899 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005900 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005901" call Dret("s:NetrwLeftmouse")
5902endfun
5903
5904" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005905" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5906fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005907 if &ft != "netrw"
5908 return
5909 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005910" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5911 call s:NetrwMarkFileTgt(a:islocal)
5912" call Dret("s:NetrwCLeftmouse")
5913endfun
5914
5915" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005916" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5917" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005918" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005919" a:islocal=2 : <c-r> used, remote
5920" a:islocal=3 : <c-r> used, local
5921fun! s:NetrwServerEdit(islocal,fname)
5922" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5923 let islocal = a:islocal%2 " =0: remote =1: local
5924 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005925" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005926
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005927 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005928 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005929 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005930" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005931 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005932 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005933 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5934 unlet s:netrw_browse_split_{winnr()}
5935 endif
5936 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5937" call Dret("s:NetrwServerEdit")
5938 return
5939 endif
5940
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005941" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005942 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005943" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005944
5945 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005946" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005947 let srvrname = g:netrw_browse_split[0]
5948 let tabnum = g:netrw_browse_split[1]
5949 let winnum = g:netrw_browse_split[2]
5950
5951 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005952" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005953
5954 if !ctrlr
5955 " user must have closed the server window and the user did not use <c-r>, but
5956 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005957" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005958 if exists("g:netrw_browse_split")
5959 unlet g:netrw_browse_split
5960 endif
5961 let g:netrw_browse_split= 0
5962 if exists("s:netrw_browse_split_".winnr())
5963 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5964 endif
5965 call s:NetrwBrowseChgDir(islocal,a:fname)
5966" call Dret("s:NetrwServerEdit")
5967 return
5968
5969 elseif has("win32") && executable("start")
5970 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005971" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005972 call system("start gvim --servername ".srvrname)
5973
5974 else
5975 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005976" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005977 call system("gvim --servername ".srvrname)
5978 endif
5979 endif
5980
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005981" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005982 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5983 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005984 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005985
5986 else
5987
5988 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5989
5990 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005991" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005992 if exists("g:netrw_browse_split")
5993 unlet g:netrw_browse_split
5994 endif
5995 let g:netrw_browse_split= 0
5996 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5997" call Dret("s:NetrwServerEdit")
5998 return
5999
6000 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006001" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006002 if has("win32") && executable("start")
6003 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006004" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006005 call system("start gvim --servername ".g:netrw_servername)
6006 else
6007 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006008" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006009 call system("gvim --servername ".g:netrw_servername)
6010 endif
6011 endif
6012 endif
6013
6014 while 1
6015 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006016" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6017 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006018 break
6019 catch /^Vim\%((\a\+)\)\=:E241/
6020 sleep 200m
6021 endtry
6022 endwhile
6023
6024 if exists("g:netrw_browse_split")
6025 if type(g:netrw_browse_split) != 3
6026 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6027 endif
6028 unlet g:netrw_browse_split
6029 endif
6030 let g:netrw_browse_split= [g:netrw_servername,1,1]
6031 endif
6032
6033 else
6034 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6035 endif
6036
6037" call Dret("s:NetrwServerEdit")
6038endfun
6039
6040" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006041" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6042fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006043 if &ft != "netrw"
6044 return
6045 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006046" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006047
Bram Moolenaar8d043172014-01-23 14:24:41 +01006048 let s:ngw= s:NetrwGetWord()
6049 call s:NetrwMarkFile(a:islocal,s:ngw)
6050
6051" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006052endfun
6053
6054" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006055" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6056" Used to mark multiple files.
6057fun! s:NetrwSLeftdrag(islocal)
6058" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6059 if !exists("s:netrwdrag")
6060 let s:netrwdrag = winnr()
6061 if a:islocal
6062 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006063 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006064 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006065 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006066 endif
6067 let ngw = s:NetrwGetWord()
6068 if !exists("s:ngw") || s:ngw != ngw
6069 call s:NetrwMarkFile(a:islocal,ngw)
6070 endif
6071 let s:ngw= ngw
6072" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6073endfun
6074
6075" ---------------------------------------------------------------------
6076" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6077fun! s:NetrwSLeftrelease(islocal)
6078" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6079 if exists("s:netrwdrag")
6080 nunmap <s-leftrelease>
6081 let ngw = s:NetrwGetWord()
6082 if !exists("s:ngw") || s:ngw != ngw
6083 call s:NetrwMarkFile(a:islocal,ngw)
6084 endif
6085 if exists("s:ngw")
6086 unlet s:ngw
6087 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006088 unlet s:netrwdrag
6089 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006090" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006091endfun
6092
6093" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006094" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
6095" separated patterns given in g:netrw_list_hide
6096fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006097" 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 +02006098" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006099 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006100
6101 " 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 +02006102 " How-it-works: take the hiding command, convert it into a range.
6103 " Duplicate characters don't matter.
6104 " Remove all such characters from the '/~@#...890' string.
6105 " Use the first character left as a separator character.
6106" call Decho("find a character not in the hide string to use as a separator")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006107 let listhide= g:netrw_list_hide
6108 let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006109" call Decho("sep=".sep,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006110
6111 while listhide != ""
6112 if listhide =~ ','
6113 let hide = substitute(listhide,',.*$','','e')
6114 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6115 else
6116 let hide = listhide
6117 let listhide = ""
6118 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006119" call Decho("hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006120
6121 " Prune the list by hiding any files which match
Bram Moolenaar85850f32019-07-19 22:05:51 +02006122" 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 +00006123 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006124" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006125 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006126 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006127" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006128 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006129 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006130" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006131 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006132
Bram Moolenaar446cb832008-06-24 21:56:24 +00006133 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006134 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006135" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006136 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006137" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006138 endif
6139
Bram Moolenaaradc21822011-04-01 18:03:16 +02006140 " remove any blank lines that have somehow remained.
6141 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006142 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006143
Bram Moolenaar97d62492012-11-15 21:28:22 +01006144 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006145" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006146endfun
6147
6148" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006149" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006150" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006151fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006152" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006153
Bram Moolenaar97d62492012-11-15 21:28:22 +01006154 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006155 " get name of new directory from user. A bare <CR> will skip.
6156 " if its currently a directory, also request will be skipped, but with
6157 " a message.
6158 call inputsave()
6159 let newdirname= input("Please give directory name: ")
6160 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006161" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006162
6163 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006164 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006165" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006166 return
6167 endif
6168
6169 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006170" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006171
6172 " Local mkdir:
6173 " sanity checks
6174 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006175" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6176 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006177 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006178 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006179 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006180 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006181" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006182 return
6183 endif
6184 if s:FileReadable(fullnewdir)
6185 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006186 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006187 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006188 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006189" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006190 return
6191 endif
6192
6193 " requested new local directory is neither a pre-existing file or
6194 " directory, so make it!
6195 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006196 if has("unix")
6197 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6198 else
6199 call mkdir(fullnewdir,"p")
6200 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006201 else
6202 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006203 if s:NetrwLcd(b:netrw_curdir)
6204" call Dret("s:NetrwMakeDir : lcd failure")
6205 return
6206 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006207" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006208 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006209 if v:shell_error != 0
6210 let @@= ykeep
6211 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 +01006212" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006213 return
6214 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006215 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006216" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006217 if s:NetrwLcd(netrw_origdir)
6218" call Dret("s:NetrwBrowse : lcd failure")
6219 return
6220 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006221 endif
6222 endif
6223
6224 if v:shell_error == 0
6225 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006226" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006227 let svpos= winsaveview()
6228" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006229 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006230" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6231 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006232 elseif !exists("g:netrw_quiet")
6233 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6234 endif
6235" redraw!
6236
6237 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006238 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006239" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006240 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6241 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006242 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006243 if v:shell_error == 0
6244 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006245 let svpos= winsaveview()
6246" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006247 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006248" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6249 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006250 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006251 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006252 endif
6253" redraw!
6254
6255 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006256 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006257 let svpos= winsaveview()
6258" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006259" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006260 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006261" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006262 let remotepath= b:netrw_fname
6263 else
6264 let remotepath= ""
6265 endif
6266 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006267 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006268" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6269 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006270
Bram Moolenaar446cb832008-06-24 21:56:24 +00006271 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006272 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006273 let svpos= winsaveview()
6274" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006275" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006276 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006277" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006278 let remotepath= b:netrw_fname
6279 else
6280 let remotepath= ""
6281 endif
6282 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006283 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006284" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6285 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286 endif
6287
Bram Moolenaar97d62492012-11-15 21:28:22 +01006288 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006289" call Dret("s:NetrwMakeDir")
6290endfun
6291
6292" ---------------------------------------------------------------------
6293" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6294fun! s:TreeSqueezeDir(islocal)
6295" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6296 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6297 " its a tree-listing style
6298 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006299 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006300 let depth = strchars(substitute(curdepth,' ','','g'))
6301 let srch = -1
6302" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6303" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006304" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006305" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6306 if depth >= 2
6307 NetrwKeepj norm! 0
6308 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6309 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6310" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6311" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6312 elseif depth == 1
6313 NetrwKeepj norm! 0
6314 let treedepthchr= substitute(s:treedepthstring,' ','','')
6315 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6316" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6317 endif
6318 if srch > 0
6319" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6320 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6321 exe srch
6322 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006323 endif
6324" call Dret("s:TreeSqueezeDir")
6325endfun
6326
6327" ---------------------------------------------------------------------
6328" s:NetrwMaps: {{{2
6329fun! s:NetrwMaps(islocal)
6330" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6331
Bram Moolenaar85850f32019-07-19 22:05:51 +02006332 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006333 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006334" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006335 if !hasmapto("<Plug>NetrwReturn")
6336 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006337" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006338 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6339 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006340" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006341 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6342 endif
6343 endif
6344 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006345" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006346 endif
6347
Bram Moolenaar85850f32019-07-19 22:05:51 +02006348 " generate default <Plug> maps {{{3
6349 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006350 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006351 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6352 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6353 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6354 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6355 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6356 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6357 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6358 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6359 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6360 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6361" ---------------------------------------------------------------------
6362" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6363" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6364" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6365" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6366" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6367" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6368" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6369" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6370" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6371" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6372" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6373" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6374" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6375" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6376" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6377" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6378" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6379" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6380" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6381" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6382" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6383" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6384" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6385" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6386" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6387" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6388" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6389" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6390" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6391" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6392" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6393" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6394" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6395" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6396" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6397" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6398" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6399" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6400" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6401" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6402" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6403" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6404" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6405" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6406" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6407" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6408" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6409
Bram Moolenaara6878372014-03-22 21:02:50 +01006410 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006411" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006412 " local normal-mode maps {{{3
6413 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6414 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6415 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6416 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6417 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6418 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6419 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6420 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6421 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6422 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6423 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6424" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6426 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6427 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006428 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006429 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006430 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6431 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6432 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6433 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006434 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6435 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6436 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6437 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6438 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6439 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6440 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6441 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6442 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6443 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6444 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6445 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6446 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006447 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006448 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006449 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6450 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6451 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6452 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6453 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006454 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006455 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006456 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6457 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006458 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6459 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6460 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006461 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006462 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006463 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6464 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006465 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006466 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006467 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6468 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6469 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006470 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6471 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006472
6473 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 +01006474 if !hasmapto('<Plug>NetrwHideEdit')
6475 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006476 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006477 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006478 if !hasmapto('<Plug>NetrwRefresh')
6479 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006480 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006481 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006482 if s:didstarstar || !mapcheck("<s-down>","n")
6483 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006484 endif
6485 if s:didstarstar || !mapcheck("<s-up>","n")
6486 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006487 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006488 if !hasmapto('<Plug>NetrwTreeSqueeze')
6489 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006490 endif
6491 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006492 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6493 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006494 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6495 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6496 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6497 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6498 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6499 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6500 imap <buffer> <leftmouse> <Plug>ILeftmouse
6501 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006502 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006503 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006504 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006505 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006506 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006507 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006508 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6509 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006510 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006511 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6512 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6513 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6514 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6515 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6516 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6517 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006518 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6519
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006520 " support user-specified maps
6521 call netrw#UserMaps(1)
6522
Bram Moolenaar85850f32019-07-19 22:05:51 +02006523 else
6524 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006525" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006526 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006527 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6528 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6529 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6530 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6531 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6532 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6533 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6534 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6535 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6536 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6537 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6538" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006539 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6540 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6541 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6542 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6543 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6544 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6545 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6546 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006547 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006548 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006549 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6550 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6551 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6552 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6553 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6554 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6555 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6556 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6557 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6558 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6559 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006560 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006561 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006562 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6563 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6564 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6565 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6566 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006567 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6568 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6569 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6570 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006571 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006572 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6573 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006574 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006575 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 +01006576 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6577 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6578 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6579 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6580 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6581 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6582 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6583 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6584 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006585 if !hasmapto('<Plug>NetrwHideEdit')
6586 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006587 endif
6588 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6589 if !hasmapto('<Plug>NetrwRefresh')
6590 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006591 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006592 if !hasmapto('<Plug>NetrwTreeSqueeze')
6593 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006594 endif
6595 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006596
6597 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006598 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006599
6600 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6601 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6603 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6604 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6605 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6606 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6607 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6608 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6609 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6610 nmap <middlemouse> <Plug>NetrwMiddlemouse
6611 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6612 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6613 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6614 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006616 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006617 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6618 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006619 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006620 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6621 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6622 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6623 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6624 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6625 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6626 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006627 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006628
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006629 " support user-specified maps
6630 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006631 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006632
6633" call Dret("s:NetrwMaps")
6634endfun
6635
6636" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006637" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006638" If -buffer, the command is only available from within netrw buffers
6639" Otherwise, the command is available from any window, so long as netrw
6640" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006641fun! s:NetrwCommands(islocal)
6642" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6643
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006644 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6645 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 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 +01006647 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006648 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006649 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006650 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006651 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006652 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006653
6654" call Dret("s:NetrwCommands")
6655endfun
6656
6657" ---------------------------------------------------------------------
6658" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6659" glob()ing only works with local files
6660fun! s:NetrwMarkFiles(islocal,...)
6661" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006662 let curdir = s:NetrwGetCurdir(a:islocal)
6663 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006664 while i <= a:0
6665 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006666 if v:version > 704 || (v:version == 704 && has("patch656"))
6667 let mffiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006668 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006669 let mffiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006670 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006671 else
6672 let mffiles= [a:{i}]
6673 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006674" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006675 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006676" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006677 call s:NetrwMarkFile(a:islocal,mffile)
6678 endfor
6679 let i= i + 1
6680 endwhile
6681" call Dret("s:NetrwMarkFiles")
6682endfun
6683
6684" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006685" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006686fun! s:NetrwMarkTarget(...)
6687" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6688 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006689 let curdir = s:NetrwGetCurdir(1)
6690 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006691 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006692 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6693 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006694 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006695" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006696 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006697 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6698 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006699 let svpos = winsaveview()
6700" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006701 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006702" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6703 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006704" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006705endfun
6706
6707" ---------------------------------------------------------------------
6708" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6709" mark and unmark files. If a markfile list exists,
6710" then the rename and delete functions will use it instead
6711" of whatever may happen to be under the cursor at that
6712" moment. When the mouse and gui are available,
6713" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006714"
6715" Creates two lists
6716" s:netrwmarkfilelist -- holds complete paths to all marked files
6717" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6718"
6719" Creates a marked file match string
6720" s:netrwmarfilemtch_# -- used with 2match to display marked files
6721"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006722" Creates a buffer version of islocal
6723" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006724fun! s:NetrwMarkFile(islocal,fname)
6725" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006726" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006727
6728 " sanity check
6729 if empty(a:fname)
6730" call Dret("s:NetrwMarkFile : emtpy fname")
6731 return
6732 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006733 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006734
Bram Moolenaar97d62492012-11-15 21:28:22 +01006735 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006736 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006737 if a:fname =~ '^\a'
6738 let leader= '\<'
6739 else
6740 let leader= ''
6741 endif
6742 if a:fname =~ '\a$'
6743 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6744 else
6745 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6746 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006747
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006749 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006750" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6751" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6752" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006753 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006754
6755 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006756 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006757" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006758 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006759 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006760
6761 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006762 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006764 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6765 if s:netrwmarkfilelist_{curbufnr} == []
6766 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006767" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006768 call s:NetrwUnmarkList(curbufnr,curdir)
6769 else
6770 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006772 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006773 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006774 for fname in s:netrwmarkfilelist_{curbufnr}
6775 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006776 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006777 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006778 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006779 endif
6780 let first= 0
6781 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006783 endif
6784 endif
6785
6786 else
6787 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006788" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006789
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006790" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006791 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006792 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6793" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006794
6795 " build initial markfile matching pattern
6796 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006797 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006798 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006799 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006800 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006801" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006802 endif
6803
6804 " handle global markfilelist
6805 if exists("s:netrwmarkfilelist")
6806 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6807 if index(s:netrwmarkfilelist,dname) == -1
6808 " append new filename to global markfilelist
6809 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006810" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006811 else
6812 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006813" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6814" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006815 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006816" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006817 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006818" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006819 unlet s:netrwmarkfilelist
6820 endif
6821 endif
6822 else
6823 " initialize new global-directory markfilelist
6824 let s:netrwmarkfilelist= []
6825 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006826" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006827 endif
6828
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006829 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006830 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6831 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6832" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6833 if exists("g:did_drchip_netrwlist_syntax")
6834 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6835 endif
6836 else
6837" " call Decho("2match none",'~'.expand("<slnum>"))
6838 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006839 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006840 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006841 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006842" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6843" 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 +00006844endfun
6845
6846" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006847" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6848" mA: move the argument list to marked file list (tomflist=1)
6849" Uses the global marked file list
6850fun! s:NetrwMarkFileArgList(islocal,tomflist)
6851" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6852
6853 let svpos = winsaveview()
6854" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6855 let curdir = s:NetrwGetCurdir(a:islocal)
6856 let curbufnr = bufnr("%")
6857
6858 if a:tomflist
6859 " mA: move argument list to marked file list
6860 while argc()
6861 let fname= argv(0)
6862" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6863 exe "argdel ".fnameescape(fname)
6864 call s:NetrwMarkFile(a:islocal,fname)
6865 endwhile
6866
6867 else
6868 " ma: move marked file list to argument list
6869 if exists("s:netrwmarkfilelist")
6870
6871 " for every filename in the marked list
6872 for fname in s:netrwmarkfilelist
6873" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6874 exe "argadd ".fnameescape(fname)
6875 endfor " for every file in the marked list
6876
6877 " unmark list and refresh
6878 call s:NetrwUnmarkList(curbufnr,curdir)
6879 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6880" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6881 NetrwKeepj call winrestview(svpos)
6882 endif
6883 endif
6884
6885" call Dret("s:NetrwMarkFileArgList")
6886endfun
6887
6888" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006889" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6890" compress/decompress files using the programs
6891" in g:netrw_compress and g:netrw_uncompress,
6892" using g:netrw_compress_suffix to know which to
6893" do. By default:
6894" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006895" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006896fun! s:NetrwMarkFileCompress(islocal)
6897" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006898 let svpos = winsaveview()
6899" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006900 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006901 let curbufnr = bufnr("%")
6902
Bram Moolenaarff034192013-04-24 18:51:19 +02006903 " sanity check
6904 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006905 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006906" call Dret("s:NetrwMarkFileCompress")
6907 return
6908 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006909" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006910
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006912
6913 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006915 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006916" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006917 if exists("g:netrw_decompress['".sfx."']")
6918 " fname has a suffix indicating that its compressed; apply associated decompression routine
6919 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006921 let exe= netrw#WinPath(exe)
6922 if a:islocal
6923 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006925 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006926 call system(exe." ".fname)
6927 if v:shell_error
6928 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006929 endif
6930 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006931 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6932 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006933 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006934
Bram Moolenaarff034192013-04-24 18:51:19 +02006935 endif
6936 unlet sfx
6937
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 if exists("exe")
6939 unlet exe
6940 elseif a:islocal
6941 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006942 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006943 if v:shell_error
6944 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6945 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946 else
6947 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006948 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006949 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006950 endfor " for every file in the marked list
6951
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006953 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006954" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6955 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006956 endif
6957" call Dret("s:NetrwMarkFileCompress")
6958endfun
6959
6960" ---------------------------------------------------------------------
6961" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6962" If no marked files, then set up directory as the
6963" target. Currently does not support copying entire
6964" directories. Uses the local-buffer marked file list.
6965" Returns 1=success (used by NetrwMarkFileMove())
6966" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006967fun! s:NetrwMarkFileCopy(islocal,...)
6968" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6969
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006970 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006971 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006972 if b:netrw_curdir !~ '/$'
6973 if !exists("b:netrw_curdir")
6974 let b:netrw_curdir= curdir
6975 endif
6976 let b:netrw_curdir= b:netrw_curdir."/"
6977 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006978
Bram Moolenaarff034192013-04-24 18:51:19 +02006979 " sanity check
6980 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006981 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006982" call Dret("s:NetrwMarkFileCopy")
6983 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006984 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006985" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006986
Bram Moolenaar446cb832008-06-24 21:56:24 +00006987 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006988 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006989" call Dret("s:NetrwMarkFileCopy 0")
6990 return 0
6991 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006992" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006994 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006995 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006996" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006997 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006998 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6999" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7000 return
7001 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007002
7003 " copy marked files while within the same directory (ie. allow renaming)
7004 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
7005 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7006 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007007" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007008 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007009 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7010 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007011" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007012 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007013 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007014 let oldname = a:1
7015 else
7016 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007017" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007018 let s:recursive= 1
7019 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7020 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7021 if ret == 0
7022 break
7023 endif
7024 endfor
7025 unlet s:recursive
7026 call s:NetrwUnmarkList(curbufnr,curdir)
7027" call Dret("s:NetrwMarkFileCopy ".ret)
7028 return ret
7029 endif
7030
7031 call inputsave()
7032 let newname= input("Copy ".oldname." to : ",oldname,"file")
7033 call inputrestore()
7034 if newname == ""
7035" call Dret("s:NetrwMarkFileCopy 0")
7036 return 0
7037 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007038 let args= s:ShellEscape(oldname)
7039 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007040 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007041 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7042 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007043 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007044 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7045 let args= substitute(args,'/','\\','g')
7046 let tgt = substitute(tgt, '/','\\','g')
7047 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007048 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7049 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7050 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7051 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7052" call Decho("args <".args.">",'~'.expand("<slnum>"))
7053" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007054 if isdirectory(s:NetrwFile(args))
7055" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007056 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007057" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007058 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7059 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7060 " contents to a target. One must append the source directory name to the target to get xcopy to
7061 " do the right thing.
7062 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007063" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007064 endif
7065 else
7066 let copycmd= g:netrw_localcopycmd
7067 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007068 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007069 let copycmd = substitute(copycmd,'\s.*$','','')
7070 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007071 let copycmd = netrw#WinPath(copycmd).copycmdargs
7072 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007073 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007074 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007075" call Decho("args <".args.">",'~'.expand("<slnum>"))
7076" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7077" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7078" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007079 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007080 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007081 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007082 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 +01007083 else
7084 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7085 endif
7086" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007087 return 0
7088 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007089
7090 elseif a:islocal && !s:netrwmftgt_islocal
7091 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007092" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007093 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094
7095 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007096 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007097" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007098 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007099
7100 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007101 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007102" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007103 let curdir = getcwd()
7104 let tmpdir = s:GetTempfile("")
7105 if tmpdir !~ '/'
7106 let tmpdir= curdir."/".tmpdir
7107 endif
7108 if exists("*mkdir")
7109 call mkdir(tmpdir)
7110 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007111 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007112 if v:shell_error != 0
7113 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 +01007114" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007115 return
7116 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007117 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007118 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007119 if s:NetrwLcd(tmpdir)
7120" call Dret("s:NetrwMarkFileCopy : lcd failure")
7121 return
7122 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007123 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007124 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007125 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007126 if getcwd() == tmpdir
7127 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007128 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007129 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007130 if s:NetrwLcd(curdir)
7131" call Dret("s:NetrwMarkFileCopy : lcd failure")
7132 return
7133 endif
7134 if v:version < 704 || (v:version == 704 && !has("patch1107"))
7135 call s:NetrwExe("sil !".g:netrw_localrmdir.g:netrw_localrmdiropt." ".s:ShellEscape(tmpdir,1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007136 if v:shell_error != 0
7137 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80)
7138" " call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".s:ShellEscape(tmpdir,1) )
7139 return
7140 endif
7141 else
7142 if delete(tmpdir,"d")
7143 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
7144 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007145 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007146 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007147 if s:NetrwLcd(curdir)
7148" call Dret("s:NetrwMarkFileCopy : lcd failure")
7149 return
7150 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007151 endif
7152 endif
7153 endif
7154
7155 " -------
7156 " cleanup
7157 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007158" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007159 " remove markings from local buffer
7160 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007161" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7162" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7163" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7164" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7165" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7166" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7167 if exists("s:recursive")
7168" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7169 else
7170" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007171 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007172 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007173 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007174 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007175 else
7176 " refresh local and targets for fast browsing
7177 if !exists("s:recursive")
7178 " remove markings from local buffer
7179" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7180 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7181 endif
7182
7183 " refresh buffers
7184 if s:netrwmftgt_islocal
7185" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7186 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7187 endif
7188 if a:islocal && s:netrwmftgt != curdir
7189" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7190 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7191 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007192 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007193
Bram Moolenaar446cb832008-06-24 21:56:24 +00007194" call Dret("s:NetrwMarkFileCopy 1")
7195 return 1
7196endfun
7197
7198" ---------------------------------------------------------------------
7199" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7200" invoke vim's diff mode on the marked files.
7201" Either two or three files can be so handled.
7202" Uses the global marked file list.
7203fun! s:NetrwMarkFileDiff(islocal)
7204" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7205 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007206
Bram Moolenaarff034192013-04-24 18:51:19 +02007207 " sanity check
7208 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007210" call Dret("s:NetrwMarkFileDiff")
7211 return
7212 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007213 let curdir= s:NetrwGetCurdir(a:islocal)
7214" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007215
Bram Moolenaara6878372014-03-22 21:02:50 +01007216 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007217 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007218 for fname in s:netrwmarkfilelist
7219 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007220 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007221" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007222 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007223 diffthis
7224 elseif cnt == 2 || cnt == 3
7225 vsplit
7226 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007227" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007228 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007229 diffthis
7230 else
7231 break
7232 endif
7233 endfor
7234 call s:NetrwUnmarkList(curbufnr,curdir)
7235 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007236
Bram Moolenaar446cb832008-06-24 21:56:24 +00007237" call Dret("s:NetrwMarkFileDiff")
7238endfun
7239
7240" ---------------------------------------------------------------------
7241" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7242" Uses global markfilelist
7243fun! s:NetrwMarkFileEdit(islocal)
7244" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7245
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007246 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007247 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007248
7249 " sanity check
7250 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007251 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007252" call Dret("s:NetrwMarkFileEdit")
7253 return
7254 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007255" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007256
Bram Moolenaar446cb832008-06-24 21:56:24 +00007257 if exists("s:netrwmarkfilelist_{curbufnr}")
7258 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007259 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007260 " unmark markedfile list
7261" call s:NetrwUnmarkList(curbufnr,curdir)
7262 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007263" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007264 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007265 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007266 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007267
Bram Moolenaar446cb832008-06-24 21:56:24 +00007268" call Dret("s:NetrwMarkFileEdit")
7269endfun
7270
7271" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007272" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007273fun! s:NetrwMarkFileQFEL(islocal,qfel)
7274" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7275 call s:NetrwUnmarkAll()
7276 let curbufnr= bufnr("%")
7277
7278 if !empty(a:qfel)
7279 for entry in a:qfel
7280 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007281" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007282 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007283" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007284 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7285 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7286 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7287 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007288" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007289 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7290 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007291" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007292 endif
7293 endfor
7294 echo "(use me to edit marked files)"
7295 else
7296 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7297 endif
7298
7299" call Dret("s:NetrwMarkFileQFEL")
7300endfun
7301
7302" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007303" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7304" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7305" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7306fun! s:NetrwMarkFileExe(islocal,enbloc)
7307" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007308 let svpos = winsaveview()
7309" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007310 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007311 let curbufnr = bufnr("%")
7312
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007313 if a:enbloc == 0
7314 " individually apply command to files, one at a time
7315 " sanity check
7316 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7317 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7318" call Dret("s:NetrwMarkFileExe")
7319 return
7320 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007321" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007322
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007323 if exists("s:netrwmarkfilelist_{curbufnr}")
7324 " get the command
7325 call inputsave()
7326 let cmd= input("Enter command: ","","file")
7327 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007328" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007329 if cmd == ""
7330" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7331 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007332 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007333
7334 " apply command to marked files, individually. Substitute: filename -> %
7335 " If no %, then append a space and the filename to the command
7336 for fname in s:netrwmarkfilelist_{curbufnr}
7337 if a:islocal
7338 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007339 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007340 endif
7341 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007342 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007343 endif
7344 if cmd =~ '%'
7345 let xcmd= substitute(cmd,'%',fname,'g')
7346 else
7347 let xcmd= cmd.' '.fname
7348 endif
7349 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007350" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007351 let ret= system(xcmd)
7352 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007353" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007354 let ret= s:RemoteSystem(xcmd)
7355 endif
7356 if v:shell_error < 0
7357 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7358 break
7359 else
7360 echo ret
7361 endif
7362 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007363
7364 " unmark marked file list
7365 call s:NetrwUnmarkList(curbufnr,curdir)
7366
7367 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007368 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007369" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7370 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007371 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007372 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007373 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007374
7375 else " apply command to global list of files, en bloc
7376
7377 call inputsave()
7378 let cmd= input("Enter command: ","","file")
7379 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007380" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007381 if cmd == ""
7382" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7383 return
7384 endif
7385 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007386 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007387 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007388 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007389 endif
7390 if a:islocal
7391 call system(cmd)
7392 if v:shell_error < 0
7393 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7394 endif
7395 else
7396 let ret= s:RemoteSystem(cmd)
7397 endif
7398 call s:NetrwUnmarkAll()
7399
7400 " refresh the listing
7401 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007402" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7403 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007404
7405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007406
Bram Moolenaar446cb832008-06-24 21:56:24 +00007407" call Dret("s:NetrwMarkFileExe")
7408endfun
7409
7410" ---------------------------------------------------------------------
7411" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7412" as the marked file(s) (toggles suffix presence)
7413" Uses the local marked file list.
7414fun! s:NetrwMarkHideSfx(islocal)
7415" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007416 let svpos = winsaveview()
7417" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007418 let curbufnr = bufnr("%")
7419
7420 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7421 if exists("s:netrwmarkfilelist_{curbufnr}")
7422
7423 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007424" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007425 " construct suffix pattern
7426 if fname =~ '\.'
7427 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7428 else
7429 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7430 endif
7431 " determine if its in the hiding list or not
7432 let inhidelist= 0
7433 if g:netrw_list_hide != ""
7434 let itemnum = 0
7435 let hidelist= split(g:netrw_list_hide,',')
7436 for hidepat in hidelist
7437 if sfxpat == hidepat
7438 let inhidelist= 1
7439 break
7440 endif
7441 let itemnum= itemnum + 1
7442 endfor
7443 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007444" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007445 if inhidelist
7446 " remove sfxpat from list
7447 call remove(hidelist,itemnum)
7448 let g:netrw_list_hide= join(hidelist,",")
7449 elseif g:netrw_list_hide != ""
7450 " append sfxpat to non-empty list
7451 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7452 else
7453 " set hiding list to sfxpat
7454 let g:netrw_list_hide= sfxpat
7455 endif
7456 endfor
7457
7458 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007459 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007460" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7461 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007462 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007463 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007464 endif
7465
7466" call Dret("s:NetrwMarkHideSfx")
7467endfun
7468
7469" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007470" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007471" Uses the local marked-file list.
7472fun! s:NetrwMarkFileVimCmd(islocal)
7473" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007474 let svpos = winsaveview()
7475" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007476 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007477 let curbufnr = bufnr("%")
7478
Bram Moolenaarff034192013-04-24 18:51:19 +02007479 " sanity check
7480 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007481 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007482" call Dret("s:NetrwMarkFileVimCmd")
7483 return
7484 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007485" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007486
Bram Moolenaar15146672011-10-20 22:22:38 +02007487 if exists("s:netrwmarkfilelist_{curbufnr}")
7488 " get the command
7489 call inputsave()
7490 let cmd= input("Enter vim command: ","","file")
7491 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007492" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007493 if cmd == ""
7494" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7495 return
7496 endif
7497
7498 " apply command to marked files. Substitute: filename -> %
7499 " If no %, then append a space and the filename to the command
7500 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007501" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007502 if a:islocal
7503 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007504 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007505" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007506 exe cmd
7507 exe "sil! keepalt wq!"
7508 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007509" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007510 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007511 endif
7512 endfor
7513
7514 " unmark marked file list
7515 call s:NetrwUnmarkList(curbufnr,curdir)
7516
7517 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007518 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007519" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7520 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007521 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007522 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007523 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007524
Bram Moolenaar15146672011-10-20 22:22:38 +02007525" call Dret("s:NetrwMarkFileVimCmd")
7526endfun
7527
7528" ---------------------------------------------------------------------
7529" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7530" as the marked file(s) (toggles suffix presence)
7531" Uses the local marked file list.
7532fun! s:NetrwMarkHideSfx(islocal)
7533" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007534 let svpos = winsaveview()
7535" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007536 let curbufnr = bufnr("%")
7537
7538 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7539 if exists("s:netrwmarkfilelist_{curbufnr}")
7540
7541 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007542" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007543 " construct suffix pattern
7544 if fname =~ '\.'
7545 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7546 else
7547 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7548 endif
7549 " determine if its in the hiding list or not
7550 let inhidelist= 0
7551 if g:netrw_list_hide != ""
7552 let itemnum = 0
7553 let hidelist= split(g:netrw_list_hide,',')
7554 for hidepat in hidelist
7555 if sfxpat == hidepat
7556 let inhidelist= 1
7557 break
7558 endif
7559 let itemnum= itemnum + 1
7560 endfor
7561 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007562" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007563 if inhidelist
7564 " remove sfxpat from list
7565 call remove(hidelist,itemnum)
7566 let g:netrw_list_hide= join(hidelist,",")
7567 elseif g:netrw_list_hide != ""
7568 " append sfxpat to non-empty list
7569 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7570 else
7571 " set hiding list to sfxpat
7572 let g:netrw_list_hide= sfxpat
7573 endif
7574 endfor
7575
7576 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007577 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007578" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7579 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007580 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007581 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007582 endif
7583
7584" call Dret("s:NetrwMarkHideSfx")
7585endfun
7586
7587" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7589" Uses the global markfilelist
7590fun! s:NetrwMarkFileGrep(islocal)
7591" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007592 let svpos = winsaveview()
7593" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007594 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007595 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007596
7597 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007598" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007599 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007600" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007601 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007602 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007603" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007604 let netrwmarkfilelist= "*"
7605 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007606
Bram Moolenaarff034192013-04-24 18:51:19 +02007607 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007608" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007609 call inputsave()
7610 let pat= input("Enter pattern: ","")
7611 call inputrestore()
7612 let patbang = ""
7613 if pat =~ '^!'
7614 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007615 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007616 endif
7617 if pat =~ '^\i'
7618 let pat = escape(pat,'/')
7619 let pat = '/'.pat.'/'
7620 else
7621 let nonisi = pat[0]
7622 endif
7623
7624 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007625" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007626 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007627 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007628 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007629 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007630" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7631 return
7632 endtry
7633 echo "(use :cn, :cp to navigate, :Rex to return)"
7634
7635 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007636" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7637 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007638
7639 if exists("nonisi")
7640 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007641" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007642 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007643 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007644 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007645 endif
7646
7647" call Dret("s:NetrwMarkFileGrep")
7648endfun
7649
7650" ---------------------------------------------------------------------
7651" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7652" uses the global marked file list
7653" s:netrwmfloc= 0: target directory is remote
7654" = 1: target directory is local
7655fun! s:NetrwMarkFileMove(islocal)
7656" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007657 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007658 let curbufnr = bufnr("%")
7659
7660 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007661 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007662 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007663" call Dret("s:NetrwMarkFileMove")
7664 return
7665 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007666" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007667
Bram Moolenaar446cb832008-06-24 21:56:24 +00007668 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007669 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007670" call Dret("s:NetrwMarkFileCopy 0")
7671 return 0
7672 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007673" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007674
7675 if a:islocal && s:netrwmftgt_islocal
7676 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007677" call Decho("move from local to local",'~'.expand("<slnum>"))
7678" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007679 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007680 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7681" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7682 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007683 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007684 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007685" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007686 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007687 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007688" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007689 if g:netrw_localmovecmd =~ '\s'
7690 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7691 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7692 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007693" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007694 else
7695 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007696" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007697 endif
7698 else
7699 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007700" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007701 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007702 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007703 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7704 let fname= substitute(fname,'/','\\','g')
7705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007706" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007707 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007708 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007709 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007710 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 +01007711 else
7712 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7713 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007714 break
7715 endif
7716 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007717
7718 elseif a:islocal && !s:netrwmftgt_islocal
7719 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007720" call Decho("move from local to remote",'~'.expand("<slnum>"))
7721" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007722 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007723 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007724" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007725 for fname in mflist
7726 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7727 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7728 endfor
7729 unlet mflist
7730
7731 elseif !a:islocal && s:netrwmftgt_islocal
7732 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007733" call Decho("move from remote to local",'~'.expand("<slnum>"))
7734" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007735 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007736 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007737" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007738 for fname in mflist
7739 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7740 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7741 endfor
7742 unlet mflist
7743
7744 elseif !a:islocal && !s:netrwmftgt_islocal
7745 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007746" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7747" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007748 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007749 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007750" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007751 for fname in mflist
7752 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7753 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7754 endfor
7755 unlet mflist
7756 endif
7757
7758 " -------
7759 " cleanup
7760 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007761" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762
7763 " remove markings from local buffer
7764 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7765
7766 " refresh buffers
7767 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007768" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007769 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007770 endif
7771 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007772" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007773 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007774 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007775 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007776" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007777 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007778 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007779
Bram Moolenaar446cb832008-06-24 21:56:24 +00007780" call Dret("s:NetrwMarkFileMove")
7781endfun
7782
7783" ---------------------------------------------------------------------
7784" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7785" using the hardcopy command. Local marked-file list only.
7786fun! s:NetrwMarkFilePrint(islocal)
7787" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7788 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007789
7790 " sanity check
7791 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007792 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007793" call Dret("s:NetrwMarkFilePrint")
7794 return
7795 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007796" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7797 let curdir= s:NetrwGetCurdir(a:islocal)
7798
Bram Moolenaar446cb832008-06-24 21:56:24 +00007799 if exists("s:netrwmarkfilelist_{curbufnr}")
7800 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 call s:NetrwUnmarkList(curbufnr,curdir)
7802 for fname in netrwmarkfilelist
7803 if a:islocal
7804 if g:netrw_keepdir
7805 let fname= s:ComposePath(curdir,fname)
7806 endif
7807 else
7808 let fname= curdir.fname
7809 endif
7810 1split
7811 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007812" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007813 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007814" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007815 hardcopy
7816 q
7817 endfor
7818 2match none
7819 endif
7820" call Dret("s:NetrwMarkFilePrint")
7821endfun
7822
7823" ---------------------------------------------------------------------
7824" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7825" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007826" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007827fun! s:NetrwMarkFileRegexp(islocal)
7828" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7829
7830 " get the regular expression
7831 call inputsave()
7832 let regexp= input("Enter regexp: ","","file")
7833 call inputrestore()
7834
7835 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007837" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007838 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007839" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007840 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007841 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007842 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007843 else
7844 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007845 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007846 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007847" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007848
7849 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007850 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007851 if fname =~ '^'.fnameescape(curdir)
7852" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7853 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7854 else
7855" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7856 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7857 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007858 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007859
7860 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007862
7863 " convert displayed listing into a filelist
7864 let eikeep = &ei
7865 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007866 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007867 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007868" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007870 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007871 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007872 sil NetrwKeepj norm! "ap
7873 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007874 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007875 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007876 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007877 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007878 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007879 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007881 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007882 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007883 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007884 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7885 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007886 call histdel("/",-1)
7887 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007888 endif
7889 " convert regexp into the more usual glob-style format
7890 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007891" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007892 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007893 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007894 let filelist= getline(1,line("$"))
7895 q!
7896 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007897 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 endfor
7899 unlet filelist
7900 let @a = areg
7901 let &ei = eikeep
7902 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007903 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007904
7905" call Dret("s:NetrwMarkFileRegexp")
7906endfun
7907
7908" ---------------------------------------------------------------------
7909" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7910" Uses the local marked file list.
7911fun! s:NetrwMarkFileSource(islocal)
7912" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7913 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007914
7915 " sanity check
7916 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007917 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007918" call Dret("s:NetrwMarkFileSource")
7919 return
7920 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7922 let curdir= s:NetrwGetCurdir(a:islocal)
7923
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924 if exists("s:netrwmarkfilelist_{curbufnr}")
7925 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007926 call s:NetrwUnmarkList(curbufnr,curdir)
7927 for fname in netrwmarkfilelist
7928 if a:islocal
7929 if g:netrw_keepdir
7930 let fname= s:ComposePath(curdir,fname)
7931 endif
7932 else
7933 let fname= curdir.fname
7934 endif
7935 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007936" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007937 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007938 endfor
7939 2match none
7940 endif
7941" call Dret("s:NetrwMarkFileSource")
7942endfun
7943
7944" ---------------------------------------------------------------------
7945" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7946" Uses the global markfilelist
7947fun! s:NetrwMarkFileTag(islocal)
7948" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007949 let svpos = winsaveview()
7950" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007951 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007952 let curbufnr = bufnr("%")
7953
Bram Moolenaarff034192013-04-24 18:51:19 +02007954 " sanity check
7955 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007956 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007957" call Dret("s:NetrwMarkFileTag")
7958 return
7959 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007960" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007961
Bram Moolenaar446cb832008-06-24 21:56:24 +00007962 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007963" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
7964 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007965 call s:NetrwUnmarkAll()
7966
7967 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007968
7969" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
7970 call system(g:netrw_ctags." ".netrwmarkfilelist)
7971 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007972 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7973 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007974
Bram Moolenaar446cb832008-06-24 21:56:24 +00007975 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007976 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007977 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007978 let curdir= b:netrw_curdir
7979 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007980 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007981 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007982" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007983 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007984 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007985 wq!
7986 endif
7987 2match none
7988 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007989" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7990 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991 endif
7992
7993" call Dret("s:NetrwMarkFileTag")
7994endfun
7995
7996" ---------------------------------------------------------------------
7997" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007998" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007999" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008000" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008001" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008002fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008003" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8004 let svpos = winsaveview()
8005" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008006 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007 let hadtgt = exists("s:netrwmftgt")
8008 if !exists("w:netrw_bannercnt")
8009 let w:netrw_bannercnt= b:netrw_bannercnt
8010 endif
8011
8012 " set up target
8013 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008014" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008015 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8016 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008017" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008018 unlet s:netrwmftgt s:netrwmftgt_islocal
8019 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008020 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008021 endif
8022 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008023" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8024 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008025" call Dret("s:NetrwMarkFileTgt : removed target")
8026 return
8027 else
8028 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008029" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008030 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008031
8032 else
8033 " get word under cursor.
8034 " * If directory, use it for the target.
8035 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008036" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008037 let curword= s:NetrwGetWord()
8038 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008039 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008041" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 elseif !a:islocal && tgtdir =~ '/$'
8043 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008044" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008045 else
8046 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008047" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 endif
8049 endif
8050 if a:islocal
8051 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8052 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008053" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 endif
8055 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008056 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8058 endif
8059 let s:netrwmftgt_islocal= a:islocal
8060
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008061 " need to do refresh so that the banner will be updated
8062 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008063 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008064" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008065 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008066 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008067" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008068 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008069 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8070 else
8071 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8072 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008073" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8074 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008075 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008076 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008077 endif
8078
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008079" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8080" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008081" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8082endfun
8083
8084" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008085" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8086fun! s:NetrwGetCurdir(islocal)
8087" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8088
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008089 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008090 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8091" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8092 elseif !exists("b:netrw_curdir")
8093 let b:netrw_curdir= getcwd()
8094" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8095 endif
8096
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008097" 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 +01008098 if b:netrw_curdir !~ '\<\a\{3,}://'
8099 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008100" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008101 if g:netrw_keepdir == 0
8102 call s:NetrwLcd(curdir)
8103 endif
8104 endif
8105
8106" call Dret("s:NetrwGetCurdir <".curdir.">")
8107 return b:netrw_curdir
8108endfun
8109
8110" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008111" s:NetrwOpenFile: query user for a filename and open it {{{2
8112fun! s:NetrwOpenFile(islocal)
8113" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008114 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008115 call inputsave()
8116 let fname= input("Enter filename: ")
8117 call inputrestore()
8118 if fname !~ '[/\\]'
8119 if exists("b:netrw_curdir")
8120 if exists("g:netrw_quiet")
8121 let netrw_quiet_keep = g:netrw_quiet
8122 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008123 let g:netrw_quiet = 1
8124 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008125 let s:rexposn_{bufnr("%")}= winsaveview()
8126" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008127 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008128 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008129 else
8130 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8131 endif
8132 if exists("netrw_quiet_keep")
8133 let g:netrw_quiet= netrw_quiet_keep
8134 else
8135 unlet g:netrw_quiet
8136 endif
8137 endif
8138 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008139 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008140 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008141 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008142" call Dret("s:NetrwOpenFile")
8143endfun
8144
8145" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008146" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8147" For the mapping to this function be made via
8148" netrwPlugin, you'll need to have had
8149" g:netrw_usetab set to non-zero.
8150fun! netrw#Shrink()
8151" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8152 let curwin = winnr()
8153 let wiwkeep = &wiw
8154 set wiw=1
8155
8156 if &ft == "netrw"
8157 if winwidth(0) > g:netrw_wiw
8158 let t:netrw_winwidth= winwidth(0)
8159 exe "vert resize ".g:netrw_wiw
8160 wincmd l
8161 if winnr() == curwin
8162 wincmd h
8163 endif
8164" call Decho("vert resize 0",'~'.expand("<slnum>"))
8165 else
8166 exe "vert resize ".t:netrw_winwidth
8167" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8168 endif
8169
8170 elseif exists("t:netrw_lexbufnr")
8171 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8172 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8173 let t:netrw_winwidth= winwidth(0)
8174 exe "vert resize ".g:netrw_wiw
8175 wincmd l
8176 if winnr() == curwin
8177 wincmd h
8178 endif
8179" call Decho("vert resize 0",'~'.expand("<slnum>"))
8180 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8181 exe "vert resize ".t:netrw_winwidth
8182" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8183 else
8184 call netrw#Lexplore(0,0)
8185 endif
8186
8187 else
8188 call netrw#Lexplore(0,0)
8189 endif
8190 let wiw= wiwkeep
8191
8192" call Dret("netrw#Shrink")
8193endfun
8194
8195" ---------------------------------------------------------------------
8196" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8197fun! s:NetSortSequence(islocal)
8198" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8199
8200 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008201 let svpos= winsaveview()
8202" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008203 call inputsave()
8204 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8205 call inputrestore()
8206
8207 " refresh the listing
8208 let g:netrw_sort_sequence= newsortseq
8209 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008210" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8211 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008212 let @@= ykeep
8213
8214" call Dret("NetSortSequence")
8215endfun
8216
8217" ---------------------------------------------------------------------
8218" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8219" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008220" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008221fun! s:NetrwUnmarkList(curbufnr,curdir)
8222" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8223
8224 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008225 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008226 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8227 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8228 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8229 call remove(s:netrwmarkfilelist,idx) " remove from global list
8230 endfor
8231 if s:netrwmarkfilelist == []
8232 unlet s:netrwmarkfilelist
8233 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008234
Bram Moolenaar446cb832008-06-24 21:56:24 +00008235 " getting rid of the local marked-file lists is easy
8236 unlet s:netrwmarkfilelist_{a:curbufnr}
8237 endif
8238 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8239 unlet s:netrwmarkfilemtch_{a:curbufnr}
8240 endif
8241 2match none
8242" call Dret("s:NetrwUnmarkList")
8243endfun
8244
8245" ---------------------------------------------------------------------
8246" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8247fun! s:NetrwUnmarkAll()
8248" call Dfunc("s:NetrwUnmarkAll()")
8249 if exists("s:netrwmarkfilelist")
8250 unlet s:netrwmarkfilelist
8251 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008252 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008253 2match none
8254" call Dret("s:NetrwUnmarkAll")
8255endfun
8256
8257" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008258" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008259fun! s:NetrwUnmarkAll2()
8260" call Dfunc("s:NetrwUnmarkAll2()")
8261 redir => netrwmarkfilelist_let
8262 let
8263 redir END
8264 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008265 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008266 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8267 for flist in netrwmarkfilelist_list
8268 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8269 unlet s:netrwmarkfilelist_{curbufnr}
8270 unlet s:netrwmarkfilemtch_{curbufnr}
8271 endfor
8272" call Dret("s:NetrwUnmarkAll2")
8273endfun
8274
8275" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008276" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8277"
8278" Marked files are in two types of lists:
8279" s:netrwmarkfilelist -- holds complete paths to all marked files
8280" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8281"
8282" Marked files suitable for use with 2match are in:
8283" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008284fun! s:NetrwUnMarkFile(islocal)
8285" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008286 let svpos = winsaveview()
8287" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008288 let curbufnr = bufnr("%")
8289
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008290 " unmark marked file list
8291 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8292 if exists("s:netrwmarkfilelist")
8293" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008294 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008295 endif
8296
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008297 let ibuf= 1
8298 while ibuf < bufnr("$")
8299 if exists("s:netrwmarkfilelist_".ibuf)
8300 unlet s:netrwmarkfilelist_{ibuf}
8301 unlet s:netrwmarkfilemtch_{ibuf}
8302 endif
8303 let ibuf = ibuf + 1
8304 endwhile
8305 2match none
8306
Bram Moolenaar446cb832008-06-24 21:56:24 +00008307" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008308"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8309call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008310" call Dret("s:NetrwUnMarkFile")
8311endfun
8312
8313" ---------------------------------------------------------------------
8314" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8315fun! s:NetrwMenu(domenu)
8316
8317 if !exists("g:NetrwMenuPriority")
8318 let g:NetrwMenuPriority= 80
8319 endif
8320
Bram Moolenaaradc21822011-04-01 18:03:16 +02008321 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008322" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8323
8324 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008325" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008326 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008327 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8328 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8329 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8330 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8331 if g:netrw_dirhistmax > 0
8332 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8333 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8334 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8335 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8336 else
8337 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8338 endif
8339 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8340 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8341 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8342 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8343 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8344 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8345 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8346 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8347 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8348 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8349 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8350 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8351 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8352 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8353 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 +01008354 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 +02008355 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8356 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8357 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8358 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8359 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8360 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8361 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8362 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8363 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8364 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8365 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8366 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8367 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8368 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8369 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8370 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8371 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8372 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8373 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8374 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8375 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8376 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8377 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8378 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8379 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8380 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8381 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8382 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8383 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8384 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>'
8385 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>'
8386 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>'
8387 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8388 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>'
8389 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>'
8390 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 +01008391 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 +02008392 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8393 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008394 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008395 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8396 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008397
8398 elseif !a:domenu
8399 let s:netrwcnt = 0
8400 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008401 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008402 exe curwin."wincmd w"
8403
8404 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008405" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008406 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008407" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008408 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008409 endif
8410 endif
8411" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008412 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008413 endif
8414
8415endfun
8416
8417" ---------------------------------------------------------------------
8418" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8419" Used by the O maps (as <SID>NetrwObtain())
8420fun! s:NetrwObtain(islocal)
8421" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8422
Bram Moolenaar97d62492012-11-15 21:28:22 +01008423 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008424 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008425 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008426 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008427 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8428 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008429 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008431 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008432
8433" call Dret("NetrwObtain")
8434endfun
8435
8436" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008437" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8438" If there's only one window, then the window will first be split.
8439" Returns:
8440" choice = 0 : didn't have to choose
8441" choice = 1 : saved modified file in window first
8442" choice = 2 : didn't save modified file, opened window
8443" choice = 3 : cancel open
8444fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008445" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008446
Bram Moolenaar97d62492012-11-15 21:28:22 +01008447 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008448 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008449 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450
8451 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008452 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453 let lastwinnr = winnr("$")
8454 let curword = s:NetrwGetWord()
8455 let choice = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008456 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008457 let curdir = s:treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008458" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008459
Bram Moolenaar8d043172014-01-23 14:24:41 +01008460 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008461 if lastwinnr == 1
8462 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008463" 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 +02008464 " g:netrw_preview=0: preview window shown in a horizontally split window
8465 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008466 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008467 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008468 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008469" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008470 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008472 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008473 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008474" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008475 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008476 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008477 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008478" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008479
8480 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008481 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008482 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008483 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008484 wincmd p
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008485" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008486
8487 " prevwinnr: the window number of the "prev" window
8488 " prevbufnr: the buffer number of the buffer in the "prev" window
8489 " bnrcnt : the qty of windows open on the "prev" buffer
8490 let prevwinnr = winnr()
8491 let prevbufnr = bufnr("%")
8492 let prevbufname = bufname("%")
8493 let prevmod = &mod
8494 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008495 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008496" 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 +01008497
8498 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008499 " and it doesn't appear in any other extant window, then ask the
8500 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008501 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008502" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008503 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008504" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008505 exe prevwinnr."wincmd w"
8506
8507 if bnrcnt == 1 && &hidden == 0
8508 " only one copy of the modified buffer in a window, and
8509 " hidden not set, so overwriting will lose the modified file. Ask first...
8510 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008511" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008512 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008513
8514 if choice == 1
8515 " Yes -- write file & then browse
8516 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008517 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008518 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008519 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008520 exe origwin."wincmd w"
8521 let &ei = eikeep
8522 let @@ = ykeep
8523" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008524 return choice
8525 endif
8526
8527 elseif choice == 2
8528 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008529" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008530 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008531
8532 else
8533 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008534" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008535 exe origwin."wincmd w"
8536 let &ei= eikeep
8537 let @@ = ykeep
8538" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008539 return choice
8540 endif
8541 endif
8542 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008543 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008544 endif
8545
8546 " restore b:netrw_curdir (window split/enew may have lost it)
8547 let b:netrw_curdir= curdir
8548 if a:islocal < 2
8549 if a:islocal
8550 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8551 else
8552 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8553 endif
8554 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008555 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008556" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008557 return choice
8558endfun
8559
8560" ---------------------------------------------------------------------
8561" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8562" Always assumed to be local -> remote
8563" call s:NetrwUpload(filename, target)
8564" call s:NetrwUpload(filename, target, fromdirectory)
8565fun! s:NetrwUpload(fname,tgt,...)
8566" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8567
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008568 if a:tgt =~ '^\a\{3,}://'
8569 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008570 else
8571 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8572 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008573" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574
8575 if a:0 > 0
8576 let fromdir= a:1
8577 else
8578 let fromdir= getcwd()
8579 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008580" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008581
8582 if type(a:fname) == 1
8583 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008584" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008586" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8587 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8588" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008589 if a:tgt =~ '/$'
8590 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008591" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008592 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008594" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008595 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008596" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008597 endif
8598 q!
8599
8600 elseif type(a:fname) == 3
8601 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008602" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008603 let curdir= getcwd()
8604 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008605 if s:NetrwLcd(fromdir)
8606" call Dret("s:NetrwUpload : lcd failure")
8607 return
8608 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008609 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008610 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008611 if exists("g:netrw_port") && g:netrw_port != ""
8612 let useport= " ".g:netrw_scpport." ".g:netrw_port
8613 else
8614 let useport= ""
8615 endif
8616 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8617 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008618 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 +02008619 if s:NetrwLcd(curdir)
8620" call Dret("s:NetrwUpload : lcd failure")
8621 return
8622 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623
8624 elseif a:tgt =~ '^ftp:'
8625 call s:NetrwMethod(a:tgt)
8626
8627 if b:netrw_method == 2
8628 " handle uploading a list of files via ftp+.netrc
8629 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008630 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008631" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008632
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008633 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008634" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008635
8636 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008637 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008638" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008639 endif
8640
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008641 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008642" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643
Bram Moolenaaradc21822011-04-01 18:03:16 +02008644 if tgtdir == ""
8645 let tgtdir= '/'
8646 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008647 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008648" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008649
8650 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008651 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8652" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008653 endfor
8654
8655 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008656 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 +00008657 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008658" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8659 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 endif
8661 " 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 +01008662 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008663 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8665 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8666 else
8667 bw!|q
8668 endif
8669
8670 elseif b:netrw_method == 3
8671 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8672 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008673 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008674 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008675 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008676
8677 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008678 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008679" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008680 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008681 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008682" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008683 endif
8684
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008685 if exists("g:netrw_uid") && g:netrw_uid != ""
8686 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008687 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008688" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008689 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008690 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008691 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008692" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008693 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008694 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008696 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008697 endif
8698
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008699 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008700" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701
8702 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008703 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008704" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008705 endif
8706
8707 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008708 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008709" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008710 endif
8711
8712 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008713 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008714" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 endfor
8716
8717 " perform ftp:
8718 " -i : turns off interactive prompting from ftp
8719 " -n unix : DON'T use <.netrc>, even though it exists
8720 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008721 NetrwKeepj norm! 1Gdd
8722 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008723 " 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 +01008724 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008725 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008726 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8727 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008728 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008729 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8730 let &debug = debugkeep
8731 let mod = 1
8732 else
8733 bw!|q
8734 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008735 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008736" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008737 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008738 endif
8739 else
8740 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8741 endif
8742 endif
8743
8744" call Dret("s:NetrwUpload")
8745endfun
8746
8747" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008748" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008749fun! s:NetrwPreview(path) range
8750" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008751" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8752" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008753 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008754 NetrwKeepj call s:NetrwOptionsSave("s:")
8755 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8756 NetrwKeepj call s:NetrwOptionsSafe(1)
8757 else
8758 NetrwKeepj call s:NetrwOptionsSafe(0)
8759 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008760 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008761" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008762 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008763" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8764 if g:netrw_preview
8765 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008766 let pvhkeep = &pvh
8767 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8768 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008769" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8770 else
8771 " horizontal split
8772 let pvhkeep = &pvh
8773 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8774 let &pvh = winheight(0) - winsz
8775" 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 +02008776 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008777 " g:netrw_preview g:netrw_alto
8778 " 1 : vert 1: top -- preview window is vertically split off and on the left
8779 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8780 " 0 : 1: top -- preview window is horizontally split off and on the top
8781 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8782 "
8783 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowse() check via
8784 " the BufEnter event set up in netrwPlugin.vim
8785" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8786 let eikeep = &ei
8787 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008788 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008789 let &ei= eikeep
8790" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008791 if exists("pvhkeep")
8792 let &pvh= pvhkeep
8793 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008794 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008795 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008796 endif
8797 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008798 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 +00008799 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008800 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008801 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802" call Dret("NetrwPreview")
8803endfun
8804
8805" ---------------------------------------------------------------------
8806" s:NetrwRefresh: {{{2
8807fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008808" 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 +00008809 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008810 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008811" call Decho("setl ma noro",'~'.expand("<slnum>"))
8812" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008813 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008814 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8815 if !exists("w:netrw_treetop")
8816 if exists("b:netrw_curdir")
8817 let w:netrw_treetop= b:netrw_curdir
8818 else
8819 let w:netrw_treetop= getcwd()
8820 endif
8821 endif
8822 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8823 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008824
8825 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008826 let screenposn = winsaveview()
8827" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008828
8829" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8830" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8831 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008833 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008834 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008835 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008837
8838 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008839" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8840 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008841
8842 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008843 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8844 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8845" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8846 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8847 else
8848" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8849 2match none
8850 endif
8851 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852
Bram Moolenaar97d62492012-11-15 21:28:22 +01008853" restore
8854 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008855" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856endfun
8857
8858" ---------------------------------------------------------------------
8859" s:NetrwRefreshDir: refreshes a directory by name {{{2
8860" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008861" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008862fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008863" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008864 if g:netrw_fastbrowse == 0
8865 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008866" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008867 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008868" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008869
8870 if tgtwin > 0
8871 " tgtwin is being displayed, so refresh it
8872 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008873" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008874 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008875 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008876 exe curwin."wincmd w"
8877
8878 elseif bufnr(a:dirname) > 0
8879 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008880" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
8881 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008882 endif
8883
8884 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008885" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008887 endif
8888" call Dret("s:NetrwRefreshDir")
8889endfun
8890
8891" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008892" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8893" window number to do its editing in.
8894" Supports [count]C where the count, if present, is used to specify
8895" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008896fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008897" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008898 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008899" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 if a:1 == "" " :NetrwC win#
8901 let g:netrw_chgwin= winnr()
8902 else " :NetrwC
8903 let g:netrw_chgwin= a:1
8904 endif
8905 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008906 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008907 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008908 let g:netrw_chgwin= winnr()
8909 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008910 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008911" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008912endfun
8913
8914" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8916" What this function does is to compute a priority for the patterns
8917" in the g:netrw_sort_sequence. It applies a substitute to any
8918" "files" that satisfy each pattern, putting the priority / in
8919" front. An "*" pattern handles the default priority.
8920fun! s:NetrwSetSort()
8921" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008922 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 if w:netrw_liststyle == s:LONGLIST
8924 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8925 else
8926 let seqlist = g:netrw_sort_sequence
8927 endif
8928 " sanity check -- insure that * appears somewhere
8929 if seqlist == ""
8930 let seqlist= '*'
8931 elseif seqlist !~ '\*'
8932 let seqlist= seqlist.',*'
8933 endif
8934 let priority = 1
8935 while seqlist != ""
8936 if seqlist =~ ','
8937 let seq = substitute(seqlist,',.*$','','e')
8938 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8939 else
8940 let seq = seqlist
8941 let seqlist = ""
8942 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008943 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008944 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008945 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008946 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008947 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008948 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008949 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008950" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008951
8952 " sanity check
8953 if w:netrw_bannercnt > line("$")
8954 " apparently no files were left after a Hiding pattern was used
8955" call Dret("SetSort : no files left after hiding")
8956 return
8957 endif
8958 if seq == '*'
8959 let starpriority= spriority
8960 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008961 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008962 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008963 " sometimes multiple sorting patterns will match the same file or directory.
8964 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008965 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8966 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008967 endif
8968 let priority = priority + 1
8969 endwhile
8970 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008971 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8972 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008973 endif
8974
8975 " Following line associated with priority -- items that satisfy a priority
8976 " pattern get prefixed by ###/ which permits easy sorting by priority.
8977 " Sometimes files can satisfy multiple priority patterns -- only the latest
8978 " priority pattern needs to be retained. So, at this point, these excess
8979 " priority prefixes need to be removed, but not directories that happen to
8980 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008981 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8982 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008983 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008984
8985" call Dret("SetSort")
8986endfun
8987
Bram Moolenaarff034192013-04-24 18:51:19 +02008988" ---------------------------------------------------------------------
8989" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8990" Implements [count]Tb (bookhist<b>)
8991" [count]Th (bookhist<h>)
8992" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008993fun! s:NetrwSetTgt(islocal,bookhist,choice)
8994" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008995
8996 if a:bookhist == 'b'
8997 " supports choosing a bookmark as a target using a qb-generated list
8998 let choice= a:choice - 1
8999 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009000 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009001 else
9002 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9003 endif
9004
9005 elseif a:bookhist == 'h'
9006 " supports choosing a history stack entry as a target using a qb-generated list
9007 let choice= (a:choice % g:netrw_dirhistmax) + 1
9008 if exists("g:netrw_dirhist_".choice)
9009 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009010 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009011 else
9012 echomsg "Sorry, history#".a:choice." not available!"
9013 endif
9014 endif
9015
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009016 " refresh the display
9017 if !exists("b:netrw_curdir")
9018 let b:netrw_curdir= getcwd()
9019 endif
9020 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9021
Bram Moolenaarff034192013-04-24 18:51:19 +02009022" call Dret("s:NetrwSetTgt")
9023endfun
9024
Bram Moolenaar446cb832008-06-24 21:56:24 +00009025" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009026" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009027fun! s:NetrwSortStyle(islocal)
9028" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009029 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009030 let svpos= winsaveview()
9031" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009032
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009033 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 +01009034 NetrwKeepj norm! 0
9035 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009036" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9037 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009038
9039" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9040endfun
9041
9042" ---------------------------------------------------------------------
9043" s:NetrwSplit: mode {{{2
9044" =0 : net and o
9045" =1 : net and t
9046" =2 : net and v
9047" =3 : local and o
9048" =4 : local and t
9049" =5 : local and v
9050fun! s:NetrwSplit(mode)
9051" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9052
Bram Moolenaar97d62492012-11-15 21:28:22 +01009053 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054 call s:SaveWinVars()
9055
9056 if a:mode == 0
9057 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009058 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009059 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009060" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009061 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009062 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009063 NetrwKeepj call s:RestoreWinVars()
9064 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009065 unlet s:didsplit
9066
9067 elseif a:mode == 1
9068 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009069 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009070" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 tabnew
9072 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009073 NetrwKeepj call s:RestoreWinVars()
9074 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009075 unlet s:didsplit
9076
9077 elseif a:mode == 2
9078 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009079 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009080 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009081" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009082 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009083 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009084 NetrwKeepj call s:RestoreWinVars()
9085 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009086 unlet s:didsplit
9087
9088 elseif a:mode == 3
9089 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009090 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009091 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009092" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009093 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009094 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009095 NetrwKeepj call s:RestoreWinVars()
9096 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009097 unlet s:didsplit
9098
9099 elseif a:mode == 4
9100 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009102 let eikeep = &ei
9103 let netrw_winnr = winnr()
9104 let netrw_line = line(".")
9105 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009106 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009107 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009108 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009109 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9110 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009111 let &ei = eikeep
9112 let netrw_curdir = s:NetrwTreeDir(0)
9113" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009114 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009115 let b:netrw_curdir = netrw_curdir
9116 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009117 NetrwKeepj call s:RestoreWinVars()
9118 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009119 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009120 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009121 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9122 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009123 let &ei= eikeep
9124 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009125 unlet s:didsplit
9126
9127 elseif a:mode == 5
9128 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009129 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009130 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009131" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009132 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009133 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009134 NetrwKeepj call s:RestoreWinVars()
9135 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009136 unlet s:didsplit
9137
9138 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009139 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140 endif
9141
Bram Moolenaar97d62492012-11-15 21:28:22 +01009142 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143" call Dret("s:NetrwSplit")
9144endfun
9145
9146" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009147" s:NetrwTgtMenu: {{{2
9148fun! s:NetrwTgtMenu()
9149 if !exists("s:netrw_menucnt")
9150 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009151 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009152" call Dfunc("s:NetrwTgtMenu()")
9153
9154 " the following test assures that gvim is running, has menus available, and has menus enabled.
9155 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9156 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009157" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009158 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9159 endif
9160 if !exists("s:netrw_initbookhist")
9161 call s:NetrwBookHistRead()
9162 endif
9163
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009164 " try to cull duplicate entries
9165 let tgtdict={}
9166
Bram Moolenaarff034192013-04-24 18:51:19 +02009167 " target bookmarked places
9168 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009169" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009170 let cnt= 1
9171 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009172 if has_key(tgtdict,bmd)
9173 let cnt= cnt + 1
9174 continue
9175 endif
9176 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009177 let ebmd= escape(bmd,g:netrw_menu_escape)
9178 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009179" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009180 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 +02009181 let cnt= cnt + 1
9182 endfor
9183 endif
9184
9185 " target directory browsing history
9186 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009187" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009188 let histcnt = 1
9189 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009190 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009191 if exists("g:netrw_dirhist_{histcnt}")
9192 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009193 if has_key(tgtdict,histentry)
9194 let histcnt = histcnt + 1
9195 continue
9196 endif
9197 let tgtdict[histentry] = histcnt
9198 let ehistentry = escape(histentry,g:netrw_menu_escape)
9199" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009200 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 +02009201 endif
9202 let histcnt = histcnt + 1
9203 endwhile
9204 endif
9205 endif
9206" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009207endfun
9208
9209" ---------------------------------------------------------------------
9210" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9211" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009212fun! s:NetrwTreeDir(islocal)
9213" 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 Moolenaaraa3b15d2016-04-21 08:53:19 +02009214" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9215" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9216" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009217
Bram Moolenaar8d043172014-01-23 14:24:41 +01009218 if exists("s:treedir")
9219 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
9220 let treedir= s:treedir
9221 unlet s:treedir
9222" call Dret("s:NetrwTreeDir ".treedir)
9223 return treedir
9224 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009225
Bram Moolenaar8d043172014-01-23 14:24:41 +01009226 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9227 let b:netrw_curdir= getcwd()
9228 endif
9229 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009230" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009231
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009232 let s:treecurpos= winsaveview()
9233" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9234
9235 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009236" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9237" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009238
9239 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009240 let curline= substitute(getline('.'),"\t -->.*$",'','')
9241 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009242" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009243 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009244" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9245 elseif curline =~ '@$'
9246" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9247 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9248" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009250" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251 let treedir= ""
9252 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009253
9254 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009255" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9256" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009257" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009258 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009261" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9262 sil! NetrwKeepj %d _
9263" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009264 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009265" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009266" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 endif
9268
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009269" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009270 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9271" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009272
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9274" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9275" let newdir = w:netrw_treetop.'/'.potentialdir
9276" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9277" let treedir = s:NetrwTreePath(newdir)
9278" let w:netrw_treetop = newdir
9279" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9280" else
9281" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009282 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009283" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009285
9286 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009287 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009288" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009289
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009290" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009291 return treedir
9292endfun
9293
9294" ---------------------------------------------------------------------
9295" s:NetrwTreeDisplay: recursive tree display {{{2
9296fun! s:NetrwTreeDisplay(dir,depth)
9297" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9298
9299 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009300 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009301
9302 " install ../ and shortdir
9303 if a:depth == ""
9304 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009305" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009306 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009307 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009308 if a:dir == w:netrw_treetop
9309 let shortdir= a:dir
9310 else
9311 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9312 endif
9313 call setline(line("$")+1,a:depth.shortdir)
9314 else
9315 let shortdir= substitute(a:dir,'^.*/','','e')
9316 call setline(line("$")+1,a:depth.shortdir.'/')
9317 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009318" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009319
9320 " append a / to dir if its missing one
9321 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322
9323 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009324 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009325" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009326
Bram Moolenaar85850f32019-07-19 22:05:51 +02009327 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9328 if g:netrw_hide == 1
9329 " hide given patterns
9330 let listhide= split(g:netrw_list_hide,',')
9331" call Decho("listhide=".string(listhide))
9332 for pat in listhide
9333 call filter(w:netrw_treedict[dir],'v:val !~ "'.pat.'"')
9334 endfor
9335
9336 elseif g:netrw_hide == 2
9337 " show given patterns (only)
9338 let listhide= split(g:netrw_list_hide,',')
9339" call Decho("listhide=".string(listhide))
9340 let entries=[]
9341 for entry in w:netrw_treedict[dir]
9342 for pat in listhide
9343 if entry =~ pat
9344 call add(entries,entry)
9345 break
9346 endif
9347 endfor
9348 endfor
9349 let w:netrw_treedict[dir]= entries
9350 endif
9351 if depth != ""
9352 " always remove "." and ".." entries when there's depth
9353 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9354 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9355 endif
9356
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009357" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009358 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009359 if dir =~ '/$'
9360 let direntry= substitute(dir.entry,'[@/]$','','e')
9361 else
9362 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9363 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009365 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009366" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009367 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009368 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009369" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9370 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9371 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9372" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009373 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009374 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009375" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009376 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009377 endif
9378 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009379" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009380
Bram Moolenaar446cb832008-06-24 21:56:24 +00009381" call Dret("NetrwTreeDisplay")
9382endfun
9383
9384" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009385" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9386fun! s:NetrwRefreshTreeDict(dir)
9387" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009388 if !exists("w:netrw_treedict")
9389" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9390 return
9391 endif
9392
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009393 for entry in w:netrw_treedict[a:dir]
9394 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9395" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9396
9397 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9398" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9399 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009400 let liststar = s:NetrwGlob(direntry,'*',1)
9401 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009402 let w:netrw_treedict[direntry] = liststar + listdotstar
9403" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9404
9405 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9406" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9407 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009408 let liststar = s:NetrwGlob(direntry.'/','*',1)
9409 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009410 let w:netrw_treedict[direntry]= liststar + listdotstar
9411" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9412
9413 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9414" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9415 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009416 let liststar = s:NetrwGlob(direntry.'/','*',1)
9417 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009418" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9419
9420 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009421" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009422 endif
9423 endfor
9424" call Dret("s:NetrwRefreshTreeDict")
9425endfun
9426
9427" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009428" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009429" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009430fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009431 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009433" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9434" 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>"))
9435" 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 +00009436
9437 " update the treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438" call Decho("update the treetop",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009439 if !exists("w:netrw_treetop")
9440 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009441" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009442 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
9443 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009444" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009445 endif
9446
Bram Moolenaar446cb832008-06-24 21:56:24 +00009447 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448 " insure that we have a treedict, albeit empty
9449" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009450 let w:netrw_treedict= {}
9451 endif
9452
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009453 " update the dictionary for the current directory
9454" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009455" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009456 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009459 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009460
9461 " if past banner, record word
9462 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9463 let fname= expand("<cword>")
9464 else
9465 let fname= ""
9466 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009467" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9468" 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 +00009469
9470 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009471 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009472" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009473
9474 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9475 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009476" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009477 1d
9478 endwhile
9479
Bram Moolenaar13600302014-05-22 18:26:40 +02009480 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009481
9482" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009483 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484 endif
9485endfun
9486
9487" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009488" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009489" Normally, treetop is w:netrw_treetop, but a
9490" user of the function ( netrw#SetTreetop() )
9491" wipes that out prior to calling this function
9492fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009493" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9494 if line(".") < w:netrw_bannercnt + 2
9495 let treedir= a:treetop
9496 if treedir !~ '/$'
9497 let treedir= treedir.'/'
9498 endif
9499" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9500 return treedir
9501 endif
9502
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009503 let svpos = winsaveview()
9504" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009505 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009506" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009507 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9509 let curline= getline('.')
9510" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9511 if curline =~ '/$'
9512" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9513 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9514" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9515 elseif curline =~ '@\s\+-->'
9516" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9517 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9518 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9519" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009520 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009521" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009522 let treedir= ""
9523 endif
9524 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009525" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9526" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009527 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9528 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9529 let treedir= dirname.treedir
9530 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009531" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009532 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009533" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009534 if a:treetop =~ '/$'
9535 let treedir= a:treetop.treedir
9536 else
9537 let treedir= a:treetop.'/'.treedir
9538 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009539" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009540 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009541" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009542" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9543 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009544" call Dret("s:NetrwTreePath <".treedir.">")
9545 return treedir
9546endfun
9547
9548" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009549" s:NetrwWideListing: {{{2
9550fun! s:NetrwWideListing()
9551
9552 if w:netrw_liststyle == s:WIDELIST
9553" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9554 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009555 " cpf: characters per filename
9556 " fpl: filenames per line
9557 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009558 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009559" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009560 let b:netrw_cpf= 0
9561 if line("$") >= w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009562 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9563 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009564 else
9565" call Dret("NetrwWideListing")
9566 return
9567 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009568 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009569" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009570
9571 " determine qty files per line (fpl)
9572 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9573 if w:netrw_fpl <= 0
9574 let w:netrw_fpl= 1
9575 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009577
9578 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009579 " fpc: files per column of wide listing
9580 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009581 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009582 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9583 let newcolstart = w:netrw_bannercnt + fpc
9584 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009585" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009586 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009587" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009588 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009589 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009590 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591 while line("$") >= newcolstart
9592 if newcolend > line("$") | let newcolend= line("$") | endif
9593 let newcolqty= newcolend - newcolstart
9594 exe newcolstart
9595 if newcolqty == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009596 exe "sil! NetrwKeepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009597 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009598 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009599 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009600 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009601 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009602 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009603 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009604" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009605 sil! let @*= keepregstar
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009606 sil! let @+= keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01009607 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009608 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9609 NetrwKeepj call histdel("/",-1)
9610 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9611 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009612" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009613 exe "setl ".g:netrw_bufsettings
Bram Moolenaar85850f32019-07-19 22:05:51 +02009614" 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 +00009615" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009616 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009617 else
9618 if hasmapto("w","n")
9619 sil! nunmap <buffer> w
9620 endif
9621 if hasmapto("b","n")
9622 sil! nunmap <buffer> b
9623 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009624 endif
9625
9626endfun
9627
9628" ---------------------------------------------------------------------
9629" s:PerformListing: {{{2
9630fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009631" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9632" 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 +02009633" 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>"))
9634 sil! NetrwKeepj %d _
9635" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009636
Bram Moolenaar15146672011-10-20 22:22:38 +02009637 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009638" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009639 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009640
Bram Moolenaar85850f32019-07-19 22:05:51 +02009641 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009642 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009643" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009644
9645" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009646" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009647" endif " Decho
9648
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009649" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009650 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9651 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009652" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9653 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009654 endif
9655
9656 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009657 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658
9659 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009660 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009661" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009662 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009663 if exists("g:netrw_pchk")
9664 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9665 " failure detections.
9666 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009667 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9669 endif
9670 if exists("g:netrw_pchk")
9671 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9672 else
9673 let curdir= b:netrw_curdir
9674 endif
9675 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9676 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9677 else
9678 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009679 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009680 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009681 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009682 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009683" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009684 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009685 let w:netrw_bannercnt= 1
9686 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009687" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9688" 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 +00009689
Bram Moolenaar85850f32019-07-19 22:05:51 +02009690 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009692 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693 let sortby= sortby." reversed"
9694 endif
9695
9696 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009697 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009698" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009699 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009700" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009701 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009702 NetrwKeepj put ='\" Sorted by '.sortby
9703 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009704 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9705 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009706" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009707 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009708 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009709 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9710 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009711 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009712" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009713" 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 +00009714 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009715
Bram Moolenaar85850f32019-07-19 22:05:51 +02009716 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009717 if g:netrw_banner
9718 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009719" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009720 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009721 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009722 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009723 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009724 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009725 endif
9726 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009727 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009729 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009730 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009731 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009732
9733 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009734 if g:netrw_banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02009735" call Decho("--handle hiding/showing (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009736 if g:netrw_list_hide != "" && g:netrw_hide
9737 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009738 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009739 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009740 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009741 endif
9742 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009743 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009744 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009745
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009746" 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 +01009747 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009748" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009749 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009750" 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 +01009751 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009752 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009753" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009754" 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 +00009755 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009756
9757 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009758 if g:netrw_banner
9759 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009760 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009761" 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 +01009762" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009763" 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 +01009764 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009765
Bram Moolenaar446cb832008-06-24 21:56:24 +00009766 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009767" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009768 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009769 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009770 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009771 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009772 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009773" 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 +01009774" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9775 return
9776 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009777 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009778
9779 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009780 if !exists("w:netrw_bannercnt")
9781 let w:netrw_bannercnt= 0
9782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009783" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9784" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9785" 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 +01009786
Bram Moolenaar5c736222010-01-06 20:54:52 +01009787 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009788" call Decho("manipulate directory listing (hide)",'~'.expand("<slnum>"))
9789" 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 +00009790 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009791 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009792 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009793 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009794" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009796 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009797 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009798" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009799 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009800
Bram Moolenaar5c736222010-01-06 20:54:52 +01009801 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009802" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009803 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009804 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009805 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009806 else
9807 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009808 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809 endif
9810 endif
9811 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009812" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009813 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9814 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009815
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009816 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009817 " exten: sort by extension
9818 " The histdel(...,-1) calls remove the last search from the search history
9819" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009820 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9821 NetrwKeepj call histdel("/",-1)
9822 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9823 NetrwKeepj call histdel("/",-1)
9824 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9825 NetrwKeepj call histdel("/",-1)
9826 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9827" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009828 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009829 " normal direction sorting
9830 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9831 else
9832 " reverse direction sorting
9833 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9834 endif
9835 endif
9836 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9837 NetrwKeepj call histdel("/",-1)
9838
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009840 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009841" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009842 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009843" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009844 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009846" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009847 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009848 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009849 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9850 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009851 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009852 endif
9853
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009854 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009855" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009856 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009857 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009858 call histdel("/",-1)
9859 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009860 endif
9861 endif
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
9864 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009865" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9866" 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 +01009867 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009868" 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 +01009869 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" 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 +00009871
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009872 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009873 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009874" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009875 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009876 endif
9877
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009879 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009880" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9881 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009882 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009883" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9884 else
9885" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9886" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9887" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9888" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009889 endif
9890
9891 " record previous current directory
9892 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009894
9895 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009896" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9897" 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 +01009898 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009899" 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 +02009900 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009901" 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 +00009902
9903 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009904" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009905 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009906" 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 +01009907 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009909 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9910 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009911" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009912
Bram Moolenaar8d043172014-01-23 14:24:41 +01009913 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009914" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9915" 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 +01009916" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9917 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009918 unlet s:treecurpos
9919 endif
9920
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009921" 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>"))
9922" 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 +00009923" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9924endfun
9925
9926" ---------------------------------------------------------------------
9927" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009928fun! s:SetupNetrwStatusLine(statline)
9929" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9930
9931 if !exists("s:netrw_setup_statline")
9932 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009933" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009934
9935 if !exists("s:netrw_users_stl")
9936 let s:netrw_users_stl= &stl
9937 endif
9938 if !exists("s:netrw_users_ls")
9939 let s:netrw_users_ls= &laststatus
9940 endif
9941
9942 " set up User9 highlighting as needed
9943 let keepa= @a
9944 redir @a
9945 try
9946 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009947 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009948 if &bg == "dark"
9949 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9950 else
9951 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9952 endif
9953 endtry
9954 redir END
9955 let @a= keepa
9956 endif
9957
9958 " set up status line (may use User9 highlighting)
9959 " insure that windows have a statusline
9960 " make sure statusline is displayed
9961 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009962 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009963" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009965
9966" call Dret("SetupNetrwStatusLine : stl=".&stl)
9967endfun
9968
Bram Moolenaar85850f32019-07-19 22:05:51 +02009969" =========================================
9970" Remote Directory Browsing Support: {{{1
9971" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009972
9973" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009974" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9975" This function assumes that a long listing will be received. Size, time,
9976" and reverse sorts will be requested of the server but not otherwise
9977" enforced here.
9978fun! s:NetrwRemoteFtpCmd(path,listcmd)
9979" 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 +01009980" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009981 " sanity check: {{{3
9982 if !exists("w:netrw_method")
9983 if exists("b:netrw_method")
9984 let w:netrw_method= b:netrw_method
9985 else
9986 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9987" call Dret("NetrwRemoteFtpCmd")
9988 return
9989 endif
9990 endif
9991
9992 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9993 let ffkeep= &ff
9994 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009995" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009996
9997 " clear off any older non-banner lines " {{{3
9998 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009999" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10000 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010001
10002 ".........................................
10003 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10004 " ftp + <.netrc>: Method #2
10005 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010006 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010007 endif
10008 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010009 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010010" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010011 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010012 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010014 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010015" 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>"))
10016 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 +010010017 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010018" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10019 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 +010010020 endif
10021
10022 ".........................................
10023 elseif w:netrw_method == 3 " {{{3
10024 " ftp + machine,id,passwd,filename: Method #3
10025 setl ff=unix
10026 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010027 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010028 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010029 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010030 endif
10031
10032 " handle userid and password
10033 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010035 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10036 call NetUserPass("ftp:".host)
10037 endif
10038 if exists("g:netrw_uid") && g:netrw_uid != ""
10039 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010040 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010041 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010042 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010043 endif
10044 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010045 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010046 endif
10047 endif
10048
10049 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010050 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010051 endif
10052 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010053 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010054" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010055 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010056 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010057
10058 " perform ftp:
10059 " -i : turns off interactive prompting from ftp
10060 " -n unix : DON'T use <.netrc>, even though it exists
10061 " -n win32: quit being obnoxious about password
10062 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010063" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010064 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010065" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010066" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10067" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010068 endif
10069
10070 ".........................................
10071 elseif w:netrw_method == 9 " {{{3
10072 " sftp username@machine: Method #9
10073 " s:netrw_sftp_cmd
10074 setl ff=unix
10075
10076 " restore settings
10077 let &ff= ffkeep
10078" call Dret("NetrwRemoteFtpCmd")
10079 return
10080
10081 ".........................................
10082 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010084 endif
10085
10086 " cleanup for Windows " {{{3
10087 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010088 sil! NetrwKeepj %s/\r$//e
10089 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010090 endif
10091 if a:listcmd == "dir"
10092 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010093 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10094 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10095 NetrwKeepj call histdel("/",-1)
10096 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010097 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 +010010098 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10099 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010100 endif
10101 endif
10102
10103 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10104 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010105 exe 'NetrwKeepj '.w:netrw_bannercnt
10106 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010107 endif
10108 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010109 exe 'NetrwKeepj '.w:netrw_bannercnt
10110 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010111 endif
10112
10113 " restore settings " {{{3
10114 let &ff= ffkeep
10115" call Dret("NetrwRemoteFtpCmd")
10116endfun
10117
10118" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010119" s:NetrwRemoteListing: {{{2
10120fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010121" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010122
Bram Moolenaara6878372014-03-22 21:02:50 +010010123 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10124 let w:netrw_bannercnt= s:bannercnt
10125 endif
10126 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10127 let w:netrw_bannercnt= s:bannercnt
10128 endif
10129
Bram Moolenaar446cb832008-06-24 21:56:24 +000010130 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010131
Bram Moolenaar446cb832008-06-24 21:56:24 +000010132 " sanity check:
10133 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010134" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010135 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010136" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010137 if !exists("g:netrw_quiet")
10138 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10139 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010140 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010141" call Dret("s:NetrwRemoteListing -1")
10142 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010143 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010144
Bram Moolenaar8d043172014-01-23 14:24:41 +010010145 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010146" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010147 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010148 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010149 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 +000010150 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010151 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 +000010152 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010153 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010154
Bram Moolenaar85850f32019-07-19 22:05:51 +020010155 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010156" call Dret("s:NetrwRemoteListing -1")
10157 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010158 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010159" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010160
Bram Moolenaar446cb832008-06-24 21:56:24 +000010161 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010162" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010163 let w:netrw_method= b:netrw_method
10164 endif
10165
Bram Moolenaar13600302014-05-22 18:26:40 +020010166 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010167 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010168" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010169 let s:method = "ftp"
10170 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010171 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010172 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010173 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010174 let listcmd= g:netrw_ftp_sizelist_cmd
10175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010176" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010177 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010178" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010179
Bram Moolenaara6878372014-03-22 21:02:50 +010010180 " report on missing file or directory messages
10181 if search('[Nn]o such file or directory\|Failed to change directory')
10182 let mesg= getline(".")
10183 if exists("w:netrw_bannercnt")
10184 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010185 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010186 setl noma
10187 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010188 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010189 call netrw#ErrorMsg(s:WARNING,mesg,96)
10190" call Dret("s:NetrwRemoteListing : -1")
10191 return -1
10192 endif
10193
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010194 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 +000010195 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010196" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010197 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010198
10199 " cleanup
10200 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010201 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10202 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010203 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010204 sil! NetrwKeepj %s/\r$//e
10205 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010206
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010207 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010208 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010209 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010210 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010211" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010212 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010213" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010214 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010215 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010216 exe "sil! NetrwKeepj ".line1
10217 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010218
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010219" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010220 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010221" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010222 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10223 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010224 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010225" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010226 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10227 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10228 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10229 NetrwKeepj call histdel("/",-1)
10230 NetrwKeepj call histdel("/",-1)
10231 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010232 endif
10233 endif
10234
Bram Moolenaar13600302014-05-22 18:26:40 +020010235 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010236 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010237" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010238 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010239" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010240 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010241" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10242 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010243 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010244 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10245 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10246 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10247 NetrwKeepj call histdel("/",-1)
10248 NetrwKeepj call histdel("/",-1)
10249 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010250 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010251 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10252 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010253 endif
10254 else
10255 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010256" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010257 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010258 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010259" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10260 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10261" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010262 endif
10263 endif
10264
10265 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010267" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010268 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10269 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010270 endif
10271 endif
10272
10273 if w:netrw_liststyle == s:LONGLIST
10274 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010275" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010276
10277 if s:method == "ftp"
10278 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010280 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010281 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010282 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010283 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010284 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010285 sil! NetrwKeepj 1
10286 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010287 let line2= line(".")
10288 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010289 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010290 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010291 endif
10292 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010293 exe "sil! NetrwKeepj ".line1
10294 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010295 endif
10296
10297 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010298" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010299 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 +000010300 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010301" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010302 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010303 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010304 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10305 NetrwKeepj call histdel("/",-1)
10306 NetrwKeepj call histdel("/",-1)
10307 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010308 endif
10309 endif
10310
10311" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010312" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010313" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010314
10315" call Dret("s:NetrwRemoteListing 0")
10316 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010317endfun
10318
Bram Moolenaar446cb832008-06-24 21:56:24 +000010319" ---------------------------------------------------------------------
10320" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10321fun! s:NetrwRemoteRm(usrhost,path) range
10322" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010323" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010324 let svpos= winsaveview()
10325" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010326
10327 let all= 0
10328 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10329 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010330" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010331 for fname in s:netrwmarkfilelist_{bufnr("%")}
10332 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010333 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010334 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010335 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010336 let all= 1
10337 endif
10338 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010339 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010340
10341 else
10342 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010343" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010344
10345 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010346 let keepsol = &l:sol
10347 setl nosol
10348 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010349
10350 " remove multiple files and directories
10351 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010352 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010353 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010354 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010355 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010356 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010357 let all= 1
10358 endif
10359 let ctr= ctr + 1
10360 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010361 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010362 endif
10363
10364 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010365" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010366 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010367" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10368 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010369
10370" call Dret("s:NetrwRemoteRm")
10371endfun
10372
10373" ---------------------------------------------------------------------
10374" s:NetrwRemoteRmFile: {{{2
10375fun! s:NetrwRemoteRmFile(path,rmfile,all)
10376" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10377
10378 let all= a:all
10379 let ok = ""
10380
10381 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10382 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010383" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010384 if !all
10385 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010386" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010387 call inputsave()
10388 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10389 call inputrestore()
10390 echohl NONE
10391 if ok == ""
10392 let ok="no"
10393 endif
10394 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010395 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010396 let all= 1
10397 endif
10398 endif
10399
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010400 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" 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 +000010402 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010403" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010404 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010405 if path =~ '^\a\{3,}://'
10406 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010407 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010408 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010409 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10410 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010412 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010413" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010414 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010415 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 let ok="q"
10417 else
10418 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010419" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10420" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10421" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010422 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010423 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010424 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010425 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010427" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010428 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010429 if v:shell_error != 0
10430 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010431 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 +010010432 else
10433 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10434 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010435 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010436 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010437 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010438" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010439 endif
10440 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010441 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010442" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010443 endif
10444
10445 else
10446 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010447" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 if !all
10449 call inputsave()
10450 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10451 call inputrestore()
10452 if ok == ""
10453 let ok="no"
10454 endif
10455 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010456 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010457 let all= 1
10458 endif
10459 endif
10460
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010461 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010462 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010463 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 else
10465 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010466 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10467" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010468 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010469" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470
10471 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010472" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10473 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10474" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010475 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010477
10478 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010479 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010480 endif
10481 endif
10482 endif
10483
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010484 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010485" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010486 endif
10487 endif
10488
10489" call Dret("s:NetrwRemoteRmFile ".ok)
10490 return ok
10491endfun
10492
10493" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494" s:NetrwRemoteRename: rename a remote file or directory {{{2
10495fun! s:NetrwRemoteRename(usrhost,path) range
10496" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10497
10498 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010499 let svpos = winsaveview()
10500" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010501 let ctr = a:firstline
10502 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10503
10504 " rename files given by the markfilelist
10505 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10506 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010507" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508 if exists("subfrom")
10509 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010510" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010511 else
10512 call inputsave()
10513 let newname= input("Moving ".oldname." to : ",oldname)
10514 call inputrestore()
10515 if newname =~ '^s/'
10516 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10517 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10518 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010519" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010520 endif
10521 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010522
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010524 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010525 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010526 let oldname= s:ShellEscape(a:path.oldname)
10527 let newname= s:ShellEscape(a:path.newname)
10528" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010529 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010530 endif
10531
10532 endfor
10533 call s:NetrwUnMarkFile(1)
10534
10535 else
10536
10537 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010538 let keepsol= &l:sol
10539 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010540 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010541 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542
10543 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010544" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010545
10546 call inputsave()
10547 let newname= input("Moving ".oldname." to : ",oldname)
10548 call inputrestore()
10549
10550 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10551 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10552 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010553 let oldname= s:ShellEscape(a:path.oldname)
10554 let newname= s:ShellEscape(a:path.newname)
10555" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010556 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 endif
10558
10559 let ctr= ctr + 1
10560 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010561 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562 endif
10563
10564 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010565 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010566" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10567 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010568
10569" call Dret("NetrwRemoteRename")
10570endfun
10571
Bram Moolenaar85850f32019-07-19 22:05:51 +020010572" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010573" Local Directory Browsing Support: {{{1
10574" ==========================================
10575
10576" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010577" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010578" Should accept: file://localhost/etc/fstab
10579" file:///etc/fstab
10580" file:///c:/WINDOWS/clock.avi
10581" file:///c|/WINDOWS/clock.avi
10582" file://localhost/c:/WINDOWS/clock.avi
10583" file://localhost/c|/WINDOWS/clock.avi
10584" file://c:/foo.txt
10585" file:///c:/foo.txt
10586" 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 +020010587fun! netrw#FileUrlEdit(fname)
10588" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010589 let fname = a:fname
10590 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010591" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010592 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010593" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010594 endif
10595 if (has("win32") || has("win95") || has("win64") || has("win16"))
10596 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010597" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010598 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010599" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010600 endif
10601 endif
10602 let fname2396 = netrw#RFC2396(fname)
10603 let fname2396e= fnameescape(fname2396)
10604 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10605 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010606" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010607 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010608" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010609 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10610 endif
10611 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010612
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010613" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10614" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010615 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010616 exe 'NetrwKeepj keepalt edit '.plainfname
10617 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10618
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010619" 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 +020010620" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010621 exe "sil doau BufReadPost ".fname2396e
10622endfun
10623
10624" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010625" netrw#LocalBrowseCheck: {{{2
10626fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010627 " This function is called by netrwPlugin.vim's s:LocalBrowse(), s:NetrwRexplore(),
10628 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10629 "
10630 " unfortunate interaction -- split window debugging can't be used here, must use
10631 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10632 " another call to LocalBrowseCheck() when attempts to write
10633 " to the DBG buffer are made.
10634 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635 " The &ft == "netrw" test was installed because the BufEnter event
10636 " would hit when re-entering netrw windows, creating unexpected
10637 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010638" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010639" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010640" 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 +020010641" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010642" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10643" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010644
Bram Moolenaar97d62492012-11-15 21:28:22 +010010645 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646 if isdirectory(s:NetrwFile(a:dirname))
10647" 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 +010010648
Bram Moolenaar97d62492012-11-15 21:28:22 +010010649 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10651" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010652 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010653
Bram Moolenaar446cb832008-06-24 21:56:24 +000010654 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010656 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010657
Bram Moolenaar5c736222010-01-06 20:54:52 +010010658 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010659" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010660 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010661 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010662 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" 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 +010010664" call Dret("netrw#LocalBrowseCheck")
10665 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010667
Bram Moolenaar85850f32019-07-19 22:05:51 +020010668 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010669 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10670 " AND IF the listing style is not a tree listing
10671 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010673 let ibuf = 1
10674 let buflast = bufnr("$")
10675 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10677 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010678 endif
10679 let ibuf= ibuf + 1
10680 endwhile
10681 endif
10682 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010683" 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>"))
10684" 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 +000010685 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010686" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687endfun
10688
10689" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010690" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010691" performed any shell command. The idea is to cause all local-browsing
10692" buffers to be refreshed after a user has executed some shell command,
10693" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010694fun! s:LocalBrowseRefresh()
10695" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10697" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010698
Bram Moolenaar446cb832008-06-24 21:56:24 +000010699 " determine which buffers currently reside in a tab
10700 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010701" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010702 return
10703 endif
10704 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010705" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010706 return
10707 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010708 if exists("s:netrw_events") && s:netrw_events == 1
10709 " s:LocalFastBrowser gets called (indirectly) from a
10710 let s:netrw_events= 2
10711" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10712 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010713 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010714 let itab = 1
10715 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010716 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010717 while itab <= tabpagenr("$")
10718 let buftablist = buftablist + tabpagebuflist()
10719 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010720 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010721 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010722" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10723" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010724 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10725 " | refresh any netrw window
10726 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010727 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010728 let ibl = 0
10729 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010730" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010731 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10732 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010733 " (ibuf not shown in a current window AND
10734 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010735" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10736 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010737 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010738" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010739 continue
10740 elseif index(tabpagebuflist(),ibuf) != -1
10741 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010742" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010743 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010744 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010745 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10746 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10747 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10748 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010749" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010750 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10751 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10752 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010753 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010754 endif
10755 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010756" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010757 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010758" call Decho("restore window: win_gotoid(".curwinid.")")
10759 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010760 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010761
Bram Moolenaara6878372014-03-22 21:02:50 +010010762" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010763endfun
10764
10765" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010766" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10767"
10768" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010769" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010770" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10771" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010772" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010773"
10774" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10775" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010776" (re-using a buffer may not be as accurate)
10777"
10778" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
10779" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10780" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10781" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10782" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010783fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010784" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10785" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10786" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10787" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010788
10789 " initialize browselist, a list of buffer numbers that the local browser has used
10790 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010791" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010792 let s:netrw_browselist= []
10793 endif
10794
10795 " append current buffer to fastbrowse list
10796 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010797" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010798 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010799" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010800 endif
10801
10802 " enable autocmd events to handle refreshing/removing local browser buffers
10803 " If local browse buffer is currently showing: refresh it
10804 " If local browse buffer is currently hidden : wipe it
10805 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10806 " =1 : medium speed, re-use directory listing for remote only
10807 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010808 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10809 let s:netrw_events= 1
10810 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010811 au!
10812 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010813" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010814 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010815 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010816" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010817 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010818 endif
10819 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010820
10821 " user must have changed fastbrowse to its fast setting, so remove
10822 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010823 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010824" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010825 unlet s:netrw_events
10826 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010827 au!
10828 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010829 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830 endif
10831
Bram Moolenaar85850f32019-07-19 22:05:51 +020010832" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833endfun
10834
10835" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010836" s:LocalListing: does the job of "ls" for local directories {{{2
10837fun! s:LocalListing()
10838" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010839" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10840" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10841" 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 +010010842
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010843" 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
10844" 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
10845" 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 +010010846
10847 " get the list of files contained in the current directory
10848 let dirname = b:netrw_curdir
10849 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010850 let filelist = s:NetrwGlob(dirname,"*",0)
10851 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010853
10854 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010856 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
10857 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010859 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010860" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010861 endif
10862
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010863" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010864" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010865" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010866
10867 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
10868 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10869 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010870" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
10871" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010872 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010873" 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 +010010874
10875 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010876" call Decho(" ",'~'.expand("<slnum>"))
10877" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010878
10879 if getftype(filename) == "link"
10880 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010881" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010882 let pfile= filename."@"
10883
10884 elseif getftype(filename) == "socket"
10885 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010887 let pfile= filename."="
10888
10889 elseif getftype(filename) == "fifo"
10890 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010891" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010892 let pfile= filename."|"
10893
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010894 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010895 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010896" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010897 let pfile= filename."/"
10898
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010900 if (has("win32") || has("win95") || has("win64") || has("win16"))
10901 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10902 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010904 let pfile= filename."*"
10905 else
10906 " normal file
10907 let pfile= filename
10908 endif
10909 elseif executable(filename)
10910 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010911" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010912 let pfile= filename."*"
10913 else
10914 " normal file
10915 let pfile= filename
10916 endif
10917
10918 else
10919 " normal file
10920 let pfile= filename
10921 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010922" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010923
10924 if pfile =~ '//$'
10925 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010926" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010927 endif
10928 let pfile= strpart(pfile,dirnamelen)
10929 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010930" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
10931" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010932
10933 if w:netrw_liststyle == s:LONGLIST
10934 let sz = getfsize(filename)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010935 let fsz = strpart(" ",1,15-strlen(sz)).sz
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010936 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010937 let sz= s:NetrwHumanReadable(sz)
10938 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010939 let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
10940 let pfile = longfile.fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010941" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010942 endif
10943
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010944 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010945 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010946" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010947 let t = getftime(filename)
10948 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010949" call Decho("exe NetrwKeepj put ='".ft.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010950 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010951 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010952
10953 elseif g:netrw_sort_by =~ "^s"
10954 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010955" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010956 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010957 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010958 let sz= s:NetrwHumanReadable(sz)
10959 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010960 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010961" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010962 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010963 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010964
10965 else
10966 " sort by name
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010967" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010968 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010969 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010970" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010010971 endfor
10972
10973 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010974 sil! NetrwKeepj g/^$/d
10975 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010976 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010977" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010978 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10979
10980" call Dret("s:LocalListing")
10981endfun
10982
10983" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010984" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10985fun! s:NetrwLocalExecute(cmd)
10986" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10987 let ykeep= @@
10988 " sanity check
10989 if !executable(a:cmd)
10990 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10991 let @@= ykeep
10992" call Dret("s:NetrwLocalExecute")
10993 return
10994 endif
10995
10996 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010997" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010998 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010999" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011000
11001 " strip any ansi escape sequences off
11002 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11003
11004 " show user the result(s)
11005 echomsg result
11006 let @@= ykeep
11007
11008" call Dret("s:NetrwLocalExecute")
11009endfun
11010
11011" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011012" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011013fun! s:NetrwLocalRename(path) range
11014" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11015
11016 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011017 let ykeep = @@
11018 let ctr = a:firstline
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011019 let svpos = winsaveview()
11020" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011021
11022 " rename files given by the markfilelist
11023 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11024 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011025" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011026 if exists("subfrom")
11027 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011028" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011029 else
11030 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011031 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011033 if newname =~ ''
11034 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11035 let newname = substitute(newname,'^.*','','')
11036 elseif newname =~ ''
11037 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11038 let newname = substitute(newname,'[^/]*','','')
11039 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011040 if newname =~ '^s/'
11041 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11042 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011043" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011044 let newname = substitute(oldname,subfrom,subto,'')
11045 endif
11046 endif
11047 call rename(oldname,newname)
11048 endfor
11049 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011050
Bram Moolenaar97d62492012-11-15 21:28:22 +010011051 else
11052
11053 " attempt to rename files/directories
11054 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011055 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011056
11057 " sanity checks
11058 if line(".") < w:netrw_bannercnt
11059 let ctr= ctr + 1
11060 continue
11061 endif
11062 let curword= s:NetrwGetWord()
11063 if curword == "./" || curword == "../"
11064 let ctr= ctr + 1
11065 continue
11066 endif
11067
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011068 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011069 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011070" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011071
11072 call inputsave()
11073 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11074 call inputrestore()
11075
11076 call rename(oldname,newname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011077" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011078
11079 let ctr= ctr + 1
11080 endwhile
11081 endif
11082
11083 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011084" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011085 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011086" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11087 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011088 let @@= ykeep
11089
11090" call Dret("NetrwLocalRename")
11091endfun
11092
11093" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011094" s:NetrwLocalRm: {{{2
11095fun! s:NetrwLocalRm(path) range
11096" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011097" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011098
11099 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011100 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011101 let ret = 0
11102 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011103 let svpos = winsaveview()
11104" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011105
11106 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11107 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011108" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011109 for fname in s:netrwmarkfilelist_{bufnr("%")}
11110 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011111 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011112 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011113 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011114 let all= 1
11115 endif
11116 endfor
11117 call s:NetrwUnMarkFile(1)
11118
11119 else
11120 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011122
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011123 let keepsol= &l:sol
11124 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011125 let ctr = a:firstline
11126 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011127 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011128
11129 " sanity checks
11130 if line(".") < w:netrw_bannercnt
11131 let ctr= ctr + 1
11132 continue
11133 endif
11134 let curword= s:NetrwGetWord()
11135 if curword == "./" || curword == "../"
11136 let ctr= ctr + 1
11137 continue
11138 endif
11139 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011140 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011141 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011142 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011143 let all= 1
11144 endif
11145 let ctr= ctr + 1
11146 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011148 endif
11149
11150 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011152 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011153 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011154" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11155 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011156 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011157 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011158
11159" call Dret("s:NetrwLocalRm")
11160endfun
11161
11162" ---------------------------------------------------------------------
11163" s:NetrwLocalRmFile: remove file fname given the path {{{2
11164" Give confirmation prompt unless all==1
11165fun! s:NetrwLocalRmFile(path,fname,all)
11166" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011167
Bram Moolenaar446cb832008-06-24 21:56:24 +000011168 let all= a:all
11169 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011170 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011171 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11172" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011173
11174 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11175 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011176" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011177 if !all
11178 echohl Statement
11179 call inputsave()
11180 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11181 call inputrestore()
11182 echohl NONE
11183 if ok == ""
11184 let ok="no"
11185 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011186" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011187 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011188" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011189 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011190 let all= 1
11191 endif
11192 endif
11193
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011194 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011195 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011196" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011197 endif
11198
11199 else
11200 " attempt to remove directory
11201 if !all
11202 echohl Statement
11203 call inputsave()
11204 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11205 call inputrestore()
11206 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11207 if ok == ""
11208 let ok="no"
11209 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011210 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011211 let all= 1
11212 endif
11213 endif
11214 let rmfile= substitute(rmfile,'[\/]$','','e')
11215
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011216 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +020011217 if v:version < 704 || (v:version == 704 && !has("patch1107"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011218" " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
11219 call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
11220" " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011221
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011222 if v:shell_error != 0
11223" " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11224 let errcode= s:NetrwDelete(rmfile)
11225" " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011226
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011227 if errcode != 0
11228 if has("unix")
11229" " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11230 call system("rm ".s:ShellEscape(rmfile))
11231 if v:shell_error != 0 && !exists("g:netrw_quiet")
11232 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
11233 let ok="no"
11234 endif
11235 elseif !exists("g:netrw_quiet")
11236 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011237 let ok="no"
11238 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011239 endif
11240 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011241 else
11242 if delete(rmfile,"d")
11243 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
11244 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011245 endif
11246 endif
11247 endif
11248
11249" call Dret("s:NetrwLocalRmFile ".ok)
11250 return ok
11251endfun
11252
Bram Moolenaar85850f32019-07-19 22:05:51 +020011253" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011254" Support Functions: {{{1
11255
Bram Moolenaar488c6512005-08-11 20:09:58 +000011256" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011257" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11258" 0: marked file list of current buffer
11259" 1: marked file target
11260fun! netrw#Access(ilist)
11261 if a:ilist == 0
11262 if exists("s:netrwmarkfilelist_".bufnr('%'))
11263 return s:netrwmarkfilelist_{bufnr('%')}
11264 else
11265 return "no-list-buf#".bufnr('%')
11266 endif
11267 elseif a:ilist == 1
11268 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011269 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011270endfun
11271
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011272" ---------------------------------------------------------------------
11273" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11274fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011275 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011276endfun
11277
Bram Moolenaara6878372014-03-22 21:02:50 +010011278" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011279" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11280" I expect this function to be used in
11281" :PChkAssert netrw#Expose("netrwmarkfilelist")
11282" for example.
11283fun! netrw#Expose(varname)
11284" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011285 if exists("s:".a:varname)
11286 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011287" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011288 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011289" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011290 if type(retval) == 3
11291 let retval = copy(retval)
11292 let i = 0
11293 while i < len(retval)
11294 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11295 let i = i + 1
11296 endwhile
11297 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011298" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011299 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011300 else
11301" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011302 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011303 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011304" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011305 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011306 endif
11307
11308" call Dret("netrw#Expose ".string(retval))
11309 return retval
11310endfun
11311
11312" ---------------------------------------------------------------------
11313" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11314fun! netrw#Modify(varname,newvalue)
11315" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11316 exe "let s:".a:varname."= ".string(a:newvalue)
11317" call Dret("netrw#Modify")
11318endfun
11319
11320" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011321" netrw#RFC2396: converts %xx into characters {{{2
11322fun! netrw#RFC2396(fname)
11323" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11324 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11325" call Dret("netrw#RFC2396 ".fname)
11326 return fname
11327endfun
11328
11329" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011330" netrw#UserMaps: supports user-specified maps {{{2
11331" see :help function()
11332"
11333" g:Netrw_UserMaps is a List with members such as:
11334" [[keymap sequence, function reference],...]
11335"
11336" The referenced function may return a string,
11337" refresh : refresh the display
11338" -other- : this string will be executed
11339" or it may return a List of strings.
11340"
11341" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011342" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011343" Related functions:
11344" netrw#Expose(varname) -- see s:varname variables
11345" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11346" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11347fun! netrw#UserMaps(islocal)
11348" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11349" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11350
11351 " set up usermaplist
11352 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11353" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11354 for umap in g:Netrw_UserMaps
11355" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11356" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11357 " if umap[0] is a string and umap[1] is a string holding a function name
11358 if type(umap[0]) == 1 && type(umap[1]) == 1
11359" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11360 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11361 else
11362 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11363 endif
11364 endfor
11365 endif
11366" call Dret("netrw#UserMaps")
11367endfun
11368
11369" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011370" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11371fun! netrw#WinPath(path)
11372" call Dfunc("netrw#WinPath(path<".a:path.">)")
11373 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11374 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011375 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011376 " remove trailing slash (Win95)
11377 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11378 " remove escaped spaces
11379 let path = substitute(path, '\ ', ' ', 'g')
11380 " convert slashes to backslashes
11381 let path = substitute(path, '/', '\', 'g')
11382 else
11383 let path= a:path
11384 endif
11385" call Dret("netrw#WinPath <".path.">")
11386 return path
11387endfun
11388
11389" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011390" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11391" cb : bl2mf=0 add marked files to buffer list
11392" cB : bl2mf=1 use bufferlist to mark files
11393" (mnemonic: cb = copy (marked files) to buffer list)
11394fun! s:NetrwBadd(islocal,bl2mf)
11395" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11396 if a:bl2mf
11397 " cB: add buffer list to marked files
11398 redir => bufl
11399 ls
11400 redir END
11401 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11402 for fname in bufl
11403 call s:NetrwMarkFile(a:islocal,fname)
11404 endfor
11405 else
11406 " cb: add marked files to buffer list
11407 for fname in s:netrwmarkfilelist_{bufnr("%")}
11408" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11409 exe "badd ".fnameescape(fname)
11410 endfor
11411 let curbufnr = bufnr("%")
11412 let curdir = s:NetrwGetCurdir(a:islocal)
11413 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11414 endif
11415" call Dret("s:NetrwBadd")
11416endfun
11417
11418" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011419" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11420fun! s:ComposePath(base,subdir)
11421" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11422
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011423 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011424" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011425 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011426 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011427 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011428 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011429 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011430 endif
11431
Bram Moolenaar85850f32019-07-19 22:05:51 +020011432 " COMBAK: test on windows with changing to root directory: :e C:/
11433 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011434" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011435 let ret= a:subdir
11436
Bram Moolenaar85850f32019-07-19 22:05:51 +020011437 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011438" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011439 if a:base =~ '[/\\]$'
11440 let ret= a:base.a:subdir
11441 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011442 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011443 endif
11444
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011445 elseif a:base =~ '^\a\{3,}://'
11446" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011447 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11448 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11449 if a:subdir == '../'
11450 if curpath =~ '[^/]/[^/]\+/$'
11451 let curpath= substitute(curpath,'[^/]\+/$','','')
11452 else
11453 let curpath=""
11454 endif
11455 let ret= urlbase.curpath
11456 else
11457 let ret= urlbase.curpath.a:subdir
11458 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011459" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11460" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11461" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011462
11463 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011464" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011465 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11466 if a:base =~ '^//'
11467 " keeping initial '//' for the benefit of network share listing support
11468 let ret= '/'.ret
11469 endif
11470 let ret= simplify(ret)
11471 endif
11472
11473" call Dret("s:ComposePath ".ret)
11474 return ret
11475endfun
11476
11477" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011478" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11479" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11480fun! s:DeleteBookmark(fname)
11481" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11482 call s:MergeBookmarks()
11483
11484 if exists("g:netrw_bookmarklist")
11485 let indx= index(g:netrw_bookmarklist,a:fname)
11486 if indx == -1
11487 let indx= 0
11488 while indx < len(g:netrw_bookmarklist)
11489 if g:netrw_bookmarklist[indx] =~ a:fname
11490 call remove(g:netrw_bookmarklist,indx)
11491 let indx= indx - 1
11492 endif
11493 let indx= indx + 1
11494 endwhile
11495 else
11496 " remove exact match
11497 call remove(g:netrw_bookmarklist,indx)
11498 endif
11499 endif
11500
11501" call Dret("s:DeleteBookmark")
11502endfun
11503
11504" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011505" s:FileReadable: o/s independent filereadable {{{2
11506fun! s:FileReadable(fname)
11507" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11508
11509 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011510 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011511 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011512 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011513 endif
11514
11515" call Dret("s:FileReadable ".ret)
11516 return ret
11517endfun
11518
11519" ---------------------------------------------------------------------
11520" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11521" Places correct suffix on end of temporary filename,
11522" using the suffix provided with fname
11523fun! s:GetTempfile(fname)
11524" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11525
11526 if !exists("b:netrw_tmpfile")
11527 " get a brand new temporary filename
11528 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011529" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011530
Bram Moolenaarc236c162008-07-13 17:41:49 +000011531 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011532" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011533
Bram Moolenaar9964e462007-05-05 17:54:07 +000011534 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011535 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11536" 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 +010011537 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011538" call Dret("s:GetTempfile getcwd<".getcwd().">")
11539 return ""
11540 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011541
Bram Moolenaar9964e462007-05-05 17:54:07 +000011542 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011543 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011544" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011545
Bram Moolenaar9964e462007-05-05 17:54:07 +000011546 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011547 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011548 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011549 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011550 if !exists("+shellslash") || !&ssl
11551 let tmpfile = substitute(tmpfile,'/','\','g')
11552 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011553 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011554 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011555 endif
11556 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011557" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011558 else
11559 " re-use temporary filename
11560 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011561" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011562 endif
11563
11564 " use fname's suffix for the temporary file
11565 if a:fname != ""
11566 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011567" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011568 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011569 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011570 elseif a:fname =~ '.txz$'
11571 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011572 else
11573 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11574 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011575" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011576 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011577" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011578 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011579" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011580 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11581 endif
11582 endif
11583
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011584" 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 +000011585" call Dret("s:GetTempfile <".tmpfile.">")
11586 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011587endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011588
11589" ---------------------------------------------------------------------
11590" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011591" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011592fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011593" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011594 if s:user == ""
11595 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11596 else
11597 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11598 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011599 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011600 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011601 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011602 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011603 else
11604 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11605 endif
11606" call Dret("s:MakeSshCmd <".sshcmd.">")
11607 return sshcmd
11608endfun
11609
11610" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011611" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11612fun! s:MakeBookmark(fname)
11613" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11614
11615 if !exists("g:netrw_bookmarklist")
11616 let g:netrw_bookmarklist= []
11617 endif
11618
11619 if index(g:netrw_bookmarklist,a:fname) == -1
11620 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011621 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011622 call add(g:netrw_bookmarklist,a:fname.'/')
11623 elseif a:fname !~ '/'
11624 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11625 else
11626 call add(g:netrw_bookmarklist,a:fname)
11627 endif
11628 call sort(g:netrw_bookmarklist)
11629 endif
11630
11631" call Dret("s:MakeBookmark")
11632endfun
11633
11634" ---------------------------------------------------------------------
11635" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11636fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011637" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011638 " get bookmarks from .netrwbook file
11639 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011640 if filereadable(s:NetrwFile(savefile))
11641" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011642 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011643" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011644 NetrwKeepj call delete(savefile)
11645 endif
11646" call Dret("s:MergeBookmarks")
11647endfun
11648
11649" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011650" s:NetrwBMShow: {{{2
11651fun! s:NetrwBMShow()
11652" call Dfunc("s:NetrwBMShow()")
11653 redir => bmshowraw
11654 menu
11655 redir END
11656 let bmshowlist = split(bmshowraw,'\n')
11657 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011658 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011659 if bmshowfuncs != []
11660 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011661 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011662 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011663 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011664 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011665 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011666" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11667endfun
11668
11669" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011670" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
11671fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011672 if !exists("w:netrw_liststyle")
11673 let w:netrw_liststyle= g:netrw_liststyle
11674 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011675" 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 +020011676
11677 if &ft != "netrw"
11678 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11679 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011680" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011681 let &l:cursorline = s:netrw_usercul
11682 let &l:cursorcolumn = s:netrw_usercuc
11683
11684 elseif g:netrw_cursor == 4
11685 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011686" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011687 setl cursorline
11688 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011689
11690 elseif g:netrw_cursor == 3
11691 " thin-long-tree: cursorline, user's cursorcolumn
11692 " wide : cursorline, cursorcolumn
11693 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011694" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011695 setl cursorline
11696 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011697 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011698" 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 +020011699 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011700 let &l:cursorcolumn = s:netrw_usercuc
11701 endif
11702
11703 elseif g:netrw_cursor == 2
11704 " thin-long-tree: cursorline, user's cursorcolumn
11705 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011706" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011707 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +020011708 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011709
11710 elseif g:netrw_cursor == 1
11711 " thin-long-tree: user's cursorline, user's cursorcolumn
11712 " wide : cursorline, user's cursorcolumn
11713 let &l:cursorcolumn = s:netrw_usercuc
11714 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011715" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011716 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011717 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011718" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011719 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011720 endif
11721
11722 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011723 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011724" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011725 let &l:cursorline = s:netrw_usercul
11726 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011727 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011728
11729" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011730endfun
11731
11732" ---------------------------------------------------------------------
11733" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11734fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011735" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011736 if exists("s:netrw_usercul")
11737 let &l:cursorline = s:netrw_usercul
11738 endif
11739 if exists("s:netrw_usercuc")
11740 let &l:cursorcolumn = s:netrw_usercuc
11741 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011742" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11743endfun
11744
11745" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011746" s:NetrwDelete: Deletes a file. {{{2
11747" Uses Steve Hall's idea to insure that Windows paths stay
11748" acceptable. No effect on Unix paths.
11749" Examples of use: let result= s:NetrwDelete(path)
11750fun! s:NetrwDelete(path)
11751" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11752
Bram Moolenaar5c736222010-01-06 20:54:52 +010011753 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011754 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
11755 if exists("+shellslash")
11756 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011757 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011758 let result = delete(path)
11759 let &shellslash = sskeep
11760 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011761" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011762 let result= delete(path)
11763 endif
11764 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011765" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011766 let result= delete(path)
11767 endif
11768 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011769 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011770 endif
11771
11772" call Dret("s:NetrwDelete ".result)
11773 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011774endfun
11775
11776" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011777" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011778fun! s:NetrwEnew(...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011779" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011780" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011781
Bram Moolenaar446cb832008-06-24 21:56:24 +000011782 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011783" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011784 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11785 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11786 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11787 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11788 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11789 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11790 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11791 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11792 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11793 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11794 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11795 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11796 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11797 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11798 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11799 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11800
Bram Moolenaar85850f32019-07-19 22:05:51 +020011801 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011802" call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011803 " when tree listing uses file TreeListing... a new buffer is made.
11804 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011805 " COMBAK: this causes a problem, see P43
11806" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011807 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011808 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011809 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011810" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011811 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011812
Bram Moolenaar446cb832008-06-24 21:56:24 +000011813 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011814" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011815 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11816 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11817 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11818 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11819 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11820 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11821 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11822 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11823 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11824 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11825 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11826 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11827 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11828 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11829 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11830 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11831
Bram Moolenaar5c736222010-01-06 20:54:52 +010011832 if a:0 > 0
11833 let b:netrw_curdir= a:1
11834 if b:netrw_curdir =~ '/$'
11835 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011836 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011837 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011838 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011839 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11840 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011841 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011842 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011843 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011844 endif
11845 endif
11846
Bram Moolenaar8d043172014-01-23 14:24:41 +010011847" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011848endfun
11849
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011850" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011851" s:NetrwExe: executes a string using "!" {{{2
11852fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011853" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011854 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020011855" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011856 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11857 set shell& shellcmdflag& shellxquote& shellxescape&
11858 set shellquote& shellpipe& shellredir& shellslash&
11859 exe a:cmd
11860 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11861 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011862" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011863 exe a:cmd
11864 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011865" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011866endfun
11867
11868" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011869" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11870fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011871 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011872" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011873 let curbuf = bufnr("%")
11874 let curwin = winnr()
11875 let iwin = 1
11876 while iwin <= winnr("$")
11877 exe iwin."wincmd w"
11878 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11879 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11880 let winvars= w:
11881 break
11882 endif
11883 let iwin= iwin + 1
11884 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011885 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011886 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011887" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011888 for k in keys(winvars)
11889 let w:{k}= winvars[k]
11890 endfor
11891 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011892" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011893 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011894endfun
11895
Bram Moolenaara6878372014-03-22 21:02:50 +010011896" ---------------------------------------------------------------------
11897" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011898" Returns: 0=success
11899" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011900fun! s:NetrwLcd(newdir)
11901" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
11902
Bram Moolenaar85850f32019-07-19 22:05:51 +020011903 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011904 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011905 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011906 catch /^Vim\%((\a\+)\)\=:E344/
11907 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11908 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011909 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011910 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11911 " forward slashes by earlier code; so check for both.
11912 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
11913 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11914 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011915 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011916 endif
11917 endif
11918 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011919 let err472= 1
11920 endtry
11921
11922 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011923 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11924 if exists("w:netrw_prvdir")
11925 let a:newdir= w:netrw_prvdir
11926 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011927 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011928" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011929 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011930" 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 +010011931 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011932 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011933" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11934 return -1
11935 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011936
Bram Moolenaar85850f32019-07-19 22:05:51 +020011937" call Dret("s:NetrwLcd 0")
11938 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011939endfun
11940
Bram Moolenaar9964e462007-05-05 17:54:07 +000011941" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011942" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11943" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11944fun! s:NetrwSaveWordPosn()
11945" call Dfunc("NetrwSaveWordPosn()")
11946 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11947" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11948endfun
11949
11950" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011951" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11952" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11953fun! s:NetrwHumanReadable(sz)
11954" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11955
11956 if g:netrw_sizestyle == 'h'
11957 if a:sz >= 1000000000
11958 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11959 elseif a:sz >= 10000000
11960 let sz = printf("%d",a:sz/1000000)."m"
11961 elseif a:sz >= 1000000
11962 let sz = printf("%.1f",a:sz/1000000.0)."m"
11963 elseif a:sz >= 10000
11964 let sz = printf("%d",a:sz/1000)."k"
11965 elseif a:sz >= 1000
11966 let sz = printf("%.1f",a:sz/1000.0)."k"
11967 else
11968 let sz= a:sz
11969 endif
11970
11971 elseif g:netrw_sizestyle == 'H'
11972 if a:sz >= 1073741824
11973 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11974 elseif a:sz >= 10485760
11975 let sz = printf("%d",a:sz/1048576)."M"
11976 elseif a:sz >= 1048576
11977 let sz = printf("%.1f",a:sz/1048576.0)."M"
11978 elseif a:sz >= 10240
11979 let sz = printf("%d",a:sz/1024)."K"
11980 elseif a:sz >= 1024
11981 let sz = printf("%.1f",a:sz/1024.0)."K"
11982 else
11983 let sz= a:sz
11984 endif
11985
11986 else
11987 let sz= a:sz
11988 endif
11989
11990" call Dret("s:NetrwHumanReadable ".sz)
11991 return sz
11992endfun
11993
11994" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011995" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11996" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11997fun! s:NetrwRestoreWordPosn()
11998" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011999 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012000" call Dret("NetrwRestoreWordPosn")
12001endfun
12002
12003" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012004" s:RestoreBufVars: {{{2
12005fun! s:RestoreBufVars()
12006" call Dfunc("s:RestoreBufVars()")
12007
12008 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12009 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12010 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12011 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12012 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12013 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12014
12015" call Dret("s:RestoreBufVars")
12016endfun
12017
12018" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012019" s:RemotePathAnalysis: {{{2
12020fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012021" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012022
Bram Moolenaara6878372014-03-22 21:02:50 +010012023 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012024 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012025 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012026 let s:user = substitute(a:dirname,dirpat,'\3','')
12027 let s:machine = substitute(a:dirname,dirpat,'\4','')
12028 let s:port = substitute(a:dirname,dirpat,'\5','')
12029 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012030 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012031 if s:machine =~ '@'
12032 let dirpat = '^\(.*\)@\(.\{-}\)$'
12033 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12034 let s:machine = substitute(s:machine,dirpat,'\2','')
12035 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012036
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012037" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12038" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12039" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12040" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12041" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12042" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012043
12044" call Dret("s:RemotePathAnalysis")
12045endfun
12046
12047" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012048" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12049" Returns status
12050" Runs system() on
12051" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012052" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012053fun! s:RemoteSystem(cmd)
12054" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12055 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012056 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 +000012057 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012058 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012059 else
12060 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12061 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12062 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012063 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012064 else
12065 let cmd= cmd.' '
12066 endif
12067 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012068" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012069 let ret= system(cmd)
12070 endif
12071" call Dret("s:RemoteSystem ".ret)
12072 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012073endfun
12074
12075" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012076" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012077fun! s:RestoreWinVars()
12078" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012079 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012080 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12081 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12082 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12083 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12084 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12085 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12086 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12087 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12088 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12089 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12090 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12091 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012092 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12093 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012094 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12095 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12096 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12097" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012098endfun
12099
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012100" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012101" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12102"
12103" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12104" is true) and a command, :Rexplore, which call this function.
12105"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012106" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012107"
12108" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012109fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012110 if exists("s:netrwdrag")
12111 return
12112 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012113" 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 +010012114" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12115" 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 +010012116
12117 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012118 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012119" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012120 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012121 unlet w:netrw_rexfile
12122" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012123 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012124" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012125" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12126" 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 +020012127 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012128
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012129 " ---------------------------
12130 " :Rex issued while in a file
12131 " ---------------------------
12132
Bram Moolenaara6878372014-03-22 21:02:50 +010012133 " record current file so :Rex can return to it from netrw
12134 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012135" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012136
12137 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012138" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012139 return
12140 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012141" 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 +020012142 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012143 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012144 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012145 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012146 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012147 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012148 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012149 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012150 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012151" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12152 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012153" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12154 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012155 if exists("s:rexposn_".bufnr('%'))
12156 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012157 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012158 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012159" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012160 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012161
Bram Moolenaar85850f32019-07-19 22:05:51 +020012162 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12163 if exists("s:explore_match")
12164 exe "2match netrwMarkFile /".s:explore_match."/"
12165 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012166 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012167
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012168" 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 +010012169" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012170endfun
12171
12172" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012173" s:SaveBufVars: save selected b: variables to s: variables {{{2
12174" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012175fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012176" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012177
12178 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12179 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12180 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12181 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12182 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12183 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12184
12185" call Dret("s:SaveBufVars")
12186endfun
12187
12188" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012189" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12190fun! s:SavePosn(posndict)
12191" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12192
Bram Moolenaar85850f32019-07-19 22:05:51 +020012193 if !exists("a:posndict[bufnr('%')]")
12194 let a:posndict[bufnr("%")]= []
12195 endif
12196" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12197 call add(a:posndict[bufnr("%")],winsaveview())
12198" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012199
12200" call Dret("s:SavePosn posndict")
12201 return a:posndict
12202endfun
12203
12204" ---------------------------------------------------------------------
12205" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12206fun! s:RestorePosn(posndict)
12207" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012208 if exists("a:posndict")
12209 if has_key(a:posndict,bufnr("%"))
12210" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12211 let posnlen= len(a:posndict[bufnr("%")])
12212 if posnlen > 0
12213 let posnlen= posnlen - 1
12214" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12215 call winrestview(a:posndict[bufnr("%")][posnlen])
12216 call remove(a:posndict[bufnr("%")],posnlen)
12217" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12218 endif
12219 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012220 endif
12221" call Dret("s:RestorePosn")
12222endfun
12223
12224" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012225" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012226fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012227" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012228 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12229 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12230 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12231 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12232 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12233 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12234 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12235 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12236 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12237 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12238 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12239 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12240 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12241 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12242 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12243 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12244 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12245 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12246" call Dret("s:SaveWinVars")
12247endfun
12248
12249" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012250" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012251" To allow separate windows to have their own activities, such as
12252" Explore **/pattern, several variables have been made window-oriented.
12253" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012254" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012255" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012256fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012257" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012258 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12259 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12260 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12261 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12262 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12263 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12264 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12265 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12266 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12267 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12268" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012269endfun
12270
12271" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012272" s:SetRexDir: set directory for :Rexplore {{{2
12273fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012274" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012275 let w:netrw_rexdir = a:dirname
12276 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012277 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012278" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12279" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012280" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012281" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012282" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012283endfun
12284
12285" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012286" s:ShowLink: used to modify thin and tree listings to show links {{{2
12287fun! s:ShowLink()
12288" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012289" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12290" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012291 if exists("b:netrw_curdir")
12292 norm! $?\a
12293 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12294 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012295" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12296" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12297" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12298 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012299 let dirlen = strlen(b:netrw_curdir)
12300 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012301" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012302 endif
12303 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012304" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12305" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012306 setl noro ma
12307 call setline(".",modline)
12308 setl ro noma nomod
12309 endif
12310" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12311endfun
12312
12313" ---------------------------------------------------------------------
12314" s:ShowStyle: {{{2
12315fun! s:ShowStyle()
12316 if !exists("w:netrw_liststyle")
12317 let liststyle= g:netrw_liststyle
12318 else
12319 let liststyle= w:netrw_liststyle
12320 endif
12321 if liststyle == s:THINLIST
12322 return s:THINLIST.":thin"
12323 elseif liststyle == s:LONGLIST
12324 return s:LONGLIST.":long"
12325 elseif liststyle == s:WIDELIST
12326 return s:WIDELIST.":wide"
12327 elseif liststyle == s:TREELIST
12328 return s:TREELIST.":tree"
12329 else
12330 return 'n/a'
12331 endif
12332endfun
12333
12334" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012335" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12336" Solution from Nicolai Weibull, vim docs (:help strlen()),
12337" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012338fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012339" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12340
12341 if v:version >= 703 && exists("*strdisplaywidth")
12342 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012343
Bram Moolenaar8d043172014-01-23 14:24:41 +010012344 elseif type(g:Align_xstrlen) == 1
12345 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12346 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012347
Bram Moolenaar8d043172014-01-23 14:24:41 +010012348 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012349 " number of codepoints (Latin a + combining circumflex is two codepoints)
12350 " (comment from TM, solution from NW)
12351 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012352
Bram Moolenaar8d043172014-01-23 14:24:41 +010012353 elseif g:Align_xstrlen == 2
12354 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012355 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12356 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012357 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012358
Bram Moolenaar8d043172014-01-23 14:24:41 +010012359 elseif g:Align_xstrlen == 3
12360 " virtual length (counting, for instance, tabs as anything between 1 and
12361 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012362 " preceded by lam, one otherwise, etc.)
12363 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012364 let modkeep= &l:mod
12365 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012366 call setline(line("."),a:x)
12367 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012368 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012369 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012370 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012371
Bram Moolenaar446cb832008-06-24 21:56:24 +000012372 else
12373 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012374 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012375 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012376" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012377 return ret
12378endfun
12379
12380" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012381" s:ShellEscape: shellescape(), or special windows handling {{{2
12382fun! s:ShellEscape(s, ...)
12383 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12384 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12385 endif
12386 let f = a:0 > 0 ? a:1 : 0
12387 return shellescape(a:s, f)
12388endfun
12389
12390" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012391" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012392fun! s:TreeListMove(dir)
12393" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012394 let curline = getline('.')
12395 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12396 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12397 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12398 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12399 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12400 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12401" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12402" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12403" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12404" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12405" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12406 " COMBAK : need to handle when on a directory
12407 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012408 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012409 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012410 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012411 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012412" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012413 elseif a:dir == '[]' && nxtline != ''
12414 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012415" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012416 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12417 if nl != 0
12418 NetrwKeepj norm! k
12419 else
12420 NetrwKeepj norm! G
12421 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012422" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012423 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012424 endif
12425
12426" call Dret("s:TreeListMove")
12427endfun
12428
12429" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012430" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12431" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12432" can't be called except via emenu. But due to locale, that menu line may not be called
12433" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12434fun! s:UpdateBuffersMenu()
12435" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012436 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012437 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012438 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012439 catch /^Vim\%((\a\+)\)\=:E/
12440 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012441 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012442 endtry
12443 endif
12444" call Dret("s:UpdateBuffersMenu")
12445endfun
12446
12447" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012448" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012449" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012450fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012451" call Dfunc("s:UseBufWinVars()")
12452 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012453 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12454 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12455 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12456 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12457 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12458 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12459 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12460 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12461 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 +000012462" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012463endfun
12464
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012465" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012466" s:UserMaps: supports user-defined UserMaps {{{2
12467" * calls a user-supplied funcref(islocal,curdir)
12468" * interprets result
12469" See netrw#UserMaps()
12470fun! s:UserMaps(islocal,funcname)
12471" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12472
12473 if !exists("b:netrw_curdir")
12474 let b:netrw_curdir= getcwd()
12475 endif
12476 let Funcref = function(a:funcname)
12477 let result = Funcref(a:islocal)
12478
12479 if type(result) == 1
12480 " if result from user's funcref is a string...
12481" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12482 if result == "refresh"
12483" call Decho("refreshing display",'~'.expand("<slnum>"))
12484 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12485 elseif result != ""
12486" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12487 exe result
12488 endif
12489
12490 elseif type(result) == 3
12491 " if result from user's funcref is a List...
12492" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12493 for action in result
12494 if action == "refresh"
12495" call Decho("refreshing display",'~'.expand("<slnum>"))
12496 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12497 elseif action != ""
12498" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12499 exe action
12500 endif
12501 endfor
12502 endif
12503
12504" call Dret("s:UserMaps")
12505endfun
12506
Bram Moolenaar85850f32019-07-19 22:05:51 +020012507" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012508" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012509" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012510let &cpo= s:keepcpo
12511unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012512
Bram Moolenaar85850f32019-07-19 22:05:51 +020012513" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012514" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012515" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012516" vim:ts=8 fdm=marker