blob: a5b47e06d55a30b2433b6fcb8c1d1bec771acd1f [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 Moolenaar85850f32019-07-19 22:05:51 +02003" Date: Jul 16, 2019
4" Version: 165
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
42let g:loaded_netrw = "v165"
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 Moolenaar85850f32019-07-19 22:05:51 +0200235 if executable("curl")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100236 let g:netrw_http_cmd = "curl"
Bram Moolenaar85850f32019-07-19 22:05:51 +0200237 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000238 elseif executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100239 let g:netrw_http_cmd = "wget"
240 call s:NetrwInit("g:netrw_http_xcmd","-q -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")
692 sil! let keepregstar = @*
693 sil! let keepregplus = @+
694 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200695 sil! let keepregslash= @/
696
Bram Moolenaar8d043172014-01-23 14:24:41 +0100697 " if dosplit
698 " -or- file has been modified AND file not hidden when abandoned
699 " -or- Texplore used
700 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100701" 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 +0200702 call s:SaveWinVars()
703 let winsz= g:netrw_winsize
704 if a:indx > 0
705 let winsz= a:indx
706 endif
707
708 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100709" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200710 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200711 if winsz == 0|let winsz= ""|endif
712 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100713" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200714
715 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100716" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200717 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200718 if winsz == 0|let winsz= ""|endif
719 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100720" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200721
722 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100723" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200724 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200725 if winsz == 0|let winsz= ""|endif
726 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100727" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200728
729 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100730" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200731 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200732 if winsz == 0|let winsz= ""|endif
733 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100734" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200735
736 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100737" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200738 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200739 if winsz == 0|let winsz= ""|endif
740 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100741" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200742
743 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100744" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200745 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200746 if winsz == 0|let winsz= ""|endif
747 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100748" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200749
750 elseif a:style == 6 " Texplore
751 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100752" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200753 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100754" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 call s:RestoreBufVars()
756 endif
757 call s:RestoreWinVars()
758" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100759" 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 +0200760 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100761 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200762
763 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100764" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200765 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100766" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200767 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100770" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
772 if dirname !~ '/$'
773 let dirname= dirname."/"
774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100775" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100777" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200778 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200780 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100781" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100783" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let dirname= a:1
787 endif
788 else
789 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 call s:NetrwClearExplore()
792" call Dret("netrw#Explore : cleared list")
793 return
794 endif
795
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100796" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200797 if dirname =~ '\.\./\=$'
798 let dirname= simplify(fnamemodify(dirname,':p:h'))
799 elseif dirname =~ '\.\.' || dirname == '.'
800 let dirname= simplify(fnamemodify(dirname,':p'))
801 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100802" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200803
804 if dirname =~ '^\*//'
805 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100806" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200807 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
808 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100809" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200810 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
811
812 elseif dirname =~ '^\*\*//'
813 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100814" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 let pattern= substitute(dirname,'^\*\*//','','')
816 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100817" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200818
819 elseif dirname =~ '/\*\*/'
820 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100821" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
823 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && (has("win32") || has("win95") || has("win64") || has("win16")))
824 let b:netrw_curdir = prefixdir
825 else
826 let b:netrw_curdir= getcwd().'/'.prefixdir
827 endif
828 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
829 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100830" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
831" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832
833 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200834 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200835 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100836" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200837
838 elseif dirname=~ '^\*\*/'
839 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
840 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842
843 else
844 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100845" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200846 endif
847
848 if starpat == 0 && a:indx >= 0
849 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100850" 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 +0200851 if dirname == ""
852 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100853" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200854 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200855 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200856 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200857 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200858 if dirname == ""
859 let dirname= getcwd()
860 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100862 " depending on whether backslashes have been converted to forward slashes by earlier code).
863 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200864 let dirname= b:netrw_curdir."/".dirname
865 endif
866 elseif dirname !~ '^/'
867 let dirname= b:netrw_curdir."/".dirname
868 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100869" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200870 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100871" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
872" 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 +0200873 endif
874 if exists("w:netrw_bannercnt")
875 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
876 " If one wants to return the same place in the netrw window, use :Rex instead.
877 exe w:netrw_bannercnt
878 endif
879
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100880" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200881 " ---------------------------------------------------------------------
882 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
883" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100884" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200885" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100886" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200887" endif
888 " ---------------------------------------------------------------------
889
890 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
891 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
892 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
893 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
894 elseif a:indx <= 0
895 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100896" 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 +0200897 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100898" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200899 let s:didstarstar= 1
900 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
901 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
902 endif
903
904 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100905" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200906 if !exists("w:netrw_explore_indx")
907 let w:netrw_explore_indx= 0
908 endif
909
910 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100911" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200912
913 if indx == -1
914 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100915" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200916 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100917 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 +0100918 if has("clipboard")
919 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +0200920 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +0100921 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200922 sil! let @/ = keepregslash
923" call Dret("netrw#Explore")
924 return
925 endif
926 let indx= w:netrw_explore_indx
927 if indx < 0 | let indx= 0 | endif
928 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
929 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100930" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200931 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
932 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100933" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 endwhile
935 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100936" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200937
938 elseif indx == -2
939 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100940" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200941 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100942 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 +0100943 if has("clipboard")
944 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +0200945 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +0100946 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200947 sil! let @/ = keepregslash
948" call Dret("netrw#Explore")
949 return
950 endif
951 let indx= w:netrw_explore_indx
952 if indx < 0 | let indx= 0 | endif
953 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
954 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100955" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200956 while indx >= 0 && curfile == w:netrw_explore_list[indx]
957 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100958" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 endwhile
960 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100961" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200962
963 else
964 " Explore -- initialize
965 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100966" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100967 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200968 let w:netrw_explore_indx= 0
969 if !exists("b:netrw_curdir")
970 let b:netrw_curdir= getcwd()
971 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100972" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200973
974 " switch on starpat to build the w:netrw_explore_list of files
975 if starpat == 1
976 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
978" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200979 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100980 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 catch /^Vim\%((\a\+)\)\=:E480/
982 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
983" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
984 return
985 endtry
986 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
987 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
988
989 elseif starpat == 2
990 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100991" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
992" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200993 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100994 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200995 catch /^Vim\%((\a\+)\)\=:E480/
996 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
997 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100998 if has("clipboard")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200999 sil! let @* = keepregstar
1000 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01001001 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001002 sil! let @/ = keepregslash
1003" call Dret("netrw#Explore : no files matched pattern")
1004 return
1005 endtry
1006 let s:netrw_curdir = b:netrw_curdir
1007 let w:netrw_explore_list = getqflist()
1008 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1009 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1010
1011 elseif starpat == 3
1012 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001013" 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 +02001014 let filepat= substitute(dirname,'^\*/','','')
1015 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001016" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1017" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001018 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1019 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1020
1021 elseif starpat == 4
1022 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001023" 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 +02001024 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1025 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1026 endif " switch on starpat to build w:netrw_explore_list
1027
1028 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001029" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1030" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001031
1032 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001033 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaara6878372014-03-22 21:02:50 +01001034 if has("clipboard")
1035 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001036 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01001037 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001038 sil! let @/ = keepregslash
1039" call Dret("netrw#Explore : no files matched")
1040 return
1041 endif
1042 endif " if indx ... endif
1043
1044 " NetrwStatusLine support - for exploring support
1045 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001046" 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 +02001047
1048 " wrap the indx around, but issue a note
1049 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001050" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001051 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1052 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001053 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001054 endif
1055
1056 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001057" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001058 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001059" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001060
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001061" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001062 call netrw#LocalBrowseCheck(newdir)
1063 if !exists("w:netrw_liststyle")
1064 let w:netrw_liststyle= g:netrw_liststyle
1065 endif
1066 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001067 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001068 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001069 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 endif
1071 let w:netrw_explore_mtchcnt = indx + 1
1072 let w:netrw_explore_bufnr = bufnr("%")
1073 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001074 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001075" 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 +02001076
1077 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001078" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001080 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 +02001081 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001082 if has("clipboard")
1083 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001084 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01001085 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 sil! let @/ = keepregslash
1087" call Dret("netrw#Explore : missing +path_extra")
1088 return
1089 endif
1090
1091 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001092" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001093 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1094 sil! unlet w:netrw_treedict
1095 sil! unlet w:netrw_treetop
1096 endif
1097 let newdir= dirname
1098 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001099 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001100 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001101 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001102 endif
1103 endif
1104
1105 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001106" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1107" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001109" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001110 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001111 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001112" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001113 let s:explore_prvdir = b:netrw_curdir
1114 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001115 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001116 if b:netrw_curdir !~ '/$'
1117 let dirlen= dirlen + 1
1118 endif
1119 let prvfname= ""
1120 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001121" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001122 if fname =~ '^'.b:netrw_curdir
1123 if s:explore_match == ""
1124 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1125 else
1126 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1127 endif
1128 elseif fname !~ '^/' && fname != prvfname
1129 if s:explore_match == ""
1130 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1131 else
1132 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1133 endif
1134 endif
1135 let prvfname= fname
1136 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001137" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001138 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1139 exe "2match netrwMarkFile /".s:explore_match."/"
1140 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001141 endif
1142 echo "<s-up>==Pexplore <s-down>==Nexplore"
1143 else
1144 2match none
1145 if exists("s:explore_match") | unlet s:explore_match | endif
1146 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
1147 echo " "
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001148" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001149 endif
1150
Bram Moolenaara6878372014-03-22 21:02:50 +01001151 " since Explore may be used to initialize netrw's browser,
1152 " there's no danger of a late FocusGained event on initialization.
1153 " Consequently, set s:netrw_events to 2.
1154 let s:netrw_events= 2
1155 if has("clipboard")
1156 sil! let @* = keepregstar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001157 sil! let @+ = keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01001158 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001159 sil! let @/ = keepregslash
1160" call Dret("netrw#Explore : @/<".@/.">")
1161endfun
1162
1163" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001164" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001165fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001166" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001167 let curwin= winnr()
1168
Bram Moolenaara6878372014-03-22 21:02:50 +01001169 if a:0 > 0 && a:1 != ""
1170 " if a netrw window is already on the left-side of the tab
1171 " and a directory has been specified, explore with that
1172 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001173" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001174 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001175" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001176 exe "1wincmd w"
1177 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001178" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001179 exe "Explore ".fnameescape(a1)
1180 exe curwin."wincmd w"
1181 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001182" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001183 unlet t:netrw_lexposn
1184 endif
1185" call Dret("netrw#Lexplore")
1186 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001187 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001188 exe curwin."wincmd w"
1189 else
1190 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001191" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001192 endif
1193
Bram Moolenaar8d043172014-01-23 14:24:41 +01001194 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001196 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001197" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001198 else
1199 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001200" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001202" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001203
1204 if lexwinnr > 0
1205 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001206" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001207 exe lexwinnr."wincmd w"
1208 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001209 let t:netrw_lexposn = winsaveview()
1210" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001211" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001212 close
1213 if lexwinnr < curwin
1214 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001215 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001216 if lexwinnr != curwin
1217 exe curwin."wincmd w"
1218 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001219 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001220" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001221
1222 else
1223 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001224" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001225 exe "1wincmd w"
1226 let keep_altv = g:netrw_altv
1227 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001228 if a:count != 0
1229 let netrw_winsize = g:netrw_winsize
1230 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001231 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001232 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001233" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001234 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 +02001235" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001236 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001237" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001238 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001240 elseif curfile =~ '^\a\{3,}://'
1241" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001242 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001243 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001244" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001245 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001246 endif
1247 if a:count != 0
1248 let g:netrw_winsize = netrw_winsize
1249 endif
1250 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251 let g:netrw_altv = keep_altv
1252 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001253" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1254" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001255 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001257" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1258 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001259 unlet t:netrw_lexposn
1260 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001261 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001262
1263 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001264 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 if a:rightside
1266 let g:netrw_chgwin= 1
1267 else
1268 let g:netrw_chgwin= 2
1269 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001270" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001271 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001272
Bram Moolenaar8d043172014-01-23 14:24:41 +01001273" call Dret("netrw#Lexplore")
1274endfun
1275
1276" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001277" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001278" supports :NetrwClean -- remove netrw from first directory on runtimepath
1279" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001280fun! netrw#Clean(sys)
1281" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001282
1283 if a:sys
1284 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1285 else
1286 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1287 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001288" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001289 let diddel= 0
1290 let diddir= ""
1291
1292 if choice == 1
1293 for dir in split(&rtp,',')
1294 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001295" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001296 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1297 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1298 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1299 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1300 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1301 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 +00001302 let diddir= dir
1303 let diddel= diddel + 1
1304 if !a:sys|break|endif
1305 endif
1306 endfor
1307 endif
1308
1309 echohl WarningMsg
1310 if diddel == 0
1311 echomsg "netrw is either not installed or not removable"
1312 elseif diddel == 1
1313 echomsg "removed one copy of netrw from <".diddir.">"
1314 else
1315 echomsg "removed ".diddel." copies of netrw"
1316 endif
1317 echohl None
1318
Bram Moolenaara6878372014-03-22 21:02:50 +01001319" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001320endfun
1321
Bram Moolenaar5c736222010-01-06 20:54:52 +01001322" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001323" netrw#MakeTgt: make a target out of the directory name provided {{{2
1324fun! netrw#MakeTgt(dname)
1325" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1326 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001327 let svpos = winsaveview()
1328" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001329 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1330" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001331 if s:netrwmftgt_islocal
1332 let netrwmftgt= simplify(a:dname)
1333 else
1334 let netrwmftgt= a:dname
1335 endif
1336 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1337 " re-selected target, so just clear it
1338 unlet s:netrwmftgt s:netrwmftgt_islocal
1339 else
1340 let s:netrwmftgt= netrwmftgt
1341 endif
1342 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001343 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001344 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001345" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1346 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001347" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001348endfun
1349
Bram Moolenaara6878372014-03-22 21:02:50 +01001350" ---------------------------------------------------------------------
1351" netrw#Obtain: {{{2
1352" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001353" islocal=0 obtain from remote source
1354" =1 obtain from local source
1355" fname : a filename or a list of filenames
1356" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001357fun! netrw#Obtain(islocal,fname,...)
1358" 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 +02001359 " NetrwStatusLine support - for obtaining support
1360
1361 if type(a:fname) == 1
1362 let fnamelist= [ a:fname ]
1363 elseif type(a:fname) == 3
1364 let fnamelist= a:fname
1365 else
1366 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 +01001367" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001368 return
1369 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001370" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001371 if a:0 > 0
1372 let tgtdir= a:1
1373 else
1374 let tgtdir= getcwd()
1375 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001376" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001377
1378 if exists("b:netrw_islocal") && b:netrw_islocal
1379 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001380" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001381 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1382 let topath= s:ComposePath(tgtdir,"")
1383 if (has("win32") || has("win95") || has("win64") || has("win16"))
1384 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001385" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001386 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001387" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001388 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001389 if v:shell_error != 0
1390 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 +01001391" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001392 return
1393 endif
1394 endfor
1395 else
1396 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001397" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1398 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1399" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001400 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001401 if v:shell_error != 0
1402 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 +01001403" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 return
1405 endif
1406 endif
1407 elseif !exists("b:netrw_curdir")
1408 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1409 else
1410 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1411 endif
1412
1413 else
1414 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001415" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001416 if type(a:fname) == 1
1417 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1418 endif
1419 call s:NetrwMethod(b:netrw_curdir)
1420
1421 if b:netrw_method == 4
1422 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001424 if exists("g:netrw_port") && g:netrw_port != ""
1425 let useport= " ".g:netrw_scpport." ".g:netrw_port
1426 else
1427 let useport= ""
1428 endif
1429 if b:netrw_fname =~ '/'
1430 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1431 else
1432 let path= ""
1433 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001434 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001435 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 +02001436
1437 elseif b:netrw_method == 2
1438 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001439" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001440 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001441 let tmpbufnr= bufnr("%")
1442 setl ff=unix
1443 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001444 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001445" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001446 endif
1447
1448 if exists("b:netrw_fname") && b:netrw_fname != ""
1449 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001450" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001451 endif
1452
1453 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001454 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001455" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001456 endif
1457 for fname in fnamelist
1458 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001460 endfor
1461 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462 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 +02001463 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001464 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001465 endif
1466 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1467 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1468 let debugkeep= &debug
1469 setl debug=msg
1470 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1471 let &debug= debugkeep
1472 endif
1473
1474 elseif b:netrw_method == 3
1475 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001476" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001477 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001478 let tmpbufnr= bufnr("%")
1479 setl ff=unix
1480
1481 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001482 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001485 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 endif
1488
1489 if exists("g:netrw_uid") && g:netrw_uid != ""
1490 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001491 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001492" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001493 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001494 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001495 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001496" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001497 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001498 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001499" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001500 endif
1501 endif
1502
1503 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001504 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001505" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001506 endif
1507
1508 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001509 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001510" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001511 endif
1512
1513 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001514 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001515" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001516 endif
1517
1518 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001519 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001520" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 endif
1522 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001523 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001524 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526
1527 " perform ftp:
1528 " -i : turns off interactive prompting from ftp
1529 " -n unix : DON'T use <.netrc>, even though it exists
1530 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001531 NetrwKeepj norm! 1Gdd
1532 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1534 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001537 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001538 endif
1539 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001540
1541 elseif b:netrw_method == 9
1542 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001543" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001544 if a:fname =~ '/'
1545 let localfile= substitute(a:fname,'^.*/','','')
1546 else
1547 let localfile= a:fname
1548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001549 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 +02001550
Bram Moolenaarff034192013-04-24 18:51:19 +02001551 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001552 " probably a badly formed url; protocol not recognized
1553" call Dret("netrw#Obtain : unsupported method")
1554 return
1555
1556 else
1557 " protocol recognized but not supported for Obtain (yet?)
1558 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001559 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001560 endif
1561" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001562 return
1563 endif
1564
1565 " restore status line
1566 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001567 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001568 endif
1569
1570 endif
1571
1572 " cleanup
1573 if exists("tmpbufnr")
1574 if bufnr("%") != tmpbufnr
1575 exe tmpbufnr."bw!"
1576 else
1577 q!
1578 endif
1579 endif
1580
Bram Moolenaara6878372014-03-22 21:02:50 +01001581" call Dret("netrw#Obtain")
1582endfun
1583
1584" ---------------------------------------------------------------------
1585" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1586fun! netrw#Nread(mode,fname)
1587" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001588 let svpos= winsaveview()
1589" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001590 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001591" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1592 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001593
1594 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1595 if exists("w:netrw_bannercnt")
1596 " start with cursor just after the banner
1597 exe w:netrw_bannercnt
1598 endif
1599 endif
1600" call Dret("netrw#Nread")
1601endfun
1602
1603" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001604" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1605" Options get restored by s:NetrwOptionsRestore()
1606"
1607" Option handling:
1608" * save user's options (s:NetrwOptionsSave)
1609" * set netrw-safe options (s:NetrwOptionsSafe)
1610" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1611" * restore user's options (s:netrwOPtionsRestore)
1612" - restore a user option when != safe option (s:NetrwRestoreSetting)
1613" vt: (variable type) normally its either "w:" or "s:"
1614fun! s:NetrwOptionsSave(vt)
1615" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1616" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
1617" 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>"))
1618
1619 if !exists("{a:vt}netrw_optionsave")
1620 let {a:vt}netrw_optionsave= 1
1621 else
1622" call Dret("s:NetrwOptionsSave : options already saved")
1623 return
1624 endif
1625" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1626
1627 " Save current settings and current directory
1628" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1629 let s:yykeep = @@
1630 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1631 let {a:vt}netrw_aikeep = &l:ai
1632 let {a:vt}netrw_awkeep = &l:aw
1633 let {a:vt}netrw_bhkeep = &l:bh
1634 let {a:vt}netrw_blkeep = &l:bl
1635 let {a:vt}netrw_btkeep = &l:bt
1636 let {a:vt}netrw_bombkeep = &l:bomb
1637 let {a:vt}netrw_cedit = &cedit
1638 let {a:vt}netrw_cikeep = &l:ci
1639 let {a:vt}netrw_cinkeep = &l:cin
1640 let {a:vt}netrw_cinokeep = &l:cino
1641 let {a:vt}netrw_comkeep = &l:com
1642 let {a:vt}netrw_cpokeep = &l:cpo
1643 let {a:vt}netrw_diffkeep = &l:diff
1644 let {a:vt}netrw_fenkeep = &l:fen
1645" call Decho("saving current settings: got here#1",'~'.expand("<slnum>"))
1646 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1647 let {a:vt}netrw_ffkeep = &l:ff
1648 endif
1649 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1650 let {a:vt}netrw_gdkeep = &l:gd " gdefault
1651 let {a:vt}netrw_hidkeep = &l:hidden
1652 let {a:vt}netrw_imkeep = &l:im
1653 let {a:vt}netrw_iskkeep = &l:isk
1654 let {a:vt}netrw_lskeep = &l:ls
1655 let {a:vt}netrw_makeep = &l:ma
1656 let {a:vt}netrw_magickeep = &l:magic
1657 let {a:vt}netrw_modkeep = &l:mod
1658 let {a:vt}netrw_nukeep = &l:nu
1659 let {a:vt}netrw_rnukeep = &l:rnu
1660 let {a:vt}netrw_repkeep = &l:report
1661 let {a:vt}netrw_rokeep = &l:ro
1662 let {a:vt}netrw_selkeep = &l:sel
1663 let {a:vt}netrw_spellkeep = &l:spell
1664" call Decho("saving current settings: got here#2",'~'.expand("<slnum>"))
1665 if !g:netrw_use_noswf
1666 let {a:vt}netrw_swfkeep = &l:swf
1667 endif
1668 let {a:vt}netrw_tskeep = &l:ts
1669 let {a:vt}netrw_twkeep = &l:tw " textwidth
1670 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1671 let {a:vt}netrw_wrapkeep = &l:wrap
1672 let {a:vt}netrw_writekeep = &l:write
1673
1674 " save a few selected netrw-related variables
1675" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1676 if g:netrw_keepdir
1677 let {a:vt}netrw_dirkeep = getcwd()
1678 endif
1679 if has("clipboard")
1680 sil! let {a:vt}netrw_starkeep = @*
1681 sil! let {a:vt}netrw_pluskeep = @+
1682 endif
1683 sil! let {a:vt}netrw_slashkeep= @/
1684
1685" 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>"))
1686" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1687endfun
1688
1689" ---------------------------------------------------------------------
1690" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1691" Use s:NetrwSaveOptions() to save user settings
1692" Use s:NetrwOptionsRestore() to restore user settings
1693fun! s:NetrwOptionsSafe(islocal)
1694" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1695" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1696" 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>"))
1697 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1698 call s:NetrwSetSafeSetting("&l:ai",0)
1699 call s:NetrwSetSafeSetting("&l:aw",0)
1700 call s:NetrwSetSafeSetting("&l:bl",0)
1701 call s:NetrwSetSafeSetting("&l:bomb",0)
1702 if a:islocal
1703 call s:NetrwSetSafeSetting("&l:bt","nofile")
1704 else
1705 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1706 endif
1707 call s:NetrwSetSafeSetting("&l:ci",0)
1708 call s:NetrwSetSafeSetting("&l:cin",0)
1709 call s:NetrwSetSafeSetting("&l:bh","hide")
1710 call s:NetrwSetSafeSetting("&l:cino","")
1711 call s:NetrwSetSafeSetting("&l:com","")
1712 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1713 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1714 setl fo=nroql2
1715 call s:NetrwSetSafeSetting("&l:hid",0)
1716 call s:NetrwSetSafeSetting("&l:im",0)
1717 setl isk+=@ isk+=* isk+=/
1718 call s:NetrwSetSafeSetting("&l:magic",1)
1719 if g:netrw_use_noswf
1720 call s:NetrwSetSafeSetting("swf",0)
1721 endif
1722 call s:NetrwSetSafeSetting("&l:report",10000)
1723 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1724 call s:NetrwSetSafeSetting("&l:spell",0)
1725 call s:NetrwSetSafeSetting("&l:tw",0)
1726 call s:NetrwSetSafeSetting("&l:wig","")
1727 setl cedit&
1728 call s:NetrwCursor()
1729
1730 " allow the user to override safe options
1731" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1732 if &ft == "netrw"
1733" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1734 keepalt NetrwKeepj doau FileType netrw
1735 endif
1736
1737" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1738" 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>"))
1739" call Dret("s:NetrwOptionsSafe")
1740endfun
1741
1742" ---------------------------------------------------------------------
1743" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1744fun! s:NetrwOptionsRestore(vt)
1745" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001746" 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 +01001747 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001748" 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>"))
1749" 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 +02001750" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001751 return
1752 endif
1753 unlet {a:vt}netrw_optionsave
1754
1755 if exists("+acd")
1756 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001757" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001758 let curdir = getcwd()
1759 let &l:acd = {a:vt}netrw_acdkeep
1760 unlet {a:vt}netrw_acdkeep
1761 if &l:acd
1762 call s:NetrwLcd(curdir)
1763 endif
1764 endif
1765 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001766 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1767 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1768 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1769 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1770 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1771 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1772 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1773 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1774 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1775 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1776 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1777 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1778 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1779 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1780 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001781 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001782 call s:NetrwRestoreSetting(a:vt."netrw_fokeep","&l:fo")
1783 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep","&l:gd")
1784 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep","&l:hidden")
1785 call s:NetrwRestoreSetting(a:vt."netrw_imkeep","&l:im")
1786 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep","&l:isk")
1787 call s:NetrwRestoreSetting(a:vt."netrw_lskeep","&l:ls")
1788 call s:NetrwRestoreSetting(a:vt."netrw_makeep","&l:ma")
1789 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
1790 call s:NetrwRestoreSetting(a:vt."netrw_modkeep","&l:mod")
1791 call s:NetrwRestoreSetting(a:vt."netrw_nukeep","&l:nu")
1792 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep","&l:rnu")
1793 call s:NetrwRestoreSetting(a:vt."netrw_repkeep","&l:report")
1794 call s:NetrwRestoreSetting(a:vt."netrw_rokeep","&l:ro")
1795 call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1796 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
1797 call s:NetrwRestoreSetting(a:vt."netrw_twkeep","&l:tw")
1798 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep","&l:wig")
1799 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep","&l:wrap")
1800 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1801 call s:NetrwRestoreSetting("s:yykeep","@@")
1802 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1803 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1804 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1805 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1806
Bram Moolenaara6878372014-03-22 21:02:50 +01001807 if exists("{a:vt}netrw_swfkeep")
1808 if &directory == ""
1809 " user hasn't specified a swapfile directory;
1810 " netrw will temporarily set the swapfile directory
1811 " to the current directory as returned by getcwd().
1812 let &l:directory= getcwd()
1813 sil! let &l:swf = {a:vt}netrw_swfkeep
1814 setl directory=
1815 unlet {a:vt}netrw_swfkeep
1816 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001817 if !g:netrw_use_noswf
1818 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1819 sil! let &l:swf= {a:vt}netrw_swfkeep
1820 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001821 unlet {a:vt}netrw_swfkeep
1822 endif
1823 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001824 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001825 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1826 if exists("{a:vt}netrw_dirkeep")
1827 call s:NetrwLcd(dirkeep)
1828 unlet {a:vt}netrw_dirkeep
1829 endif
1830 endif
1831 if has("clipboard")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001832 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1833 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001834 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001835 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001836
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001837" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1838" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1839" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1840" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1841" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001842 " Moved the filetype detect here from NetrwGetFile() because remote files
1843 " were having their filetype detect-generated settings overwritten by
1844 " NetrwOptionRestore.
1845 if &ft != "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001846" call Decho("filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001847 filetype detect
1848 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001849" 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 +02001850" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001851endfun
1852
1853" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001854" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1855" but only when the options' value and the safe setting differ
1856" Doing this means that netrw will not come up as having changed a
1857" setting last when it really didn't actually change it.
1858"
1859" Called from s:NetrwOptionsSafe
1860" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1861fun! s:NetrwSetSafeSetting(setting,safesetting)
1862" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001863
Bram Moolenaar85850f32019-07-19 22:05:51 +02001864 if a:setting =~ '^&'
1865" call Decho("fyi: a:setting starts with &")
1866 exe "let settingval= ".a:setting
1867" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001868
Bram Moolenaar85850f32019-07-19 22:05:51 +02001869 if settingval != a:safesetting
1870" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1871 if type(a:safesetting) == 0
1872 exe "let ".a:setting."=".a:safesetting
1873 elseif type(a:safesetting) == 1
1874 exe "let ".a:setting."= '".a:safesetting."'"
1875 else
1876 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1877 endif
1878 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001879 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001880
Bram Moolenaar85850f32019-07-19 22:05:51 +02001881" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001882endfun
1883
1884" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001885" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1886" but only if the setting value differs from the associated keepvar.
1887" Doing this means that netrw will not come up as having changed a
1888" setting last when it really didn't actually change it.
1889"
1890" Used by s:NetrwOptionsRestore() to restore each netrw-senstive setting
1891" keepvars are set up by s:NetrwOptionsSave
1892fun! s:NetrwRestoreSetting(keepvar,setting)
1893"" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001894
Bram Moolenaar85850f32019-07-19 22:05:51 +02001895 " typically called from s:NetrwOptionsRestore
1896 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1897 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1898 " Restores option (if different) from a keepvar
1899 if exists(a:keepvar)
1900 exe "let keepvarval= ".a:keepvar
1901 exe "let setting= ".a:setting
1902
1903"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1904"" call Decho("fyi: keepvarval=".keepvarval)
1905"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1906
1907 if setting != keepvarval
1908"" call Decho("restore setting<".a:setting."=".setting."> to keepvarval<".keepvarval.">")
1909 if type(a:setting) == 0
1910 exe "let ".a:setting."= ".keepvarval
1911 elseif type(a:setting) == 1
1912 exe "let ".a:setting."= '".keepvarval."'"
1913 else
1914 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1915 endif
1916 endif
1917
1918 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001919 endif
1920
Bram Moolenaar85850f32019-07-19 22:05:51 +02001921"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001922endfun
1923
1924" ---------------------------------------------------------------------
1925" NetrwStatusLine: {{{2
1926fun! NetrwStatusLine()
1927
1928" vvv NetrwStatusLine() debugging vvv
1929" let g:stlmsg=""
1930" if !exists("w:netrw_explore_bufnr")
1931" let g:stlmsg="!X<explore_bufnr>"
1932" elseif w:netrw_explore_bufnr != bufnr("%")
1933" let g:stlmsg="explore_bufnr!=".bufnr("%")
1934" endif
1935" if !exists("w:netrw_explore_line")
1936" let g:stlmsg=" !X<explore_line>"
1937" elseif w:netrw_explore_line != line(".")
1938" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1939" endif
1940" if !exists("w:netrw_explore_list")
1941" let g:stlmsg=" !X<explore_list>"
1942" endif
1943" ^^^ NetrwStatusLine() debugging ^^^
1944
1945 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")
1946 " restore user's status line
1947 let &stl = s:netrw_users_stl
1948 let &laststatus = s:netrw_users_ls
1949 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1950 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1951 return ""
1952 else
1953 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1954 endif
1955endfun
1956
Bram Moolenaar85850f32019-07-19 22:05:51 +02001957" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001958" Netrw Transfer Functions: {{{1
1959" ===============================
1960
Bram Moolenaar071d4272004-06-13 20:20:40 +00001961" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001962" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001963" mode: =0 read remote file and insert before current line
1964" =1 read remote file and insert after current line
1965" =2 replace with remote file
1966" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001967fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001968" 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 +00001969
Bram Moolenaar5c736222010-01-06 20:54:52 +01001970 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001971 call s:NetrwOptionsSave("w:")
1972 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001973 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001974 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1975 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1976 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001977" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001978
Bram Moolenaar5c736222010-01-06 20:54:52 +01001979 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001980 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001981 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001982 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001983 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001984 elseif a:mode == 2 " replace with remote file
1985 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001986 elseif a:mode == 3 " skip read of file (leave as temporary)
1987 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001988 else
1989 exe a:mode
1990 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001991 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001992 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001993" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001994
Bram Moolenaar5c736222010-01-06 20:54:52 +01001995 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001996 let tmpfile= s:GetTempfile("")
1997 if tmpfile == ""
1998" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001999 return
2000 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002001
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002002 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002003
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002004 " attempt to repeat with previous host-file-etc
2005 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002006" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002007 let choice = b:netrw_lastfile
2008 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002009
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002010 else
2011 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002012" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002013
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002014 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002015 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002016 echomsg 'NetRead Usage:'
2017 echomsg ':Nread machine:path uses rcp'
2018 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2019 echomsg ':Nread "machine id password path" uses ftp'
2020 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2021 echomsg ':Nread fetch://machine/path uses fetch'
2022 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2023 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002024 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002025 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002026 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2027 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2028 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2029 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002030 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002031 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002032
Bram Moolenaar9964e462007-05-05 17:54:07 +00002033 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002034 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002035" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002036 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002037 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002038 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002039 else
2040 " case "... ... ..."
2041 let choice = strpart(choice,1,strlen(choice)-1)
2042 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043
Bram Moolenaar9964e462007-05-05 17:54:07 +00002044 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002045 let wholechoice = wholechoice . " " . choice
2046 let ichoice = ichoice + 1
2047 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002048 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002049 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002050 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002051" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 return
2053 endif
2054 let choice= a:{ichoice}
2055 endwhile
2056 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2057 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 endif
2059 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002061" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002062 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002063
Bram Moolenaar5c736222010-01-06 20:54:52 +01002064 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002065 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002066 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002067" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002068 return
2069 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002070 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071
Bram Moolenaar8d043172014-01-23 14:24:41 +01002072 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002073" 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 +02002074 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002075" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002076 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002077" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002080
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002081 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002082 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002083 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002084 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2085 echo "(netrw) Processing your read request..."
2086 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002087
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002089 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002090 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002091" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002092 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002093 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002094 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002095 " ER: the tmpfile is full path: rcp sees C:\... as host C
2096 if s:netrw_has_nt_rcp == 1
2097 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2098 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2099 else
2100 " Any way needed it machine contains a '.'
2101 let uid_machine = g:netrw_machine .'.'. $USERNAME
2102 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002104 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2105 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2106 else
2107 let uid_machine = g:netrw_machine
2108 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002109 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002110 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 +00002111 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002112 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002113
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002114 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002115 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002116 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002117" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002118 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002119 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002120 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002121 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002122 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002123" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002124 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002125 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002126" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002127 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002128 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002129" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002130 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002131 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 +00002132 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002133 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002134 endif
2135 " 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 +00002136 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002137 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002138 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002139 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002140 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002141 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002142 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002143 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002144 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2145 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002146 q!
2147 endif
2148 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002149 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002151
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002153 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2155 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002156" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002157 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002158 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002159 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002160 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002162 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002163" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002165 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002166" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002168
Bram Moolenaar97d62492012-11-15 21:28:22 +01002169 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002170 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002171 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002172" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002173 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002174 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002176" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002177 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002178 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002179" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002180 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002181 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002182
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002183 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002184 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002186 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002187 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002188 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002189" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002190 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002191 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002192" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002193
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 " perform ftp:
2195 " -i : turns off interactive prompting from ftp
2196 " -n unix : DON'T use <.netrc>, even though it exists
2197 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002198 NetrwKeepj norm! 1Gdd
2199 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002200 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2201 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002202" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002203 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002204 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002205 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002206 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002208 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002210
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002211 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002212 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002213 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002214" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002215 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002216 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002217 else
2218 let useport= ""
2219 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002220 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2221 " This is workaround to avoid mis-handle windows local-path:
2222 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2223 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2224 else
2225 let tmpfile_get = tmpfile
2226 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002227 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 +00002228 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002230
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002231 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002232 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002233 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002235 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002236 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002237 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002238 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002239" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002240 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002241 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002242
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002243 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2244 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002245" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002246 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247 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 +00002248 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002249 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 +00002250 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002251 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002252
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002253 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002254 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002255" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002256 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2257 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2259" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2260 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 +00002261 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002262" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002263 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 endif
2265 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002266" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002267 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002268
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002269 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002270 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002271 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002272" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002273
Bram Moolenaar5c736222010-01-06 20:54:52 +01002274 if !executable(g:netrw_dav_cmd)
2275 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2276" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2277 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002279 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002280 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 +01002281 else
2282 " Construct execution string (four lines) which will be passed through filter
2283 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2284 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002285 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002286 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002287 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002288 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002289 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002290 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002291 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002292 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002293 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002294 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2295 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002296
Bram Moolenaar5c736222010-01-06 20:54:52 +01002297 " perform cadaver operation:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002298 NetrwKeepj norm! 1Gdd
2299 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002300 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002301 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002302 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002304
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002306 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002307 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002308" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002309 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 +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: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002315 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002316 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002317" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002318 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002319 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002320 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002321 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002322" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002323 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002324 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002325 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 let netrw_option= "http"
2327 else
2328 let netrw_option= "ftp"
2329 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002331
Bram Moolenaar446cb832008-06-24 21:56:24 +00002332 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333 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 +00002334 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002335 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 +00002336 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002337
Bram Moolenaar446cb832008-06-24 21:56:24 +00002338 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002339 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002341 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002342
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002343 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002344 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002345 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002346" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2347 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 +00002348 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002349 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002350
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002351 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002352 " NetRead: (file) NetRead Method #10 {{{3
2353 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002354" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2355 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002356 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2357 let b:netrw_lastfile = choice
2358
2359 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002360 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002361 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002362 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002363 endif
2364 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002365
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002367 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002368" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002369 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002370 unlet b:netrw_fname
2371 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002372 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 +01002373" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002374 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002375 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002376 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002377
Bram Moolenaar9964e462007-05-05 17:54:07 +00002378" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002379endfun
2380
2381" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002382" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002383fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002384" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002385
Bram Moolenaar5c736222010-01-06 20:54:52 +01002386 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002388 call s:NetrwOptionsSave("w:")
2389 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002390
Bram Moolenaar5c736222010-01-06 20:54:52 +01002391 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002392 let tmpfile= s:GetTempfile("")
2393 if tmpfile == ""
2394" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002395 return
2396 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002397
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002398 if a:0 == 0
2399 let ichoice = 0
2400 else
2401 let ichoice = 1
2402 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002403
Bram Moolenaar9964e462007-05-05 17:54:07 +00002404 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002405" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002406 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002407 " For binary writes, always write entire file.
2408 " (line numbers don't really make sense for that).
2409 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002410" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002411 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002412 elseif g:netrw_cygwin
2413 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002414 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002415" 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 +01002416 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002417 else
2418 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002419" 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 +01002420 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002421 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002422
Bram Moolenaar9964e462007-05-05 17:54:07 +00002423 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002424 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002425 " on the temporary file's name. Deletion of the temporary file during
2426 " cleanup then causes an error message.
2427 0file!
2428 endif
2429
Bram Moolenaar5c736222010-01-06 20:54:52 +01002430 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002431 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002432
Bram Moolenaar9964e462007-05-05 17:54:07 +00002433 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002434 " attempt to repeat with previous host-file-etc
2435 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002436" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 let choice = b:netrw_lastfile
2438 let ichoice= ichoice + 1
2439 else
2440 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002441
Bram Moolenaar8d043172014-01-23 14:24:41 +01002442 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002443 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002444 echomsg 'NetWrite Usage:"'
2445 echomsg ':Nwrite machine:path uses rcp'
2446 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2447 echomsg ':Nwrite "machine id password path" uses ftp'
2448 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2449 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2450 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2451 echomsg ':Nwrite rcp://machine/path uses rcp'
2452 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2453 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2454 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002455 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002456 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002457
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002458 elseif match(choice,"^\"") != -1
2459 if match(choice,"\"$") != -1
2460 " case "..."
2461 let choice=strpart(choice,1,strlen(choice)-2)
2462 else
2463 " case "... ... ..."
2464 let choice = strpart(choice,1,strlen(choice)-1)
2465 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002466
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002467 while match(choice,"\"$") == -1
2468 let wholechoice= wholechoice . " " . choice
2469 let ichoice = ichoice + 1
2470 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002471 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002472 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002473 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002474" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002475 return
2476 endif
2477 let choice= a:{ichoice}
2478 endwhile
2479 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2480 endif
2481 endif
2482 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002483 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002484" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002485
Bram Moolenaar9964e462007-05-05 17:54:07 +00002486 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002487 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002488 if !exists("b:netrw_method") || b:netrw_method < 0
2489" call Dfunc("netrw#NetWrite : unsupported method")
2490 return
2491 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002492
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002493 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002494 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002495 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002496 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2497 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002498" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002499 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: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002503 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002504" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 if s:netrw_has_nt_rcp == 1
2506 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2507 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2508 else
2509 let uid_machine = g:netrw_machine .'.'. $USERNAME
2510 endif
2511 else
2512 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2513 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2514 else
2515 let uid_machine = g:netrw_machine
2516 endif
2517 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002518 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 +00002519 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002520
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002521 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002522 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002523 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002524" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002525 let netrw_fname = b:netrw_fname
2526
2527 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2528 let bhkeep = &l:bh
2529 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002530 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002531 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002532
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002533" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002534 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002535 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002536" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002537 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002538 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002539" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002540 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002541 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002542" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002543 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002544 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 +00002545 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002546" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2547 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002548 endif
2549 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2550 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002551 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002552 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002553 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002554 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002556
2557 " remove enew buffer (quietly)
2558 let filtbuf= bufnr("%")
2559 exe curbuf."b!"
2560 let &l:bh = bhkeep
2561 exe filtbuf."bw!"
2562
Bram Moolenaar071d4272004-06-13 20:20:40 +00002563 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002564
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002565 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002566 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002567 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002568 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002569" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002570 let netrw_fname = b:netrw_fname
2571 let bhkeep = &l:bh
2572
2573 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2574 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002575 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002576 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002577 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002578
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002579 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002580 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002581" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002582 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002583 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002584" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002585 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002586 if exists("g:netrw_uid") && g:netrw_uid != ""
2587 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002588 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002590 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002591 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002592 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002593" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002594 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002595 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002596" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002597 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002598 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002599 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002600" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002601 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002602 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002603" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002604 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002605 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002606" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002607 " save choice/id/password for future use
2608 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002609
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002610 " perform ftp:
2611 " -i : turns off interactive prompting from ftp
2612 " -n unix : DON'T use <.netrc>, even though it exists
2613 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002614 NetrwKeepj norm! 1Gdd
2615 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002616 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2617 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002618 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002619 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002620 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002621 let mod=1
2622 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002623
2624 " remove enew buffer (quietly)
2625 let filtbuf= bufnr("%")
2626 exe curbuf."b!"
2627 let &l:bh= bhkeep
2628 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002629
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002630 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002631 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002632 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002633" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002634 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002635 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002636 else
2637 let useport= ""
2638 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002639 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 +00002640 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002641
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002642 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002644 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002645" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002646 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2647 if executable(curl)
2648 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002649 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 +01002650 elseif !exists("g:netrw_quiet")
Bram Moolenaar85850f32019-07-19 22:05:51 +02002651 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002652 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002653
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002654 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002655 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002656 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002657" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002658
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002659 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002660 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2661 let bhkeep = &l:bh
2662
2663 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2664 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002665 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002666 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002667
Bram Moolenaarff034192013-04-24 18:51:19 +02002668 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002669 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002671 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002672 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002673 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002674 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002675 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002676 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002678
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002679 " perform cadaver operation:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 NetrwKeepj norm! 1Gdd
2681 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002682
2683 " remove enew buffer (quietly)
2684 let filtbuf= bufnr("%")
2685 exe curbuf."b!"
2686 let &l:bh = bhkeep
2687 exe filtbuf."bw!"
2688
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002689 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002690
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002691 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002692 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002693 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002694" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002695 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 +00002696 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002697
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002698 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002699 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002700 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002701" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002702 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002703 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2704 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2705 else
2706 let uid_machine = g:netrw_machine
2707 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002708
2709 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2710 let bhkeep = &l:bh
2711 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002712 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002713 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002714
Bram Moolenaarff034192013-04-24 18:51:19 +02002715 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002716 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002717" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002718 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002719 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002720 let filtbuf= bufnr("%")
2721 exe curbuf."b!"
2722 let &l:bh = bhkeep
2723 exe filtbuf."bw!"
2724 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002725
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002726 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002727 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002728 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002729 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002730 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002732 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002733
Bram Moolenaar5c736222010-01-06 20:54:52 +01002734 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002735" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002736 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002737" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002738 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002739 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002740 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002741
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002742 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002743 " restore modifiability; usually equivalent to set nomod
2744 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002745" 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 +02002746 elseif !exists("leavemod")
2747 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002748" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002749 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002750" 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 +00002751 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002752
Bram Moolenaar9964e462007-05-05 17:54:07 +00002753" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002754endfun
2755
2756" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002757" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002758" uses NetRead to get a copy of the file into a temporarily file,
2759" then sources that file,
2760" then removes that file.
2761fun! netrw#NetSource(...)
2762" call Dfunc("netrw#NetSource() a:0=".a:0)
2763 if a:0 > 0 && a:1 == '?'
2764 " give help
2765 echomsg 'NetSource Usage:'
2766 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2767 echomsg ':Nsource fetch://machine/path uses fetch'
2768 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002769 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002770 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2771 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2772 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2773 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2774 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002775 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002776 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002777 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002778 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002780 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002781" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002782 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002783" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002784 if delete(s:netrw_tmpfile)
2785 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2786 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002787 unlet s:netrw_tmpfile
2788 else
2789 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2790 endif
2791 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002792 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002793 endif
2794" call Dret("netrw#NetSource")
2795endfun
2796
Bram Moolenaar8d043172014-01-23 14:24:41 +01002797" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002798" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2799" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002800fun! netrw#SetTreetop(iscmd,...)
2801" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2802" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002803
Bram Moolenaar85850f32019-07-19 22:05:51 +02002804 " iscmd==0: netrw#SetTreetop called using gn mapping
2805 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2806" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002807 " clear out the current tree
2808 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002809" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002810 let inittreetop= w:netrw_treetop
2811 unlet w:netrw_treetop
2812 endif
2813 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002814" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002815 unlet w:netrw_treedict
2816 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002817" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002818
Bram Moolenaar85850f32019-07-19 22:05:51 +02002819 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002820 let treedir= s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002822 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823 if isdirectory(s:NetrwFile(a:1))
2824" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002825 let treedir= a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002826 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar8d043172014-01-23 14:24:41 +01002827 let treedir= b:netrw_curdir."/".a:1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002828" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002829 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002830 " normally the cursor is left in the message window.
2831 " However, here this results in the directory being listed in the message window, which is not wanted.
2832 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002833 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002834 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaara6878372014-03-22 21:02:50 +01002835 let treedir= "."
Bram Moolenaar8d043172014-01-23 14:24:41 +01002836 endif
2837 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002838" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002839
2840 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002841 let islocal= expand("%") !~ '^\a\{3,}://'
2842" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002843
2844 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002845 if islocal
2846 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2847 else
2848 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2849 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002850
Bram Moolenaara6878372014-03-22 21:02:50 +01002851" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002852endfun
2853
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002855" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856" readcmd == %r : replace buffer with newly read file
2857" == 0r : read file at top of buffer
2858" == r : read file after current line
2859" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002860fun! s:NetrwGetFile(readcmd, tfile, method)
2861" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862
2863 " readcmd=='t': simply do nothing
2864 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002865" 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 +00002866" call Dret("NetrwGetFile : skip read of <".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002867 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002868 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002869
Bram Moolenaar9964e462007-05-05 17:54:07 +00002870 " get name of remote filename (ie. url and all)
2871 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002872" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002873
Bram Moolenaar9964e462007-05-05 17:54:07 +00002874 if exists("*NetReadFixup")
2875 " for the use of NetReadFixup (not otherwise used internally)
2876 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002877 endif
2878
Bram Moolenaar9964e462007-05-05 17:54:07 +00002879 if a:readcmd[0] == '%'
2880 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002881" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002882
2883 " rename the current buffer to the temp file (ie. tfile)
2884 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002886 else
2887 let tfile= a:tfile
2888 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002889 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002890
2891 " edit temporary file (ie. read the temporary file in)
2892 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002894 call zip#Browse(tfile)
2895 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002897 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002898 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002900 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002901 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002902" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002903 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002904 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002906 call tar#Browse(tfile)
2907 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002908" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002909 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002910 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002911" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002912 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002913 endif
2914
2915 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002916 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002917
Bram Moolenaar97d62492012-11-15 21:28:22 +01002918 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002919 " Note that isk must not include a "/" for scripts.vim
2920 " to process this detection correctly.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002921" call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002922 let iskkeep= &l:isk
2923 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002924 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002925" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002926 let line1 = 1
2927 let line2 = line("$")
2928
Bram Moolenaar8d043172014-01-23 14:24:41 +01002929 elseif !&ma
2930 " 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 +01002931 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002932" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002933 return
2934
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935 elseif s:FileReadable(a:tfile)
2936 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002937" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002938 let curline = line(".")
2939 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002940" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002941 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002942 let line1= curline + 1
2943 let line2= line("$") - lastline + 1
2944
2945 else
2946 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002947" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2948" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002949 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002950" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 return
2952 endif
2953
2954 " User-provided (ie. optional) fix-it-up command
2955 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002956" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002957 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002958" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002959" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960 endif
2961
Bram Moolenaaradc21822011-04-01 18:03:16 +02002962 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002963 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002964 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965 endif
2966
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" 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 +00002968
2969 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002970" redraw!
2971
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002972" 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 +00002973" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002974endfun
2975
Bram Moolenaar9964e462007-05-05 17:54:07 +00002976" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002977" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002978" Input:
2979" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2980" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002981" b:netrw_method= 1: rcp
2982" 2: ftp + <.netrc>
2983" 3: ftp + machine, id, password, and [path]filename
2984" 4: scp
2985" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002986" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002987" 7: rsync
2988" 8: fetch
2989" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002990" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002991" g:netrw_machine= hostname
2992" b:netrw_fname = filename
2993" g:netrw_port = optional port number (for ftp)
2994" g:netrw_choice = copy of input url (choice)
2995fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002996" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002997
Bram Moolenaar251e1912011-06-19 05:09:16 +02002998 " sanity check: choice should have at least three slashes in it
2999 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3000 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3001 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003002" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003003 return
3004 endif
3005
Bram Moolenaar5c736222010-01-06 20:54:52 +01003006 " record current g:netrw_machine, if any
3007 " curmachine used if protocol == ftp and no .netrc
3008 if exists("g:netrw_machine")
3009 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003010" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003011 else
3012 let curmachine= "N O T A HOST"
3013 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003014 if exists("g:netrw_port")
3015 let netrw_port= g:netrw_port
3016 endif
3017
3018 " insure that netrw_ftp_cmd starts off every method determination
3019 " with the current g:netrw_ftp_cmd
3020 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003021
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003022 " initialization
3023 let b:netrw_method = 0
3024 let g:netrw_machine = ""
3025 let b:netrw_fname = ""
3026 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003027 let g:netrw_choice = a:choice
3028
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003029 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003030 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003031 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3032 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003033 " rcpurm : rcp://[user@]host/filename Use rcp
3034 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003035 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003036 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003037 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003038 " rsyncurm : rsync://host[:port]/path Use rsync
3039 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3040 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003041 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003042 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3043 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003044 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3045 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003046 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003047 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003048 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003049 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003050 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003051 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003052 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003053 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003054
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003055" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003056 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003057 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003058 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003059" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003060 let b:netrw_method = 1
3061 let userid = substitute(a:choice,rcpurm,'\1',"")
3062 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3063 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003064 if userid != ""
3065 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003067
Bram Moolenaaradc21822011-04-01 18:03:16 +02003068 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003069 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003070" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003071 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003072 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3073 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3074 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003075
Bram Moolenaar15146672011-10-20 22:22:38 +02003076 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003077 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003078" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003079 let b:netrw_method = 5
3080 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3081 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003082 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003083
Bram Moolenaaradc21822011-04-01 18:03:16 +02003084 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003085 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003086" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003087 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003088 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003089 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3090 else
3091 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3092 endif
3093 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003094
Bram Moolenaaradc21822011-04-01 18:03:16 +02003095 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003096 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003097" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003098 let b:netrw_method = 7
3099 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3100 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003101
Bram Moolenaaradc21822011-04-01 18:03:16 +02003102 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003103 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003104" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003105 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3107 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3108 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003109" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003110 if userid != ""
3111 let g:netrw_uid= userid
3112 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003113
Bram Moolenaaradc21822011-04-01 18:03:16 +02003114 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003115 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003116 call NetUserPass("ftp:".g:netrw_machine)
3117 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003118 " if there's a change in hostname, require password re-entry
3119 unlet s:netrw_passwd
3120 endif
3121 if exists("netrw_port")
3122 unlet netrw_port
3123 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003124 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003125
Bram Moolenaar446cb832008-06-24 21:56:24 +00003126 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let b:netrw_method = 3
3128 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003129 let host= substitute(g:netrw_machine,'\..*$','','')
3130 if exists("s:netrw_hup[host]")
3131 call NetUserPass("ftp:".host)
3132
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003133 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003134" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3135" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003136 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003137 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003138" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003139 endif
3140 let b:netrw_method= 2
3141 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003142" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 let b:netrw_method= 2
3144 else
3145 if !exists("g:netrw_uid") || g:netrw_uid == ""
3146 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003147 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003148 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003149 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003150 endif
3151 let b:netrw_method= 3
3152 endif
3153 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003154
Bram Moolenaaradc21822011-04-01 18:03:16 +02003155 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003157" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003158 let b:netrw_method = 8
3159 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3160 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3161 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3162 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003163
Bram Moolenaaradc21822011-04-01 18:03:16 +02003164 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003165 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003166" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003168 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3169 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003170 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003171 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003172 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003173
Bram Moolenaaradc21822011-04-01 18:03:16 +02003174 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003175 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003176" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003177 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 let b:netrw_method = 3
3179 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3180 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003181
Bram Moolenaar9964e462007-05-05 17:54:07 +00003182 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 let b:netrw_method = 2
3184 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3185 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3186 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003187
Bram Moolenaaradc21822011-04-01 18:03:16 +02003188 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003189 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003190" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003191 let b:netrw_method = 9
3192 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3193 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003194
Bram Moolenaaradc21822011-04-01 18:03:16 +02003195 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003196 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003197" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003198 let b:netrw_method = 1
3199 let userid = substitute(a:choice,rcphf,'\2',"")
3200 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3201 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003202" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3203" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3204" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3205" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003206 if userid != ""
3207 let g:netrw_uid= userid
3208 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003209
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003210 " Method#10: file://user@hostname/...path-to-file {{{3
3211 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003212" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003213 let b:netrw_method = 10
3214 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003215" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003216
Bram Moolenaaradc21822011-04-01 18:03:16 +02003217 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003218 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003219 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003220 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003221 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003222 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003224 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003225
Bram Moolenaar81695252004-12-29 20:58:21 +00003226 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003227 " remove any leading [:#] from port number
3228 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3229 elseif exists("netrw_port")
3230 " retain port number as implicit for subsequent ftp operations
3231 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003232 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003233
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003234" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3235" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3236" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3237" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003238" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003239" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003240" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003241" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003242" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003243" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003244" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003245" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247
3248" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003249" NetReadFixup: this sort of function is typically written by the user {{{2
3250" to handle extra junk that their system's ftp dumps
3251" into the transfer. This function is provided as an
3252" example and as a fix for a Windows 95 problem: in my
3253" experience, win95's ftp always dumped four blank lines
3254" at the end of the transfer.
3255if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3256 fun! NetReadFixup(method, line1, line2)
3257" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003258
3259 " sanity checks -- attempt to convert inputs to integers
3260 let method = a:method + 0
3261 let line1 = a:line1 + 0
3262 let line2 = a:line2 + 0
3263 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3264" call Dret("NetReadFixup")
3265 return
3266 endif
3267
Bram Moolenaar9964e462007-05-05 17:54:07 +00003268 if method == 3 " ftp (no <.netrc>)
3269 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003270 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003271 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003272 call histdel("/",-1)
3273 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003274 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003275
Bram Moolenaar9964e462007-05-05 17:54:07 +00003276" call Dret("NetReadFixup")
3277 endfun
3278endif
3279
3280" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003281" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003282" Usage: :call NetUserPass() -- will prompt for userid and password
3283" :call NetUserPass("uid") -- will prompt for password
3284" :call NetUserPass("uid","password") -- sets global userid and password
3285" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3286" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287fun! NetUserPass(...)
3288
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003289" call Dfunc("NetUserPass() a:0=".a:0)
3290
3291 if !exists('s:netrw_hup')
3292 let s:netrw_hup= {}
3293 endif
3294
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003296 " case: no input arguments
3297
3298 " change host and username if not previously entered; get new password
3299 if !exists("g:netrw_machine")
3300 let g:netrw_machine= input('Enter hostname: ')
3301 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003303 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304 let g:netrw_uid= input('Enter username: ')
3305 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003306 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003307 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003308
3309 " set up hup database
3310 let host = substitute(g:netrw_machine,'\..*$','','')
3311 if !exists('s:netrw_hup[host]')
3312 let s:netrw_hup[host]= {}
3313 endif
3314 let s:netrw_hup[host].uid = g:netrw_uid
3315 let s:netrw_hup[host].passwd = s:netrw_passwd
3316
3317 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003318 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003319
3320 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003321 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003322 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003323" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003324 let host = substitute(a:1,'^ftp:','','')
3325 let host = substitute(host,'\..*','','')
3326 if exists("s:netrw_hup[host]")
3327 let g:netrw_uid = s:netrw_hup[host].uid
3328 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003329" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3330" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003331 else
3332 let g:netrw_uid = input("Enter UserId: ")
3333 let s:netrw_passwd = inputsecret("Enter Password: ")
3334 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003335
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003336 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003337 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003338" 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 +02003339 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003340 if g:netrw_machine =~ '[0-9.]\+'
3341 let host= g:netrw_machine
3342 else
3343 let host= substitute(g:netrw_machine,'\..*$','','')
3344 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003345 else
3346 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003347 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003348 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003349" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003350 if exists("g:netrw_passwd")
3351 " ask for password if one not previously entered
3352 let s:netrw_passwd= g:netrw_passwd
3353 else
3354 let s:netrw_passwd = inputsecret("Enter Password: ")
3355 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003356 endif
3357
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003358" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003359 if exists("host")
3360 if !exists('s:netrw_hup[host]')
3361 let s:netrw_hup[host]= {}
3362 endif
3363 let s:netrw_hup[host].uid = g:netrw_uid
3364 let s:netrw_hup[host].passwd = s:netrw_passwd
3365 endif
3366
3367 elseif a:0 == 2
3368 let g:netrw_uid = a:1
3369 let s:netrw_passwd = a:2
3370
3371 elseif a:0 == 3
3372 " enter hostname, user-id, and password into the hup dictionary
3373 let host = substitute(a:1,'^\a\+:','','')
3374 let host = substitute(host,'\..*$','','')
3375 if !exists('s:netrw_hup[host]')
3376 let s:netrw_hup[host]= {}
3377 endif
3378 let s:netrw_hup[host].uid = a:2
3379 let s:netrw_hup[host].passwd = a:3
3380 let g:netrw_uid = s:netrw_hup[host].uid
3381 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003382" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3383" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003385
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003386" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388
Bram Moolenaar85850f32019-07-19 22:05:51 +02003389" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003390" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003391" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003393" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003394" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3395fun! s:ExplorePatHls(pattern)
3396" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3397 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003398" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003399 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003400" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003401 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3402" call Dret("s:ExplorePatHls repat<".repat.">")
3403 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003404endfun
3405
3406" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003407" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003408" 0: (user: <mb>) bookmark current directory
3409" 1: (user: <gb>) change to the bookmarked directory
3410" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003411" 3: (browsing) records current directory history
3412" 4: (user: <u>) go up (previous) directory, using history
3413" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003414" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003415fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003416" 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 +02003417 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3418" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3419 return
3420 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003421
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003422 let ykeep = @@
3423 let curbufnr = bufnr("%")
3424
Bram Moolenaar9964e462007-05-05 17:54:07 +00003425 if a:chg == 0
3426 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003427" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003428 if exists("s:netrwmarkfilelist_{curbufnr}")
3429 call s:NetrwBookmark(0)
3430 echo "bookmarked marked files"
3431 else
3432 call s:MakeBookmark(a:curdir)
3433 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003434 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003435
3436 elseif a:chg == 1
3437 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003438" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003439 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003440" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003441 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003442 else
3443 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3444 endif
3445
3446 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003447" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003448 let didwork= 0
3449 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003450" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003451 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003452" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003453 let cnt= 1
3454 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003455" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003456 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003457 let didwork = 1
3458 let cnt = cnt + 1
3459 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003460 endif
3461
3462 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003463 " Note: history is saved only when PerformListing is done;
3464 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3465 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003466 let first = 1
3467 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003468 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003469 while ( first || cnt != g:netrw_dirhistcnt )
3470" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003471 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003472" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003473 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003474 let didwork= 1
3475 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003476 let histcnt = histcnt + 1
3477 let first = 0
3478 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003479 if cnt < 0
3480 let cnt= cnt + g:netrw_dirhistmax
3481 endif
3482 endwhile
3483 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003484 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003485 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003486 if didwork
3487 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3488 endif
3489
3490 elseif a:chg == 3
3491 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003492" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003493 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 +02003494 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003495 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3496 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003497 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003498" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003499 endif
3500
3501 elseif a:chg == 4
3502 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003504 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003505 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3506 if g:netrw_dirhistcnt < 0
3507 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003508 endif
3509 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003510 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003511 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003512 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3513" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003514 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003515 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003516" call Decho("setl ma noro",'~'.expand("<slnum>"))
3517 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003518 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003519" call Decho("setl nomod",'~'.expand("<slnum>"))
3520" 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 +00003521 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003522" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3523 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003524 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003525 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003526 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003527 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003528 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003529 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003530 echo "Sorry, no predecessor directory exists yet"
3531 endif
3532
3533 elseif a:chg == 5
3534 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003535" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003536 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003537 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3538 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3539" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003540 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003541" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003542 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003543 sil! NetrwKeepj %d _
3544" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3545" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003546 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003547" 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 +02003548 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003549" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3550 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003551 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003552 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3553 if g:netrw_dirhistcnt < 0
3554 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003555 endif
3556 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003557 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003558 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003559 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003560 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003561 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003562
3563 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003564" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003565 if exists("s:netrwmarkfilelist_{curbufnr}")
3566 call s:NetrwBookmark(1)
3567 echo "removed marked files from bookmarks"
3568 else
3569 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003570 let iremove = v:count
3571 let dremove = g:netrw_bookmarklist[iremove - 1]
3572" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003573 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003574" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3575 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3576 echo "removed ".dremove." from g:netrw_bookmarklist"
3577" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003578 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003579" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003580 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003581 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003582 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003583 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003584" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003585endfun
3586
3587" ---------------------------------------------------------------------
3588" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003589" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003590" Sister function: s:NetrwBookHistSave()
3591fun! s:NetrwBookHistRead()
3592" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003593 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003594" 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 +02003595 return
3596 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003597 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003598
3599 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003600 if !exists("s:netrw_initbookhist")
3601 let home = s:NetrwHome()
3602 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003603 if filereadable(s:NetrwFile(savefile))
3604" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003605 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003606 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003607
3608 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003609 if g:netrw_dirhistmax > 0
3610 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003611 if filereadable(s:NetrwFile(savefile))
3612" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003613 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003614 endif
3615 let s:netrw_initbookhist= 1
3616 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003617 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003618 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003619
Bram Moolenaar97d62492012-11-15 21:28:22 +01003620 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003621" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3622" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003623" call Dret("s:NetrwBookHistRead")
3624endfun
3625
3626" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003627" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003628" Sister function: s:NetrwBookHistRead()
3629" I used to do this via viminfo but that appears to
3630" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003631" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3632" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003633" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003634fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003635" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003636 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003637" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003638 return
3639 endif
3640
Bram Moolenaar5c736222010-01-06 20:54:52 +01003641 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003642" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003643 1split
3644 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003645" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003646 if g:netrw_use_noswf
3647 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3648 else
3649 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3650 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003651 setl nocin noai noci magic nospell nohid wig= noaw
3652 setl ma noro write
3653 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003654 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003655
Bram Moolenaar85850f32019-07-19 22:05:51 +02003656 " rename enew'd file: .netrwhist -- no attempt to merge
3657 " record dirhistmax and current dirhistcnt
3658 " save history
3659" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003660 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003661 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003662 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3663 if g:netrw_dirhistmax > 0
3664 let lastline = line("$")
3665 let cnt = g:netrw_dirhistcnt
3666 let first = 1
3667 while ( first || cnt != g:netrw_dirhistcnt )
3668 let lastline= lastline + 1
3669 if exists("g:netrw_dirhist_{cnt}")
3670 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3671" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3672 endif
3673 let first = 0
3674 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3675 if cnt < 0
3676 let cnt= cnt + g:netrw_dirhistmax
3677 endif
3678 endwhile
3679 exe "sil! w! ".savefile
3680" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3681 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003682
Bram Moolenaar85850f32019-07-19 22:05:51 +02003683 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003684 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003685 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003686" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003687 " merge and write .netrwbook
3688 let savefile= s:NetrwHome()."/.netrwbook"
3689
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003690 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003691 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003692 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693 for bdm in booklist
3694 if index(g:netrw_bookmarklist,bdm) == -1
3695 call add(g:netrw_bookmarklist,bdm)
3696 endif
3697 endfor
3698 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699 endif
3700
3701 " construct and save .netrwbook
3702 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003703 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003704" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003705 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003706
3707 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003708 let bgone= bufnr("%")
3709 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003710 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003711
3712" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003713endfun
3714
3715" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003716" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3717" list of the contents of a local or remote directory. It is assumed that the
3718" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3719" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003720" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003721fun! s:NetrwBrowse(islocal,dirname)
3722 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003723" 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 +02003724" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3725" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3726" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003727
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003728 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3729 " This is useful when one edits a local file, then :e ., then :Rex
3730 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3731 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003732" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003733 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003734
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003735 " s:NetrwBrowse : initialize history {{{3
3736 if !exists("s:netrw_initbookhist")
3737 NetrwKeepj call s:NetrwBookHistRead()
3738 endif
3739
3740 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003741 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003743" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744 else
3745 let dirname= a:dirname
3746 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003747
Bram Moolenaar85850f32019-07-19 22:05:51 +02003748 " repoint t:netrw_lexbufnr if appropriate
3749 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3750" call Decho("set repointlexbufnr to true!")
3751 let repointlexbufnr= 1
3752 endif
3753
3754 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003755 if exists("s:netrw_skipbrowse")
3756 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003757" 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 +01003758" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003759 return
3760 endif
3761 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003762 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003763" call Dret("s:NetrwBrowse : missing shellescape()")
3764 return
3765 endif
3766 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003767 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003768" call Dret("s:NetrwBrowse : missing fnameescape()")
3769 return
3770 endif
3771
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003772 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003773 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003774
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003775 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003776 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3777 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3778" call Decho("clearing marked files",'~'.expand("<slnum>"))
3779 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3780 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003781 endif
3782
3783 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003784 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003785" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3786" 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 +02003787 if s:NetrwLcd(dirname)
3788" call Dret("s:NetrwBrowse : lcd failure")
3789 return
3790 endif
3791 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003792" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003793
Bram Moolenaar5c736222010-01-06 20:54:52 +01003794 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003795 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003796" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003797 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003798" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003799 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003800 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003801 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003802" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003803
3804 " remove any filetype indicator from end of dirname, except for the
3805 " "this is a directory" indicator (/).
3806 " There shouldn't be one of those here, anyway.
3807 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003808" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003809 call s:RemotePathAnalysis(dirname)
3810
3811 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3812 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003813 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003814 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003815" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003816 let b:netrw_curdir = dirname
3817 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003818 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003819 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3820 sil call netrw#NetRead(2,url)
3821 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003822" call Decho("url<".url.">",'~'.expand("<slnum>"))
3823" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3824" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003825 if s:path =~ '.bz2'
3826 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3827 elseif s:path =~ '.gz'
3828 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3829 elseif s:path =~ '.gz'
3830 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3831 else
3832 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3833 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003834 endif
3835
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003836 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003837 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003838 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003839" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003840 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003841" 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 +00003842
Bram Moolenaar446cb832008-06-24 21:56:24 +00003843" call Dret("s:NetrwBrowse : file<".s:fname.">")
3844 return
3845 endif
3846
Bram Moolenaaradc21822011-04-01 18:03:16 +02003847 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003848 call s:UseBufWinVars()
3849
3850 " set up some variables {{{3
3851 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003852 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853 let s:last_sort_by = g:netrw_sort_by
3854
3855 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003857
Bram Moolenaar97d62492012-11-15 21:28:22 +01003858 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003859" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003860 let svpos = winsaveview()
3861" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003862 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863
Bram Moolenaar446cb832008-06-24 21:56:24 +00003864 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003865 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3866 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3867" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3868" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3869 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3870 else
3871" " call Decho("2match none",'~'.expand("<slnum>"))
3872 2match none
3873 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003874 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003875 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003876 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003877" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003878 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003879" 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 +01003880" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003881 return
3882 endif
3883
3884 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003885" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003886 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003887 if b:netrw_curdir =~ '[/\\]$'
3888 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3889 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003890 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3891 let b:netrw_curdir= b:netrw_curdir."/"
3892 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003893 if b:netrw_curdir == ''
3894 if has("amiga")
3895 " On the Amiga, the empty string connotes the current directory
3896 let b:netrw_curdir= getcwd()
3897 else
3898 " under unix, when the root directory is encountered, the result
3899 " from the preceding substitute is an empty string.
3900 let b:netrw_curdir= '/'
3901 endif
3902 endif
3903 if !a:islocal && b:netrw_curdir !~ '/$'
3904 let b:netrw_curdir= b:netrw_curdir.'/'
3905 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003906" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003907
3908 " ------------
3909 " (local only) {{{3
3910 " ------------
3911 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003912" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003913
3914 " Set up ShellCmdPost handling. Append current buffer to browselist
3915 call s:LocalFastBrowser()
3916
3917 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3918 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003919" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3920" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003922 if s:NetrwLcd(b:netrw_curdir)
3923" call Dret("s:NetrwBrowse : lcd failure")
3924 return
3925 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003926 endif
3927 endif
3928
3929 " --------------------------------
3930 " remote handling: {{{3
3931 " --------------------------------
3932 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003933" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003934
Bram Moolenaar97d62492012-11-15 21:28:22 +01003935 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003936" 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 +02003937 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003938 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003939" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003940 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3941 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3942 if dirname !~ '/$'
3943 let dirname= dirname.'/'
3944 endif
3945 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003946" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003947 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003948 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003949" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003950 endif
3951
3952 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3953 if dirname !~ dirpat
3954 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003955 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003956 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003957 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003958" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003959 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003960" 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 +00003961" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3962 return
3963 endif
3964 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003965" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003966 endif " (additional remote handling)
3967
Bram Moolenaar85850f32019-07-19 22:05:51 +02003968 " -------------------------------
3969 " Perform Directory Listing: {{{3
3970 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003971 NetrwKeepj call s:NetrwMaps(a:islocal)
3972 NetrwKeepj call s:NetrwCommands(a:islocal)
3973 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003974
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003975 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003976 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003977" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3978
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979 " If there is a rexposn: restore position with rexposn
3980 " Otherwise : set rexposn
3981 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003982" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
3983 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3984 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3985 NetrwKeepj exe w:netrw_bannercnt
3986 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003987 else
3988 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3989 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003990 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003991 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003992" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01003993 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003994 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003995
Bram Moolenaar85850f32019-07-19 22:05:51 +02003996 " repoint t:netrw_lexbufnr if appropriate
3997 if exists("repointlexbufnr")
3998 let t:netrw_lexbufnr= bufnr("%")
3999" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4000 endif
4001
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004002 " restore position
4003 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004004" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4005 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004006 endif
4007
Bram Moolenaara6878372014-03-22 21:02:50 +01004008 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004009 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4010 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004011" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4012" 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 +02004013" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004014 return
4015endfun
4016
4017" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004018" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4019" may not apply correctly; ie. netrw's idea of the current directory may
4020" differ from vim's. This function insures that netrw's idea of the current
4021" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004022" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004023fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004024" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4025" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4026" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4027" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4028" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004029
4030 " clean up any leading treedepthstring
4031 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4032 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004033" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004034 else
4035 let fname= a:fname
4036 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004037
4038 if g:netrw_keepdir
4039 " vim's idea of the current directory possibly may differ from netrw's
4040 if !exists("b:netrw_curdir")
4041 let b:netrw_curdir= getcwd()
4042 endif
4043
4044 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004045 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004047 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004048" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004049 else
4050 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004051 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004052" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004053 endif
4054
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004055 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004056 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004057 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004058" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059 else
4060 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004061 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004062" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004063 endif
4064 else
4065 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004066 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004067" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4068" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4069" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004070 endif
4071
Bram Moolenaar85850f32019-07-19 22:05:51 +02004072" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004073 return ret
4074endfun
4075
4076" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004077" s:NetrwFileInfo: supports qf (query for file information) {{{2
4078fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004079" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004080 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004081 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004082 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004083 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004084 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004085 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004086 let lsopt= "-lsadh --si"
4087 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004088 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004089
4090 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004091 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004092" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004093
Bram Moolenaara6878372014-03-22 21:02:50 +01004094 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004095 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004096" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004097
4098 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004099 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004100" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004101
Bram Moolenaar446cb832008-06-24 21:56:24 +00004102 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004103" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004104 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004105" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004106 endif
4107 else
4108 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004109" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4110 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004111 let fname= substitute(a:fname,".$","","")
4112 else
4113 let fname= a:fname
4114 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115 let t = getftime(s:NetrwFile(fname))
4116 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004117 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 let sz= s:NetrwHumanReadable(sz)
4119 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4121" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004122 endif
4123 else
4124 echo "sorry, \"qf\" not supported yet for remote files"
4125 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004126 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004127" call Dret("s:NetrwFileInfo")
4128endfun
4129
4130" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004131" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4132fun! s:NetrwFullPath(filename)
4133" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4134 let filename= a:filename
4135 if filename !~ '^/'
4136 let filename= resolve(getcwd().'/'.filename)
4137 endif
4138 if filename != "/" && filename =~ '/$'
4139 let filename= substitute(filename,'/$','','')
4140 endif
4141" " call Dret("s:NetrwFullPath <".filename.">")
4142 return filename
4143endfun
4144
4145" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004146" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004147" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004148" 1=re-used buffer (buffer not cleared)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004149fun! s:NetrwGetBuffer(islocal,dirname)
4150" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004151" 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 +02004152" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4153" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004154 let dirname= a:dirname
4155
4156 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004157" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004158 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004159" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004160 let s:netrwbuf= {}
4161 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004162" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4163" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4164
4165 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4166 let bufnum = -1
4167
4168 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4169 if has_key(s:netrwbuf,"NetrwTreeListing")
4170 let bufnum= s:netrwbuf["NetrwTreeListing"]
4171 else
4172 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4173 endif
4174" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4175 if !bufexists(bufnum)
4176 call remove(s:netrwbuf,"NetrwTreeListing"])
4177 let bufnum= -1
4178 endif
4179 elseif bufnr("NetrwTreeListing") != -1
4180 let bufnum= bufnr("NetrwTreeListing")
4181" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4182 else
4183" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4184 let bufnum= -1
4185 endif
4186
4187 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004188 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004189" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004190 if !bufexists(bufnum)
4191 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4192 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004193 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004194
Bram Moolenaar446cb832008-06-24 21:56:24 +00004195 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004196" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004197 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004198 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004199" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4200
4201 " highjack the current buffer if
4202 " it has the desired name
4203 " it is empty
4204" call Decho("deciding if I can highjack the current buffer#".bufnr("%"),'~'.expand("<slnum>"))
4205" call Decho("..dirname<".dirname.">",'~'.expand("<slnum>"))
4206" call Decho("..bufname<".bufname("%").">",'~'.expand("<slnum>"))
4207" call Decho("..getline($)<".getline("$").">",'~'.expand("<slnum>"))
4208 if dirname == bufname("%") && line("$") == 1 && getline("%") == ""
4209" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4210 return 0
4211 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004212
4213 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004214 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004215" 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 +00004216 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004217" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004218 " name the buffer
4219 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4220 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004221" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004222 let w:netrw_treebufnr = bufnr("%")
4223 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004224 if g:netrw_use_noswf
4225 setl nobl bt=nofile noswf
4226 else
4227 setl nobl bt=nofile
4228 endif
4229 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4230 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4231 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4232 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004233" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004234 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004235 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004236 " enter the new buffer into the s:netrwbuf dictionary
4237 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4238" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4239" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004240 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004241" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004242
4243 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004244" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004245 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004246 setl ei=all
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004247 if getline(2) =~# '^" Netrw Directory Listing'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004248" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
4249 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004250 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004251" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
4252 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004253 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004254" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004255 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004256 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004257 endif
4258 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004259
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004260 if line("$") <= 1 && getline(1) == ""
4261 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004262 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004263" 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>"))
4264" 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 +01004265" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4266 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004267
Bram Moolenaar97d62492012-11-15 21:28:22 +01004268 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004269" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004270 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004271 sil NetrwKeepj %d _
4272" 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>"))
4273" 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 +01004274" 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 +00004275 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004276
Bram Moolenaar446cb832008-06-24 21:56:24 +00004277 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004278" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4279" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004280 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004281 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004282 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004283" 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>"))
4284" 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 +01004285" 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 +00004286 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004287
Bram Moolenaar446cb832008-06-24 21:56:24 +00004288 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004289" 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>"))
4290" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4291" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004292 return 1
4293 endif
4294 endif
4295
4296 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4297 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4298 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4299 " med 1 D H
4300 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004301" 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 +00004302 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004303 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004304 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004305
4306 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004307" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4308" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4309 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004310
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004311" 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>"))
4312" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4313" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314 return 0
4315endfun
4316
4317" ---------------------------------------------------------------------
4318" s:NetrwGetcwd: get the current directory. {{{2
4319" Change backslashes to forward slashes, if any.
4320" If doesc is true, escape certain troublesome characters
4321fun! s:NetrwGetcwd(doesc)
4322" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4323 let curdir= substitute(getcwd(),'\\','/','ge')
4324 if curdir !~ '[\/]$'
4325 let curdir= curdir.'/'
4326 endif
4327 if a:doesc
4328 let curdir= fnameescape(curdir)
4329 endif
4330" call Dret("NetrwGetcwd <".curdir.">")
4331 return curdir
4332endfun
4333
4334" ---------------------------------------------------------------------
4335" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4336fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4338" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4339 let keepsol= &l:sol
4340 setl nosol
4341
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 call s:UseBufWinVars()
4343
4344 " insure that w:netrw_liststyle is set up
4345 if !exists("w:netrw_liststyle")
4346 if exists("g:netrw_liststyle")
4347 let w:netrw_liststyle= g:netrw_liststyle
4348 else
4349 let w:netrw_liststyle= s:THINLIST
4350 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004351" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004352 endif
4353
4354 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4355 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004356" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004357 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004358 let dirname= "./"
4359 let curline= getline('.')
4360
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004361 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004362 NetrwKeepj norm! s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004363 let s:netrw_skipbrowse= 1
4364 echo 'Pressing "s" also works'
4365
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004366 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 let s:netrw_skipbrowse= 1
4368 echo 'Press "S" to edit sorting sequence'
4369
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004370 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004371 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004373
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004374 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004375 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376 let s:netrw_skipbrowse= 1
4377 echo 'Pressing "a" also works'
4378
4379 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004380 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004381 endif
4382
4383 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004384" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004385 NetrwKeepj norm! 0
4386 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004387
4388 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004389" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004390 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004391 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4392
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004393 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004394" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004395 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004396 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004397
4398 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004399" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004400 let dirname= getline('.')
4401
4402 if !exists("b:netrw_cpf")
4403 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004404 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 +01004405 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004406" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004407 endif
4408
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004409" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004410 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004411" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4412" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004413 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004414 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004415 else
4416 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004417 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004418 endif
4419 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004420 let eofname= filestart + b:netrw_cpf + 1
4421 if eofname <= col("$")
4422 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004423 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004424 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004425 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004426 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004427 let dirname = @a
4428 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004429" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004431" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004432 endif
4433
4434 " symlinks are indicated by a trailing "@". Remove it before further processing.
4435 let dirname= substitute(dirname,"@$","","")
4436
4437 " executables are indicated by a trailing "*". Remove it before further processing.
4438 let dirname= substitute(dirname,"\*$","","")
4439
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004440 let &l:sol= keepsol
4441
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442" call Dret("s:NetrwGetWord <".dirname.">")
4443 return dirname
4444endfun
4445
4446" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004447" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4448" g:netrw_bufsettings will be used after the listing is produced.
4449" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450fun! s:NetrwListSettings(islocal)
4451" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004452" 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 +00004453 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004454" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4455 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4456 setl bt=nofile nobl ma nonu nowrap noro nornu
4457 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004459 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004460 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004461" call Dredir("ls!","s:NetrwListSettings")
4462" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004463 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004464 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004466 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004467 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004468 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004469 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004470" 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 +00004471" call Dret("s:NetrwListSettings")
4472endfun
4473
4474" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004475" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004476" islocal=0: remote browsing
4477" =1: local browsing
4478fun! s:NetrwListStyle(islocal)
4479" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004480
Bram Moolenaar97d62492012-11-15 21:28:22 +01004481 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004482 let fname = s:NetrwGetWord()
4483 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004484 let svpos = winsaveview()
4485" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004486 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4488" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4489" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004490
Bram Moolenaar85850f32019-07-19 22:05:51 +02004491 " repoint t:netrw_lexbufnr if appropriate
4492 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4493" call Decho("set repointlexbufnr to true!")
4494 let repointlexbufnr= 1
4495 endif
4496
Bram Moolenaar446cb832008-06-24 21:56:24 +00004497 if w:netrw_liststyle == s:THINLIST
4498 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004499" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004500 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4501
4502 elseif w:netrw_liststyle == s:LONGLIST
4503 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004504" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004505 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4506
4507 elseif w:netrw_liststyle == s:WIDELIST
4508 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004509" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4511
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004512 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004513" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004514 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4515
4516 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004517 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004518 let g:netrw_liststyle = s:THINLIST
4519 let w:netrw_liststyle = g:netrw_liststyle
4520 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4521 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004522 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004523" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004524
4525 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004526" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4527 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004528 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004529" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004530 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004531" 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 +00004532
4533 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004534" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004535 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4536 NetrwKeepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004537
Bram Moolenaar85850f32019-07-19 22:05:51 +02004538 " repoint t:netrw_lexbufnr if appropriate
4539 if exists("repointlexbufnr")
4540 let t:netrw_lexbufnr= bufnr("%")
4541" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4542 endif
4543
Bram Moolenaar13600302014-05-22 18:26:40 +02004544 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004545" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4546 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004547 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004548
4549" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4550endfun
4551
4552" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004553" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4554fun! s:NetrwBannerCtrl(islocal)
4555" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4556
Bram Moolenaar97d62492012-11-15 21:28:22 +01004557 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004558 " toggle the banner (enable/suppress)
4559 let g:netrw_banner= !g:netrw_banner
4560
4561 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004562 let svpos= winsaveview()
4563" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004564 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4565
4566 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004567 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4568 let fname= s:NetrwGetWord()
4569 sil NetrwKeepj $
4570 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4571" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4572 if result <= 0 && exists("w:netrw_bannercnt")
4573 exe "NetrwKeepj ".w:netrw_bannercnt
4574 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004575 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004576 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004577" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4578endfun
4579
4580" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004581" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4582"
4583" No bang: enters files/directories into Netrw's bookmark system
4584" No argument and in netrw buffer:
4585" if there are marked files: bookmark marked files
4586" otherwise : bookmark file/directory under cursor
4587" No argument and not in netrw buffer: bookmarks current open file
4588" Has arguments: globs them individually and bookmarks them
4589"
4590" With bang: deletes files/directories from Netrw's bookmark system
4591fun! s:NetrwBookmark(del,...)
4592" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4593 if a:0 == 0
4594 if &ft == "netrw"
4595 let curbufnr = bufnr("%")
4596
4597 if exists("s:netrwmarkfilelist_{curbufnr}")
4598 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004599" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004600 let svpos = winsaveview()
4601" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004602 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004603 for fname in s:netrwmarkfilelist_{curbufnr}
4604 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4605 endfor
4606 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4607 call s:NetrwUnmarkList(curbufnr,curdir)
4608 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004609" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4610 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004611 else
4612 let fname= s:NetrwGetWord()
4613 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4614 endif
4615
4616 else
4617 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004618" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004619 let fname= expand("%")
4620 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4621 endif
4622
4623 else
4624 " bookmark specified files
4625 " attempts to infer if working remote or local
4626 " by deciding if the current file begins with an url
4627 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004628 let islocal= expand("%") !~ '^\a\{3,}://'
4629" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004630 let i = 1
4631 while i <= a:0
4632 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004633 if v:version > 704 || (v:version == 704 && has("patch656"))
4634 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004635 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004636 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004637 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004638 else
4639 let mbfiles= [a:{i}]
4640 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004641" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004642 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004643" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004644 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4645 endfor
4646 let i= i + 1
4647 endwhile
4648 endif
4649
4650 " update the menu
4651 call s:NetrwBookmarkMenu()
4652
4653" call Dret("s:NetrwBookmark")
4654endfun
4655
4656" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004657" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4658" .2.[cnt] for bookmarks, and
4659" .3.[cnt] for history
4660" (see s:NetrwMenu())
4661fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004662 if !exists("s:netrw_menucnt")
4663 return
4664 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004665" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004666
4667 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004668 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004669 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004670" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004671 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4672 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004673 endif
4674 if !exists("s:netrw_initbookhist")
4675 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004676 endif
4677
4678 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004679 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004680 let cnt= 1
4681 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004682" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004683 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004684
4685 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004686 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004687
4688 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004689 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 +01004690 let cnt= cnt + 1
4691 endfor
4692
4693 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004694
4695 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004696 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004697 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004698 let first = 1
4699 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004700 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004701 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004702 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004703 if exists("g:netrw_dirhist_{cnt}")
4704 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004705" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004706 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4707 endif
4708 let first = 0
4709 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4710 if cnt < 0
4711 let cnt= cnt + g:netrw_dirhistmax
4712 endif
4713 endwhile
4714 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004715
Bram Moolenaar9964e462007-05-05 17:54:07 +00004716 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004717" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004718endfun
4719
4720" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004721" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4722" directory and a new directory name. Also, if the
4723" "new directory name" is actually a file,
4724" NetrwBrowseChgDir() edits the file.
4725fun! s:NetrwBrowseChgDir(islocal,newdir,...)
4726" 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 +01004727" 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 +00004728
Bram Moolenaar97d62492012-11-15 21:28:22 +01004729 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004730 if !exists("b:netrw_curdir")
4731 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4732 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004733 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004734" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4735" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004736" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004737" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004738 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004739 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004740" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004741
Bram Moolenaar97d62492012-11-15 21:28:22 +01004742 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004743" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004744 call s:SavePosn(s:netrw_posn)
4745 NetrwKeepj call s:NetrwOptionsSave("s:")
4746 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004747 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004748 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004749 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004750 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004751 endif
4752 let newdir = a:newdir
4753 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004754 let dorestore = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004755" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004756" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004757
4758 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004759" 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 +01004760 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004761" 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 +01004762 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004763 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004764" 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 +01004765 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004766" 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 +02004767 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004768 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004769 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004770 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004771" 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 +01004772 endif
4773 endif
4774" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004775" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004776 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777
Bram Moolenaar446cb832008-06-24 21:56:24 +00004778 " set up o/s-dependent directory recognition pattern
4779 if has("amiga")
4780 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004781 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004782 let dirpat= '[\/]$'
4783 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004784" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004785
4786 if dirname !~ dirpat
4787 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004788 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004789 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004790" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004791 endif
4792
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004793" 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 +01004794 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004795 " ------------------------------
4796 " NetrwBrowseChgDir: edit a file {{{3
4797 " ------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004798" call Decho('(s:NetrwBrowseChgDir) edit-a-file: case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004799
Bram Moolenaar97d62492012-11-15 21:28:22 +01004800 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004801 let s:rexposn_{bufnr("%")}= winsaveview()
4802" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004803" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4804" 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 +01004805
Bram Moolenaar446cb832008-06-24 21:56:24 +00004806 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004807" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4808" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004809 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004810 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4811" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4812 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004813 if dirname =~ '/$'
4814 let dirname= dirname.newdir
4815 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004816 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004818" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4819" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004820 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004821" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004822 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004823 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004824 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004825 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004826" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004827 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004828 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004829" 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 +02004830 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004831 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004832 if !exists("s:didsplit")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004833" 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 +01004834 if type(g:netrw_browse_split) == 3
4835 " open file in server
4836 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004837" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004838 call s:NetrwServerEdit(a:islocal,dirname)
4839" call Dret("s:NetrwBrowseChgDir")
4840 return
4841 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004842 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004843" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004844 keepalt new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004845 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004846 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004847 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004848 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004849 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004850 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004851" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004852 keepalt rightb vert 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 == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004858 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004859" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004860 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004861 if !exists("b:netrw_curdir")
4862 let b:netrw_curdir= getcwd()
4863 endif
4864 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004866 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004867" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004868 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004869 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004871 return
4872 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004873 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004874 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004875 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004876" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004877 call s:NetrwMenu(0)
4878 " optional change to window
4879 if g:netrw_chgwin >= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004880" call Decho("edit-a-file: changing window to #".g:netrw_chgwin,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004881 if winnr("$")+1 == g:netrw_chgwin
4882 " if g:netrw_chgwin is set to one more than the last window, then
4883 " vertically split the last window to make that window available.
4884 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004885 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004886 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004887 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004888 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004889 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004890 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004891 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004892 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004893 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004894
Bram Moolenaar446cb832008-06-24 21:56:24 +00004895 " the point where netrw actually edits the (local) file
4896 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004897 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004898 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004899" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004900 " some like c-^ to return to the last edited file
4901 " others like c-^ to return to the netrw buffer
4902 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004903 exe "NetrwKeepj keepalt e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004904 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004905 exe "NetrwKeepj e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004906 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004907" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004908 call s:NetrwCursor()
Bram Moolenaar13600302014-05-22 18:26:40 +02004909 if &hidden || &bufhidden == "hide"
4910 " file came from vim's hidden storage. Don't "restore" options with it.
4911 let dorestore= 0
4912 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004913 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004914" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004915 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004916 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01004917
4918 " handle g:Netrw_funcref -- call external-to-netrw functions
4919 " This code will handle g:Netrw_funcref as an individual function reference
4920 " or as a list of function references. It will ignore anything that's not
4921 " a function reference. See :help Funcref for information about function references.
4922 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004923" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004924 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004925" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004926 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004927 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004928" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004929 for Fncref in g:Netrw_funcref
4930 if type(FncRef) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004931 NetrwKeepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004932 endif
4933 endfor
4934 endif
4935 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004936 endif
4937
4938 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004939 " ----------------------------------------------------
4940 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4941 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004942" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004943 let dirname = newdir
4944 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004945 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004946 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004947
4948 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004949 " ---------------------------------------------
4950 " NetrwBrowseChgDir: refresh the directory list {{{3
4951 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004952" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004953 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
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: go up one directory {{{3
4959 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004960" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004961
4962 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4963 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004964" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4965" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004966 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004967 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968 endif
4969
4970 if has("amiga")
4971 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004972" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004973 if a:islocal
4974 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4975 let dirname= substitute(dirname,'/$','','')
4976 else
4977 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4978 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004979" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004980
Bram Moolenaar8d043172014-01-23 14:24:41 +01004981 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
4982 " windows
4983 if a:islocal
4984 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4985 if dirname == ""
4986 let dirname= '/'
4987 endif
4988 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004989 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004990 endif
4991 if dirname =~ '^\a:$'
4992 let dirname= dirname.'/'
4993 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004994" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004995
Bram Moolenaar446cb832008-06-24 21:56:24 +00004996 else
4997 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02004998" 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 +00004999 if a:islocal
5000 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5001 if dirname == ""
5002 let dirname= '/'
5003 endif
5004 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005005 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005006 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005007" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005008 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005009 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005010 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005011
5012 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005013 " --------------------------------------
5014 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5015 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005016" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005017 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5018" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005019 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005020 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005021" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5022 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005023 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005024 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005026 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005027 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005028" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005029
5030 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005031" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005032 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005033" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005034 let haskey= 1
5035 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005036" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005037 endif
5038
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005039 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005040" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005041 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005042 if has_key(w:netrw_treedict,treedir."/")
5043 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005044" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005045 let haskey = 1
5046 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005047" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005048 endif
5049 endif
5050
5051 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005052" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005053 if !haskey && treedir =~ '/$'
5054 let treedir= substitute(treedir,'/$','','')
5055 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005056" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005057 let haskey = 1
5058 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005059" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005060 endif
5061 endif
5062
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005063" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005064 if haskey
5065 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005066" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005067 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005068" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5069" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005070 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005071 else
5072 " go down one directory
5073 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005074" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5075" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005076 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005077 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005078" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005079 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080
5081 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005082 " ----------------------------------------
5083 " NetrwBrowseChgDir: Go down one directory {{{3
5084 " ----------------------------------------
5085 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005086" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005087 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005088 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005089 endif
5090
Bram Moolenaar97d62492012-11-15 21:28:22 +01005091 " --------------------------------------
5092 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5093 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005094 if dorestore
5095 " dorestore is zero'd when a local file was hidden or bufhidden;
5096 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005097" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005098 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005099" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005100" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005101 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005102 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005103" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005104 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5106" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005107 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005108" 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 +02005109 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005110" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5111" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005112 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005113" 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 +02005114 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005115 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005116 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005117 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005118
Bram Moolenaar446cb832008-06-24 21:56:24 +00005119" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5120 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005121endfun
5122
5123" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005124" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5125" for thin, long, and wide: cursor placed just after banner
5126" for tree, keeps cursor on current filename
5127fun! s:NetrwBrowseUpDir(islocal)
5128" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005129 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5130 " this test needed because occasionally this function seems to be incorrectly called
5131 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005132 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005133 " directories.
5134" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5135 return
5136 endif
5137
Bram Moolenaara6878372014-03-22 21:02:50 +01005138 norm! 0
5139 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005140" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005141 let curline= getline(".")
5142 let swwline= winline() - 1
5143 if exists("w:netrw_treetop")
5144 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005145 elseif exists("b:netrw_curdir")
5146 let w:netrw_treetop= b:netrw_curdir
5147 else
5148 let w:netrw_treetop= getcwd()
5149 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005150 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005151 let curfile = getline(".")
5152 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005153 if a:islocal
5154 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5155 else
5156 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5157 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005158" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5159" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5160 if w:netrw_treetop == '/'
5161 keepj call search('^\M'.curfile,"w")
5162 elseif curfile == '../'
5163 keepj call search('^\M'.curfile,"wb")
5164 else
5165" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5166 while 1
5167 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5168 let treepath= s:NetrwTreePath(w:netrw_treetop)
5169" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5170 if treepath == curpath
5171 break
5172 endif
5173 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005174 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005175
Bram Moolenaara6878372014-03-22 21:02:50 +01005176 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005177" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005178 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005179 if exists("b:netrw_curdir")
5180 let curdir= b:netrw_curdir
5181 else
5182 let curdir= expand(getcwd())
5183 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005184 if a:islocal
5185 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5186 else
5187 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5188 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005189 call s:RestorePosn(s:netrw_posn)
5190 let curdir= substitute(curdir,'^.*[\/]','','')
5191 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005192 endif
5193" call Dret("s:NetrwBrowseUpDir")
5194endfun
5195
5196" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005197" netrw#BrowseX: (implements "x") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005198" given filename; typically this means given their extension.
5199" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005200fun! netrw#BrowseX(fname,remote)
5201" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.")")
5202
Bram Moolenaar85850f32019-07-19 22:05:51 +02005203 " if its really just a local directory, then do a "gf" instead
5204 if (a:remote == 0 && isdirectory(a:fname)) || (a:remote == 1 && a:fname =~ '/$' && a:fname !~ '^https\=:')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005205 norm! gf
Bram Moolenaar85850f32019-07-19 22:05:51 +02005206" call Dret("(netrw#BrowseX) did gf instead")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005207 endif
5208
Bram Moolenaar97d62492012-11-15 21:28:22 +01005209 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005210 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005211" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005212
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005213 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5214 let awkeep = &aw
5215 set noaw
5216
Bram Moolenaar5c736222010-01-06 20:54:52 +01005217 " special core dump handler
5218 if a:fname =~ '/core\(\.\d\+\)\=$'
5219 if exists("g:Netrw_corehandler")
5220 if type(g:Netrw_corehandler) == 2
5221 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005222" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005223 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005224 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005225 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005226" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005227 for Fncref in g:Netrw_corehandler
5228 if type(FncRef) == 2
5229 call FncRef(a:fname)
5230 endif
5231 endfor
5232 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005233" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005234 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005235 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005236 let &aw= awkeep
5237" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005238 return
5239 endif
5240 endif
5241
Bram Moolenaar446cb832008-06-24 21:56:24 +00005242 " set up the filename
5243 " (lower case the extension, make a local copy of a remote file)
5244 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5245 if has("win32") || has("win95") || has("win64") || has("win16")
5246 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005248 if exten =~ "[\\/]"
5249 let exten= ""
5250 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005251" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005252
Bram Moolenaar446cb832008-06-24 21:56:24 +00005253 if a:remote == 1
5254 " create a local copy
Bram Moolenaar46973992017-12-14 19:56:46 +01005255" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005256 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005257 call netrw#NetRead(3,a:fname)
5258 " attempt to rename tempfile
5259 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005260 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005261" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5262" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005263 if s:netrw_tmpfile != newname && newname != ""
5264 if rename(s:netrw_tmpfile,newname) == 0
5265 " renaming succeeded
5266" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5267 let fname= newname
5268 else
5269 " renaming failed
5270" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5271 let fname= s:netrw_tmpfile
5272 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005273 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005274 let fname= s:netrw_tmpfile
5275 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005276 else
Bram Moolenaar46973992017-12-14 19:56:46 +01005277" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005278 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005279 " special ~ handler for local
5280 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005281" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5282 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005283 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005284 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005285" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5286" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005287
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005288 " set up redirection (avoids browser messages)
5289 " by default, g:netrw_suppress_gx_mesg is true
5290 if g:netrw_suppress_gx_mesg
5291 if &srr =~ "%s"
5292 if (has("win32") || has("win95") || has("win64") || has("win16"))
5293 let redir= substitute(&srr,"%s","nul","")
5294 else
5295 let redir= substitute(&srr,"%s","/dev/null","")
5296 endif
5297 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5298 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005299 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005300 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005301 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005302 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005303" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005304
5305 " extract any viewing options. Assumes that they're set apart by quotes.
Bram Moolenaar46973992017-12-14 19:56:46 +01005306" call Decho("extract any viewing options",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005307 if exists("g:netrw_browsex_viewer")
Bram Moolenaar46973992017-12-14 19:56:46 +01005308" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005309 if g:netrw_browsex_viewer =~ '\s'
5310 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5311 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5312 let oviewer = ''
5313 let cnt = 1
5314 while !executable(viewer) && viewer != oviewer
5315 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5316 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5317 let cnt = cnt + 1
5318 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005319" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005320 endwhile
5321 else
5322 let viewer = g:netrw_browsex_viewer
5323 let viewopt = ""
5324 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005325" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005326 endif
5327
5328 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005329" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005330 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar46973992017-12-14 19:56:46 +01005331" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005332 let ret= netrwFileHandlers#Invoke(exten,fname)
5333
5334 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar46973992017-12-14 19:56:46 +01005335" call Decho("g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005336 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005337 let ret= v:shell_error
5338
5339 elseif has("win32") || has("win64")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005340" call Decho("win".(has("win32")? "32" : "64")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005341 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005342 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005344 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 else
5346 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5347 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005348 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005349 let ret= v:shell_error
5350
Bram Moolenaar97d62492012-11-15 21:28:22 +01005351 elseif has("win32unix")
5352 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar46973992017-12-14 19:56:46 +01005353" call Decho("cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005354 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005355 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005356 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005357 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005358 elseif executable("cygstart")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005359 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005360 else
5361 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5362 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005363 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005364 let ret= v:shell_error
5365
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005366 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
Bram Moolenaar46973992017-12-14 19:56:46 +01005367" call Decho("unix and kfmclient",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005368 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005369 let ret= v:shell_error
5370
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005371 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
Bram Moolenaar46973992017-12-14 19:56:46 +01005372" call Decho("unix, exo-open, xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005373 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir)
5374 let ret= v:shell_error
5375
Bram Moolenaar85850f32019-07-19 22:05:51 +02005376 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
5377" call Decho("unix and atril",'~'.expand("<slnum>"))
5378 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5379 let ret= v:shell_error
5380
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005381 elseif has("unix") && executable("xdg-open")
Bram Moolenaar46973992017-12-14 19:56:46 +01005382" call Decho("unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005383 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005384 let ret= v:shell_error
5385
5386 elseif has("macunix") && executable("open")
Bram Moolenaar46973992017-12-14 19:56:46 +01005387" call Decho("macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005388 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005389 let ret= v:shell_error
5390
5391 else
5392 " netrwFileHandlers#Invoke() always returns 0
5393 let ret= netrwFileHandlers#Invoke(exten,fname)
5394 endif
5395
5396 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5397 if ret
5398 let ret= netrwFileHandlers#Invoke(exten,fname)
5399 endif
5400
Bram Moolenaarc236c162008-07-13 17:41:49 +00005401 " restoring redraw! after external file handlers
5402 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005403
5404 " cleanup: remove temporary file,
5405 " delete current buffer if success with handler,
5406 " return to prior buffer (directory listing)
5407 " Feb 12, 2008: had to de-activiate removal of
5408 " temporary file because it wasn't getting seen.
5409" if a:remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005410"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005411" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005412" endif
5413
5414 if a:remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005415 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005416 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005417 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005418 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005419 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005420" redraw!
5421 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005422" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005423 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005424 let @@ = ykeep
5425 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005426
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005427" call Dret("netrw#BrowseX")
5428endfun
5429
5430" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005431" netrw#GX: gets word under cursor for gx support {{{2
5432" See also: netrw#BrowseXVis
5433" netrw#BrowseX
5434fun! netrw#GX()
5435" call Dfunc("netrw#GX()")
5436 if &ft == "netrw"
5437 let fname= s:NetrwGetWord()
5438 else
5439 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5440 endif
5441" call Dret("netrw#GX <".fname.">")
5442 return fname
5443endfun
5444
5445" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005446" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5447fun! netrw#BrowseXVis()
5448" call Dfunc("netrw#BrowseXVis()")
5449 let atkeep = @@
5450 norm! gvy
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005451" call Decho("@@<".@@.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005452 call netrw#BrowseX(@@,netrw#CheckIfRemote(@@))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005453 let @@ = atkeep
5454" call Dret("netrw#BrowseXVis")
5455endfun
5456
5457" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005458" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5459" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5460" to become an unlisted buffer, so in that case don't bwipe it.
5461fun! s:NetrwBufRename(newname)
5462" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5463" call Dredir("ls!","s:NetrwBufRename (before rename)")
5464 let oldbufname= bufname(bufnr("%"))
5465" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5466
5467 if oldbufname != a:newname
5468" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5469 let b:junk= 1
5470" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5471 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
5472" call Dredir("ls!","s:NetrwBufRename (before bwipe)")
5473 let oldbufnr= bufnr(oldbufname)
5474" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5475" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5476 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5477" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5478 exe "bwipe! ".oldbufnr
5479" else " Decho
5480" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
5481 endif
5482" call Dredir("ls!","s:NetrwBufRename (after rename)")
5483" else " Decho
5484" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5485 endif
5486
5487" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5488endfun
5489
5490" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005491" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005492fun! netrw#CheckIfRemote(...)
5493" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5494 if a:0 > 0
5495 let curfile= a:1
5496 else
5497 let curfile= expand("%")
5498 endif
5499" call Decho("curfile<".curfile.">")
5500 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005501" call Dret("netrw#CheckIfRemote 1")
5502 return 1
5503 else
5504" call Dret("netrw#CheckIfRemote 0")
5505 return 0
5506 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005507endfun
5508
5509" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005510" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5511fun! s:NetrwChgPerm(islocal,curdir)
5512" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005513 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005514 call inputsave()
5515 let newperm= input("Enter new permission: ")
5516 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005517 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5518 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5519" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005520 call system(chgperm)
5521 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005522 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005523 endif
5524 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005525 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005526 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005527 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005528" call Dret("s:NetrwChgPerm")
5529endfun
5530
5531" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005532" s:CheckIfKde: checks if kdeinit is running {{{2
5533" Returns 0: kdeinit not running
5534" 1: kdeinit is running
5535fun! s:CheckIfKde()
5536" call Dfunc("s:CheckIfKde()")
5537 " seems kde systems often have gnome-open due to dependencies, even though
5538 " gnome-open's subsidiary display tools are largely absent. Kde systems
5539 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5540 if !exists("s:haskdeinit")
5541 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005542 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005543 if v:shell_error
5544 let s:haskdeinit = 0
5545 endif
5546 else
5547 let s:haskdeinit= 0
5548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005549" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005550 endif
5551
5552" call Dret("s:CheckIfKde ".s:haskdeinit)
5553 return s:haskdeinit
5554endfun
5555
5556" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005557" s:NetrwClearExplore: clear explore variables (if any) {{{2
5558fun! s:NetrwClearExplore()
5559" call Dfunc("s:NetrwClearExplore()")
5560 2match none
5561 if exists("s:explore_match") |unlet s:explore_match |endif
5562 if exists("s:explore_indx") |unlet s:explore_indx |endif
5563 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5564 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5565 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5566 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5567 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5568 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5569 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5570" redraw!
5571 echo " "
5572 echo " "
5573" call Dret("s:NetrwClearExplore")
5574endfun
5575
5576" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005577" s:NetrwExploreListUniq: {{{2
5578fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005579" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005580
5581 " this assumes that the list is already sorted
5582 let newexplist= []
5583 for member in a:explist
5584 if !exists("uniqmember") || member != uniqmember
5585 let uniqmember = member
5586 let newexplist = newexplist + [ member ]
5587 endif
5588 endfor
5589
Bram Moolenaar15146672011-10-20 22:22:38 +02005590" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005591 return newexplist
5592endfun
5593
5594" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005595" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5596fun! s:NetrwForceChgDir(islocal,newdir)
5597" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005598 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005599 if a:newdir !~ '/$'
5600 " ok, looks like force is needed to get directory-style treatment
5601 if a:newdir =~ '@$'
5602 let newdir= substitute(a:newdir,'@$','/','')
5603 elseif a:newdir =~ '[*=|\\]$'
5604 let newdir= substitute(a:newdir,'.$','/','')
5605 else
5606 let newdir= a:newdir.'/'
5607 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005608" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005609 else
5610 " should already be getting treatment as a directory
5611 let newdir= a:newdir
5612 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005613 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005614 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005615 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005616" call Dret("s:NetrwForceChgDir")
5617endfun
5618
5619" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005620" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005621" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5622" expr : this is the expression to follow the directory. Will use s:ComposePath()
5623" pare =1: remove the current directory from the resulting glob() filelist
5624" =0: leave the current directory in the resulting glob() filelist
5625fun! s:NetrwGlob(direntry,expr,pare)
5626" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005627 if netrw#CheckIfRemote()
5628 keepalt 1sp
5629 keepalt enew
5630 let keep_liststyle = w:netrw_liststyle
5631 let w:netrw_liststyle = s:THINLIST
5632 if s:NetrwRemoteListing() == 0
5633 keepj keepalt %s@/@@
5634 let filelist= getline(1,$)
5635 q!
5636 else
5637 " remote listing error -- leave treedict unchanged
5638 let filelist= w:netrw_treedict[a:direntry]
5639 endif
5640 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005641 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5642 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5643 if a:pare
5644 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5645 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005646 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005647 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5648 if a:pare
5649 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5650 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005651 endif
5652" call Dret("s:NetrwGlob ".string(filelist))
5653 return filelist
5654endfun
5655
5656" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005657" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5658fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005659" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005660 if a:newfile =~ '[/@*=|\\]$'
5661 let newfile= substitute(a:newfile,'.$','','')
5662 else
5663 let newfile= a:newfile
5664 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005665 if a:islocal
5666 call s:NetrwBrowseChgDir(a:islocal,newfile)
5667 else
5668 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5669 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005670" call Dret("s:NetrwForceFile")
5671endfun
5672
5673" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005674" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5675" and switches the hiding mode. The actual hiding is done by
5676" s:NetrwListHide().
5677" g:netrw_hide= 0: show all
5678" 1: show not-hidden files
5679" 2: show hidden files only
5680fun! s:NetrwHide(islocal)
5681" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005682 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005683 let svpos= winsaveview()
5684" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005685
5686 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005687" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5688" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005689
5690 " hide the files in the markfile list
5691 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005692" 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 +00005693 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5694 " remove fname from hiding list
5695 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5696 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5697 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005698" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005699 else
5700 " append fname to hiding list
5701 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5702 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5703 else
5704 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5705 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005706" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005707 endif
5708 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005709 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005710 let g:netrw_hide= 1
5711
5712 else
5713
5714 " switch between show-all/show-not-hidden/show-hidden
5715 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005716 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005717 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005718 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005719 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005720" call Dret("NetrwHide")
5721 return
5722 endif
5723 endif
5724
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005725 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005726" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5727 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005728 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005729" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005730endfun
5731
5732" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005733" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5734fun! s:NetrwHideEdit(islocal)
5735" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5736
5737 let ykeep= @@
5738 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005739 let svpos= winsaveview()
5740" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005741
5742 " get new hiding list from user
5743 call inputsave()
5744 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5745 call inputrestore()
5746 let g:netrw_list_hide= newhide
5747" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5748
5749 " refresh the listing
5750 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5751
5752 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005753" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5754 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005755 let @@= ykeep
5756
5757" call Dret("NetrwHideEdit")
5758endfun
5759
5760" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005761" s:NetrwHidden: invoked by "gh" {{{2
5762fun! s:NetrwHidden(islocal)
5763" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005764 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005765 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005766 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005767" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005768
5769 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005770 " remove .file pattern from hiding list
5771" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005772 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005773 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005774" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005775 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5776 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005777" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005778 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5779 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005780 if g:netrw_list_hide =~ '^,'
5781 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5782 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005783
5784 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005785 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005786" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5787 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005788 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005789" call Dret("s:NetrwHidden")
5790endfun
5791
5792" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005793" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5794fun! s:NetrwHome()
5795 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005796 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005797 else
5798 " go to vim plugin home
5799 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005800 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005801 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005802 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005803 let home= basehome."/.vim"
5804 break
5805 endif
5806 endfor
5807 if home == ""
5808 " just pick the first directory
5809 let home= substitute(&rtp,',.*$','','')
5810 endif
5811 if (has("win32") || has("win95") || has("win64") || has("win16"))
5812 let home= substitute(home,'/','\\','g')
5813 endif
5814 endif
5815 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005816 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005817" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005818 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005819" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005820 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005821 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005822" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005823 call mkdir(home)
5824 endif
5825 endif
5826 let g:netrw_home= home
5827 return home
5828endfun
5829
5830" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005831" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5832fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005833 if exists("s:netrwdrag")
5834 return
5835 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005836 if &ft != "netrw"
5837 return
5838 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005839" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005840
Bram Moolenaar97d62492012-11-15 21:28:22 +01005841 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005842 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005843 while getchar(0) != 0
5844 "clear the input stream
5845 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005846 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005847 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005848 let mouse_lnum = v:mouse_lnum
5849 let wlastline = line('w$')
5850 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005851" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5852" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005853 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5854 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005855 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005856" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5857 return
5858 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005859 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005860 " 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 +01005861 " without this test when its disabled.
5862 " 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 +01005863" 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 +01005864 if v:mouse_col > virtcol('.')
5865 let @@= ykeep
5866" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5867 return
5868 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005869
Bram Moolenaar446cb832008-06-24 21:56:24 +00005870 if a:islocal
5871 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005872 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873 endif
5874 else
5875 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005876 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877 endif
5878 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005879 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005880" call Dret("s:NetrwLeftmouse")
5881endfun
5882
5883" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005884" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5885fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005886 if &ft != "netrw"
5887 return
5888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005889" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5890 call s:NetrwMarkFileTgt(a:islocal)
5891" call Dret("s:NetrwCLeftmouse")
5892endfun
5893
5894" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005895" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5896" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005897" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005898" a:islocal=2 : <c-r> used, remote
5899" a:islocal=3 : <c-r> used, local
5900fun! s:NetrwServerEdit(islocal,fname)
5901" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5902 let islocal = a:islocal%2 " =0: remote =1: local
5903 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005904" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005905
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005906 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005907 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005908 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005909" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005910 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005911 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005912 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5913 unlet s:netrw_browse_split_{winnr()}
5914 endif
5915 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5916" call Dret("s:NetrwServerEdit")
5917 return
5918 endif
5919
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005920" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005921 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005922" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005923
5924 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005925" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005926 let srvrname = g:netrw_browse_split[0]
5927 let tabnum = g:netrw_browse_split[1]
5928 let winnum = g:netrw_browse_split[2]
5929
5930 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005931" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005932
5933 if !ctrlr
5934 " user must have closed the server window and the user did not use <c-r>, but
5935 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005936" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005937 if exists("g:netrw_browse_split")
5938 unlet g:netrw_browse_split
5939 endif
5940 let g:netrw_browse_split= 0
5941 if exists("s:netrw_browse_split_".winnr())
5942 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5943 endif
5944 call s:NetrwBrowseChgDir(islocal,a:fname)
5945" call Dret("s:NetrwServerEdit")
5946 return
5947
5948 elseif has("win32") && executable("start")
5949 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005950" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005951 call system("start gvim --servername ".srvrname)
5952
5953 else
5954 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005955" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005956 call system("gvim --servername ".srvrname)
5957 endif
5958 endif
5959
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005960" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005961 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5962 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005963 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005964
5965 else
5966
5967 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5968
5969 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005970" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005971 if exists("g:netrw_browse_split")
5972 unlet g:netrw_browse_split
5973 endif
5974 let g:netrw_browse_split= 0
5975 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5976" call Dret("s:NetrwServerEdit")
5977 return
5978
5979 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005980" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005981 if has("win32") && executable("start")
5982 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005983" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005984 call system("start gvim --servername ".g:netrw_servername)
5985 else
5986 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005987" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005988 call system("gvim --servername ".g:netrw_servername)
5989 endif
5990 endif
5991 endif
5992
5993 while 1
5994 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005995" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
5996 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005997 break
5998 catch /^Vim\%((\a\+)\)\=:E241/
5999 sleep 200m
6000 endtry
6001 endwhile
6002
6003 if exists("g:netrw_browse_split")
6004 if type(g:netrw_browse_split) != 3
6005 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6006 endif
6007 unlet g:netrw_browse_split
6008 endif
6009 let g:netrw_browse_split= [g:netrw_servername,1,1]
6010 endif
6011
6012 else
6013 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6014 endif
6015
6016" call Dret("s:NetrwServerEdit")
6017endfun
6018
6019" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006020" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6021fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006022 if &ft != "netrw"
6023 return
6024 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006025" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006026
Bram Moolenaar8d043172014-01-23 14:24:41 +01006027 let s:ngw= s:NetrwGetWord()
6028 call s:NetrwMarkFile(a:islocal,s:ngw)
6029
6030" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006031endfun
6032
6033" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006034" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6035" Used to mark multiple files.
6036fun! s:NetrwSLeftdrag(islocal)
6037" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6038 if !exists("s:netrwdrag")
6039 let s:netrwdrag = winnr()
6040 if a:islocal
6041 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006042 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006043 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006044 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006045 endif
6046 let ngw = s:NetrwGetWord()
6047 if !exists("s:ngw") || s:ngw != ngw
6048 call s:NetrwMarkFile(a:islocal,ngw)
6049 endif
6050 let s:ngw= ngw
6051" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6052endfun
6053
6054" ---------------------------------------------------------------------
6055" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6056fun! s:NetrwSLeftrelease(islocal)
6057" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6058 if exists("s:netrwdrag")
6059 nunmap <s-leftrelease>
6060 let ngw = s:NetrwGetWord()
6061 if !exists("s:ngw") || s:ngw != ngw
6062 call s:NetrwMarkFile(a:islocal,ngw)
6063 endif
6064 if exists("s:ngw")
6065 unlet s:ngw
6066 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006067 unlet s:netrwdrag
6068 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006069" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006070endfun
6071
6072" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006073" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
6074" separated patterns given in g:netrw_list_hide
6075fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006076" 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 +02006077" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006078 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02006079" call DechoBuf(bufnr("%"),"COMBAK#3")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006080
6081 " 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 +02006082 " How-it-works: take the hiding command, convert it into a range.
6083 " Duplicate characters don't matter.
6084 " Remove all such characters from the '/~@#...890' string.
6085 " Use the first character left as a separator character.
6086" call Decho("find a character not in the hide string to use as a separator")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006087 let listhide= g:netrw_list_hide
6088 let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006089" call Decho("sep=".sep,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006090
6091 while listhide != ""
6092 if listhide =~ ','
6093 let hide = substitute(listhide,',.*$','','e')
6094 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6095 else
6096 let hide = listhide
6097 let listhide = ""
6098 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006099" call Decho("hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006100
6101 " Prune the list by hiding any files which match
Bram Moolenaar85850f32019-07-19 22:05:51 +02006102" 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 +00006103 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006104" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006105 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006106 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006107" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006108 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006109 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006110" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006111 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006112
Bram Moolenaar446cb832008-06-24 21:56:24 +00006113 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006114 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006115" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006117" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006118 endif
6119
Bram Moolenaaradc21822011-04-01 18:03:16 +02006120 " remove any blank lines that have somehow remained.
6121 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006122 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006123" call DechoBuf(bufnr("%"),"COMBAK#4")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006124
Bram Moolenaar97d62492012-11-15 21:28:22 +01006125 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006126" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006127endfun
6128
6129" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006130" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006131" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006132fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006133" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006134
Bram Moolenaar97d62492012-11-15 21:28:22 +01006135 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006136 " get name of new directory from user. A bare <CR> will skip.
6137 " if its currently a directory, also request will be skipped, but with
6138 " a message.
6139 call inputsave()
6140 let newdirname= input("Please give directory name: ")
6141 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006142" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006143
6144 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006145 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006146" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006147 return
6148 endif
6149
6150 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006151" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006152
6153 " Local mkdir:
6154 " sanity checks
6155 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006156" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6157 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006158 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006159 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006160 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006161 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006162" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006163 return
6164 endif
6165 if s:FileReadable(fullnewdir)
6166 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006167 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006168 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006169 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006170" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006171 return
6172 endif
6173
6174 " requested new local directory is neither a pre-existing file or
6175 " directory, so make it!
6176 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006177 if has("unix")
6178 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6179 else
6180 call mkdir(fullnewdir,"p")
6181 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006182 else
6183 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006184 if s:NetrwLcd(b:netrw_curdir)
6185" call Dret("s:NetrwMakeDir : lcd failure")
6186 return
6187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006188" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006189 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006190 if v:shell_error != 0
6191 let @@= ykeep
6192 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 +01006193" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006194 return
6195 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006196 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006197" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006198 if s:NetrwLcd(netrw_origdir)
6199" call Dret("s:NetrwBrowse : lcd failure")
6200 return
6201 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006202 endif
6203 endif
6204
6205 if v:shell_error == 0
6206 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006207" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006208 let svpos= winsaveview()
6209" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006210 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006211" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6212 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006213 elseif !exists("g:netrw_quiet")
6214 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6215 endif
6216" redraw!
6217
6218 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006219 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006220" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006221 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6222 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006223 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006224 if v:shell_error == 0
6225 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006226 let svpos= winsaveview()
6227" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006228 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006229" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6230 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006231 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006232 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006233 endif
6234" redraw!
6235
6236 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006237 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006238 let svpos= winsaveview()
6239" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006240" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006241 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006242" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006243 let remotepath= b:netrw_fname
6244 else
6245 let remotepath= ""
6246 endif
6247 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006248 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006249" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6250 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006251
Bram Moolenaar446cb832008-06-24 21:56:24 +00006252 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006253 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006254 let svpos= winsaveview()
6255" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006256" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006257 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006258" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006259 let remotepath= b:netrw_fname
6260 else
6261 let remotepath= ""
6262 endif
6263 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006264 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006265" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6266 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267 endif
6268
Bram Moolenaar97d62492012-11-15 21:28:22 +01006269 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006270" call Dret("s:NetrwMakeDir")
6271endfun
6272
6273" ---------------------------------------------------------------------
6274" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6275fun! s:TreeSqueezeDir(islocal)
6276" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6277 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6278 " its a tree-listing style
6279 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006280 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006281 let depth = strchars(substitute(curdepth,' ','','g'))
6282 let srch = -1
6283" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6284" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006285" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006286" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6287 if depth >= 2
6288 NetrwKeepj norm! 0
6289 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6290 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6291" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6292" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6293 elseif depth == 1
6294 NetrwKeepj norm! 0
6295 let treedepthchr= substitute(s:treedepthstring,' ','','')
6296 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6297" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6298 endif
6299 if srch > 0
6300" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6301 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6302 exe srch
6303 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006304 endif
6305" call Dret("s:TreeSqueezeDir")
6306endfun
6307
6308" ---------------------------------------------------------------------
6309" s:NetrwMaps: {{{2
6310fun! s:NetrwMaps(islocal)
6311" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6312
Bram Moolenaar85850f32019-07-19 22:05:51 +02006313 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006314 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006315" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006316 if !hasmapto("<Plug>NetrwReturn")
6317 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006318" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006319 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6320 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006321" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006322 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6323 endif
6324 endif
6325 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006326" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006327 endif
6328
Bram Moolenaar85850f32019-07-19 22:05:51 +02006329 " generate default <Plug> maps {{{3
6330 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
6331 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir |endif
6332 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6333 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6334 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6335 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6336 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6337 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6338 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6339 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6340 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6341 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6342" ---------------------------------------------------------------------
6343" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6344" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6345" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6346" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6347" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6348" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6349" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6350" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6351" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6352" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6353" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6354" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6355" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6356" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6357" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6358" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6359" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6360" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6361" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6362" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6363" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6364" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6365" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6366" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6367" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6368" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6369" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6370" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6371" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6372" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6373" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6374" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6375" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6376" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6377" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6378" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6379" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6380" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6381" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6382" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6383" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6384" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6385" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6386" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6387" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6388" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6389" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6390
Bram Moolenaara6878372014-03-22 21:02:50 +01006391 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006393 " local normal-mode maps {{{3
6394 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6395 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6396 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6397 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6398 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6399 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6400 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6401 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6402 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6403 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6404 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6405" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006406 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6407 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6408 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006409 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006410 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006411 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6412 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6413 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6414 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006415 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6416 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6417 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6418 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6419 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6420 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6421 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6422 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6423 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6424 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6425 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6426 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6427 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006428 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006429 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006430 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6431 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6432 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6433 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6434 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006435 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006436 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006437 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6438 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006439 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6440 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6441 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006442 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006443 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006444 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6445 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006446 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006447 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006448 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6449 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6450 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006451 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6452 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006453
6454 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 +01006455 if !hasmapto('<Plug>NetrwHideEdit')
6456 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006457 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006458 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006459 if !hasmapto('<Plug>NetrwRefresh')
6460 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006461 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006462 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 +01006463 if s:didstarstar || !mapcheck("<s-down>","n")
6464 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006465 endif
6466 if s:didstarstar || !mapcheck("<s-up>","n")
6467 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006468 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006469 if !hasmapto('<Plug>NetrwTreeSqueeze')
6470 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006471 endif
6472 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006473 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6474 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006475 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6476 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6477 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6478 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6479 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6480 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6481 imap <buffer> <leftmouse> <Plug>ILeftmouse
6482 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006483 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006484 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006485 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006486 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006487 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006488 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006489 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6490 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006492 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6493 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6494 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6495 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6496 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6497 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6498 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006499 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6500
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006501 " support user-specified maps
6502 call netrw#UserMaps(1)
6503
Bram Moolenaar85850f32019-07-19 22:05:51 +02006504 else
6505 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006506" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006507 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006508 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6509 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6510 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6511 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6512 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6513 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6514 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6515 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6516 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6517 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6518 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6519" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006520 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6521 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6522 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6523 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6524 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6525 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6526 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6527 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006528 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006529 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006530 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6531 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6532 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6533 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6534 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6535 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6536 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6537 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6538 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6539 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6540 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006541 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006542 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006543 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6544 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6545 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6546 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6547 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006548 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6549 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6550 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6551 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006552 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006553 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6554 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006555 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006556 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 +01006557 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6558 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6559 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6560 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6561 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6562 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6563 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6564 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6565 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006566 if !hasmapto('<Plug>NetrwHideEdit')
6567 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006568 endif
6569 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6570 if !hasmapto('<Plug>NetrwRefresh')
6571 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006572 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006573 if !hasmapto('<Plug>NetrwTreeSqueeze')
6574 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006575 endif
6576 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006577
6578 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006579 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006580
6581 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6582 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006583 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6584 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6585 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6586 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6587 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6588 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6589 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6590 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6591 nmap <middlemouse> <Plug>NetrwMiddlemouse
6592 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6593 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6594 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6595 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006596 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006598 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6599 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006600 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006601 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6602 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6603 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6604 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6605 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6606 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6607 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006608 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006609
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006610 " support user-specified maps
6611 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006612 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006613
6614" call Dret("s:NetrwMaps")
6615endfun
6616
6617" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006618" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006619" If -buffer, the command is only available from within netrw buffers
6620" Otherwise, the command is available from any window, so long as netrw
6621" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006622fun! s:NetrwCommands(islocal)
6623" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6624
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006625 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6626 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006627 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 +01006628 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006629 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006630 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006631 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006632 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006633 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006634
6635" call Dret("s:NetrwCommands")
6636endfun
6637
6638" ---------------------------------------------------------------------
6639" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6640" glob()ing only works with local files
6641fun! s:NetrwMarkFiles(islocal,...)
6642" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006643 let curdir = s:NetrwGetCurdir(a:islocal)
6644 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006645 while i <= a:0
6646 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006647 if v:version > 704 || (v:version == 704 && has("patch656"))
6648 let mffiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006649 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006650 let mffiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006651 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006652 else
6653 let mffiles= [a:{i}]
6654 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006655" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006656 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006657" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006658 call s:NetrwMarkFile(a:islocal,mffile)
6659 endfor
6660 let i= i + 1
6661 endwhile
6662" call Dret("s:NetrwMarkFiles")
6663endfun
6664
6665" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006666" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006667fun! s:NetrwMarkTarget(...)
6668" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6669 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006670 let curdir = s:NetrwGetCurdir(1)
6671 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006672 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006673 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6674 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006675 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006676" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006677 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006678 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6679 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006680 let svpos = winsaveview()
6681" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006682 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006683" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6684 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006685" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006686endfun
6687
6688" ---------------------------------------------------------------------
6689" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6690" mark and unmark files. If a markfile list exists,
6691" then the rename and delete functions will use it instead
6692" of whatever may happen to be under the cursor at that
6693" moment. When the mouse and gui are available,
6694" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006695"
6696" Creates two lists
6697" s:netrwmarkfilelist -- holds complete paths to all marked files
6698" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6699"
6700" Creates a marked file match string
6701" s:netrwmarfilemtch_# -- used with 2match to display marked files
6702"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006703" Creates a buffer version of islocal
6704" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006705fun! s:NetrwMarkFile(islocal,fname)
6706" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006707" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006708
6709 " sanity check
6710 if empty(a:fname)
6711" call Dret("s:NetrwMarkFile : emtpy fname")
6712 return
6713 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006714 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006715
Bram Moolenaar97d62492012-11-15 21:28:22 +01006716 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006717 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006718 if a:fname =~ '^\a'
6719 let leader= '\<'
6720 else
6721 let leader= ''
6722 endif
6723 if a:fname =~ '\a$'
6724 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6725 else
6726 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6727 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006728
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006729 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006730 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006731" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6732" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6733" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006734 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006735
6736 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006737 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006738" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006739 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006740 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006741
6742 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006743 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006744" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006745 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6746 if s:netrwmarkfilelist_{curbufnr} == []
6747 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006748" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006749 call s:NetrwUnmarkList(curbufnr,curdir)
6750 else
6751 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006752" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006753 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006754 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006755 for fname in s:netrwmarkfilelist_{curbufnr}
6756 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006757 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006758 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006759 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006760 endif
6761 let first= 0
6762 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006763" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006764 endif
6765 endif
6766
6767 else
6768 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006769" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006770
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006772 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006773 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6774" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006775
6776 " build initial markfile matching pattern
6777 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006778 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006779 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006780 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006781 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006783 endif
6784
6785 " handle global markfilelist
6786 if exists("s:netrwmarkfilelist")
6787 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6788 if index(s:netrwmarkfilelist,dname) == -1
6789 " append new filename to global markfilelist
6790 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006791" call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006792 else
6793 " remove new filename from global markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006794" call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006795 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006796" call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006797 if s:netrwmarkfilelist == []
6798 unlet s:netrwmarkfilelist
6799 endif
6800 endif
6801 else
6802 " initialize new global-directory markfilelist
6803 let s:netrwmarkfilelist= []
6804 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006805" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006806 endif
6807
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006808 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006809 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6810 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6811" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6812 if exists("g:did_drchip_netrwlist_syntax")
6813 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6814 endif
6815 else
6816" " call Decho("2match none",'~'.expand("<slnum>"))
6817 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006818 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006819 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006820 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02006821" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006822endfun
6823
6824" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006825" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6826" mA: move the argument list to marked file list (tomflist=1)
6827" Uses the global marked file list
6828fun! s:NetrwMarkFileArgList(islocal,tomflist)
6829" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6830
6831 let svpos = winsaveview()
6832" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6833 let curdir = s:NetrwGetCurdir(a:islocal)
6834 let curbufnr = bufnr("%")
6835
6836 if a:tomflist
6837 " mA: move argument list to marked file list
6838 while argc()
6839 let fname= argv(0)
6840" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6841 exe "argdel ".fnameescape(fname)
6842 call s:NetrwMarkFile(a:islocal,fname)
6843 endwhile
6844
6845 else
6846 " ma: move marked file list to argument list
6847 if exists("s:netrwmarkfilelist")
6848
6849 " for every filename in the marked list
6850 for fname in s:netrwmarkfilelist
6851" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6852 exe "argadd ".fnameescape(fname)
6853 endfor " for every file in the marked list
6854
6855 " unmark list and refresh
6856 call s:NetrwUnmarkList(curbufnr,curdir)
6857 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6858" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6859 NetrwKeepj call winrestview(svpos)
6860 endif
6861 endif
6862
6863" call Dret("s:NetrwMarkFileArgList")
6864endfun
6865
6866" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006867" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6868" compress/decompress files using the programs
6869" in g:netrw_compress and g:netrw_uncompress,
6870" using g:netrw_compress_suffix to know which to
6871" do. By default:
6872" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006873" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006874fun! s:NetrwMarkFileCompress(islocal)
6875" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006876 let svpos = winsaveview()
6877" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006878 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006879 let curbufnr = bufnr("%")
6880
Bram Moolenaarff034192013-04-24 18:51:19 +02006881 " sanity check
6882 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006883 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006884" call Dret("s:NetrwMarkFileCompress")
6885 return
6886 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006887" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006888
Bram Moolenaar446cb832008-06-24 21:56:24 +00006889 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006890
6891 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006892 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006893 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006894" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006895 if exists("g:netrw_decompress['".sfx."']")
6896 " fname has a suffix indicating that its compressed; apply associated decompression routine
6897 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006898" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006899 let exe= netrw#WinPath(exe)
6900 if a:islocal
6901 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006902 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006903 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006904 call system(exe." ".fname)
6905 if v:shell_error
6906 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006907 endif
6908 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006909 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6910 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006911 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006912
Bram Moolenaarff034192013-04-24 18:51:19 +02006913 endif
6914 unlet sfx
6915
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 if exists("exe")
6917 unlet exe
6918 elseif a:islocal
6919 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006921 if v:shell_error
6922 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6923 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 else
6925 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006926 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006927 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006928 endfor " for every file in the marked list
6929
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006931 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006932" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6933 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006934 endif
6935" call Dret("s:NetrwMarkFileCompress")
6936endfun
6937
6938" ---------------------------------------------------------------------
6939" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6940" If no marked files, then set up directory as the
6941" target. Currently does not support copying entire
6942" directories. Uses the local-buffer marked file list.
6943" Returns 1=success (used by NetrwMarkFileMove())
6944" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006945fun! s:NetrwMarkFileCopy(islocal,...)
6946" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6947
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006948 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006949 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006950 if b:netrw_curdir !~ '/$'
6951 if !exists("b:netrw_curdir")
6952 let b:netrw_curdir= curdir
6953 endif
6954 let b:netrw_curdir= b:netrw_curdir."/"
6955 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006956
Bram Moolenaarff034192013-04-24 18:51:19 +02006957 " sanity check
6958 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006959 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006960" call Dret("s:NetrwMarkFileCopy")
6961 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006962 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006963" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006964
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006966 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967" call Dret("s:NetrwMarkFileCopy 0")
6968 return 0
6969 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006970" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006972 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006973 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006974" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006975 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006976 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6977" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6978 return
6979 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006980
6981 " copy marked files while within the same directory (ie. allow renaming)
6982 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
6983 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6984 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006985" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006986 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006987 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6988 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006989" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006990 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006991 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006992 let oldname = a:1
6993 else
6994 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006995" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006996 let s:recursive= 1
6997 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6998 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6999 if ret == 0
7000 break
7001 endif
7002 endfor
7003 unlet s:recursive
7004 call s:NetrwUnmarkList(curbufnr,curdir)
7005" call Dret("s:NetrwMarkFileCopy ".ret)
7006 return ret
7007 endif
7008
7009 call inputsave()
7010 let newname= input("Copy ".oldname." to : ",oldname,"file")
7011 call inputrestore()
7012 if newname == ""
7013" call Dret("s:NetrwMarkFileCopy 0")
7014 return 0
7015 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007016 let args= s:ShellEscape(oldname)
7017 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007018 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007019 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7020 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007021 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007022 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7023 let args= substitute(args,'/','\\','g')
7024 let tgt = substitute(tgt, '/','\\','g')
7025 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007026 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7027 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7028 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7029 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7030" call Decho("args <".args.">",'~'.expand("<slnum>"))
7031" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007032 if isdirectory(s:NetrwFile(args))
7033" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007034 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007035" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007036 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7037 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7038 " contents to a target. One must append the source directory name to the target to get xcopy to
7039 " do the right thing.
7040 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007041" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007042 endif
7043 else
7044 let copycmd= g:netrw_localcopycmd
7045 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007046 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007047 let copycmd = substitute(copycmd,'\s.*$','','')
7048 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007049 let copycmd = netrw#WinPath(copycmd).copycmdargs
7050 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007051 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007052 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007053" call Decho("args <".args.">",'~'.expand("<slnum>"))
7054" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7055" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7056" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007057 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007058 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007059 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007060 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 +01007061 else
7062 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7063 endif
7064" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007065 return 0
7066 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067
7068 elseif a:islocal && !s:netrwmftgt_islocal
7069 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007070" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007071 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007072
7073 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007074 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007075" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007076 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077
7078 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007079 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007080" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007081 let curdir = getcwd()
7082 let tmpdir = s:GetTempfile("")
7083 if tmpdir !~ '/'
7084 let tmpdir= curdir."/".tmpdir
7085 endif
7086 if exists("*mkdir")
7087 call mkdir(tmpdir)
7088 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007089 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007090 if v:shell_error != 0
7091 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 +01007092" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007093 return
7094 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007095 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007096 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007097 if s:NetrwLcd(tmpdir)
7098" call Dret("s:NetrwMarkFileCopy : lcd failure")
7099 return
7100 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007101 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007102 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007103 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007104 if getcwd() == tmpdir
7105 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007106 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007107 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007108 if s:NetrwLcd(curdir)
7109" call Dret("s:NetrwMarkFileCopy : lcd failure")
7110 return
7111 endif
7112 if v:version < 704 || (v:version == 704 && !has("patch1107"))
7113 call s:NetrwExe("sil !".g:netrw_localrmdir.g:netrw_localrmdiropt." ".s:ShellEscape(tmpdir,1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007114 if v:shell_error != 0
7115 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80)
7116" " call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".s:ShellEscape(tmpdir,1) )
7117 return
7118 endif
7119 else
7120 if delete(tmpdir,"d")
7121 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
7122 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007123 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007124 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007125 if s:NetrwLcd(curdir)
7126" call Dret("s:NetrwMarkFileCopy : lcd failure")
7127 return
7128 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007129 endif
7130 endif
7131 endif
7132
7133 " -------
7134 " cleanup
7135 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007136" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007137 " remove markings from local buffer
7138 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007139" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7140" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7141" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7142" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7143" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7144" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7145 if exists("s:recursive")
7146" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7147 else
7148" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007149 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007150 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007151 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007152 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007153 else
7154 " refresh local and targets for fast browsing
7155 if !exists("s:recursive")
7156 " remove markings from local buffer
7157" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7158 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7159 endif
7160
7161 " refresh buffers
7162 if s:netrwmftgt_islocal
7163" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7164 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7165 endif
7166 if a:islocal && s:netrwmftgt != curdir
7167" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7168 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7169 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007171
Bram Moolenaar446cb832008-06-24 21:56:24 +00007172" call Dret("s:NetrwMarkFileCopy 1")
7173 return 1
7174endfun
7175
7176" ---------------------------------------------------------------------
7177" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7178" invoke vim's diff mode on the marked files.
7179" Either two or three files can be so handled.
7180" Uses the global marked file list.
7181fun! s:NetrwMarkFileDiff(islocal)
7182" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7183 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007184
Bram Moolenaarff034192013-04-24 18:51:19 +02007185 " sanity check
7186 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007187 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007188" call Dret("s:NetrwMarkFileDiff")
7189 return
7190 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007191 let curdir= s:NetrwGetCurdir(a:islocal)
7192" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007193
Bram Moolenaara6878372014-03-22 21:02:50 +01007194 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007195 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007196 for fname in s:netrwmarkfilelist
7197 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007198 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007199" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007200 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007201 diffthis
7202 elseif cnt == 2 || cnt == 3
7203 vsplit
7204 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007205" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007207 diffthis
7208 else
7209 break
7210 endif
7211 endfor
7212 call s:NetrwUnmarkList(curbufnr,curdir)
7213 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007214
Bram Moolenaar446cb832008-06-24 21:56:24 +00007215" call Dret("s:NetrwMarkFileDiff")
7216endfun
7217
7218" ---------------------------------------------------------------------
7219" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7220" Uses global markfilelist
7221fun! s:NetrwMarkFileEdit(islocal)
7222" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7223
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007224 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007225 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007226
7227 " sanity check
7228 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007229 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007230" call Dret("s:NetrwMarkFileEdit")
7231 return
7232 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007233" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007234
Bram Moolenaar446cb832008-06-24 21:56:24 +00007235 if exists("s:netrwmarkfilelist_{curbufnr}")
7236 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007237 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007238 " unmark markedfile list
7239" call s:NetrwUnmarkList(curbufnr,curdir)
7240 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007241" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007242 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007243 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007244 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007245
Bram Moolenaar446cb832008-06-24 21:56:24 +00007246" call Dret("s:NetrwMarkFileEdit")
7247endfun
7248
7249" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007250" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007251fun! s:NetrwMarkFileQFEL(islocal,qfel)
7252" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7253 call s:NetrwUnmarkAll()
7254 let curbufnr= bufnr("%")
7255
7256 if !empty(a:qfel)
7257 for entry in a:qfel
7258 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007259" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007260 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007261" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007262 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7263 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7264 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7265 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007266" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007267 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7268 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007269" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007270 endif
7271 endfor
7272 echo "(use me to edit marked files)"
7273 else
7274 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7275 endif
7276
7277" call Dret("s:NetrwMarkFileQFEL")
7278endfun
7279
7280" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007281" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7282" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7283" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7284fun! s:NetrwMarkFileExe(islocal,enbloc)
7285" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007286 let svpos = winsaveview()
7287" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007288 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007289 let curbufnr = bufnr("%")
7290
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007291 if a:enbloc == 0
7292 " individually apply command to files, one at a time
7293 " sanity check
7294 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7295 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7296" call Dret("s:NetrwMarkFileExe")
7297 return
7298 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007299" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007300
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007301 if exists("s:netrwmarkfilelist_{curbufnr}")
7302 " get the command
7303 call inputsave()
7304 let cmd= input("Enter command: ","","file")
7305 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007306" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007307 if cmd == ""
7308" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7309 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007310 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007311
7312 " apply command to marked files, individually. Substitute: filename -> %
7313 " If no %, then append a space and the filename to the command
7314 for fname in s:netrwmarkfilelist_{curbufnr}
7315 if a:islocal
7316 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007317 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007318 endif
7319 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007320 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007321 endif
7322 if cmd =~ '%'
7323 let xcmd= substitute(cmd,'%',fname,'g')
7324 else
7325 let xcmd= cmd.' '.fname
7326 endif
7327 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007328" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007329 let ret= system(xcmd)
7330 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007331" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007332 let ret= s:RemoteSystem(xcmd)
7333 endif
7334 if v:shell_error < 0
7335 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7336 break
7337 else
7338 echo ret
7339 endif
7340 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007341
7342 " unmark marked file list
7343 call s:NetrwUnmarkList(curbufnr,curdir)
7344
7345 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007346 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007347" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7348 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007349 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007350 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007351 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007352
7353 else " apply command to global list of files, en bloc
7354
7355 call inputsave()
7356 let cmd= input("Enter command: ","","file")
7357 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007358" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007359 if cmd == ""
7360" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7361 return
7362 endif
7363 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007365 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007366 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007367 endif
7368 if a:islocal
7369 call system(cmd)
7370 if v:shell_error < 0
7371 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7372 endif
7373 else
7374 let ret= s:RemoteSystem(cmd)
7375 endif
7376 call s:NetrwUnmarkAll()
7377
7378 " refresh the listing
7379 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007380" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7381 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007382
7383 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007384
Bram Moolenaar446cb832008-06-24 21:56:24 +00007385" call Dret("s:NetrwMarkFileExe")
7386endfun
7387
7388" ---------------------------------------------------------------------
7389" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7390" as the marked file(s) (toggles suffix presence)
7391" Uses the local marked file list.
7392fun! s:NetrwMarkHideSfx(islocal)
7393" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007394 let svpos = winsaveview()
7395" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007396 let curbufnr = bufnr("%")
7397
7398 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7399 if exists("s:netrwmarkfilelist_{curbufnr}")
7400
7401 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007402" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 " construct suffix pattern
7404 if fname =~ '\.'
7405 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7406 else
7407 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7408 endif
7409 " determine if its in the hiding list or not
7410 let inhidelist= 0
7411 if g:netrw_list_hide != ""
7412 let itemnum = 0
7413 let hidelist= split(g:netrw_list_hide,',')
7414 for hidepat in hidelist
7415 if sfxpat == hidepat
7416 let inhidelist= 1
7417 break
7418 endif
7419 let itemnum= itemnum + 1
7420 endfor
7421 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007422" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007423 if inhidelist
7424 " remove sfxpat from list
7425 call remove(hidelist,itemnum)
7426 let g:netrw_list_hide= join(hidelist,",")
7427 elseif g:netrw_list_hide != ""
7428 " append sfxpat to non-empty list
7429 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7430 else
7431 " set hiding list to sfxpat
7432 let g:netrw_list_hide= sfxpat
7433 endif
7434 endfor
7435
7436 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007437 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007438" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7439 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007440 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007441 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007442 endif
7443
7444" call Dret("s:NetrwMarkHideSfx")
7445endfun
7446
7447" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007448" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007449" Uses the local marked-file list.
7450fun! s:NetrwMarkFileVimCmd(islocal)
7451" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007452 let svpos = winsaveview()
7453" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007454 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007455 let curbufnr = bufnr("%")
7456
Bram Moolenaarff034192013-04-24 18:51:19 +02007457 " sanity check
7458 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007459 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007460" call Dret("s:NetrwMarkFileVimCmd")
7461 return
7462 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007463" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007464
Bram Moolenaar15146672011-10-20 22:22:38 +02007465 if exists("s:netrwmarkfilelist_{curbufnr}")
7466 " get the command
7467 call inputsave()
7468 let cmd= input("Enter vim command: ","","file")
7469 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007470" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007471 if cmd == ""
7472" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7473 return
7474 endif
7475
7476 " apply command to marked files. Substitute: filename -> %
7477 " If no %, then append a space and the filename to the command
7478 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007479" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007480 if a:islocal
7481 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007483" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007484 exe cmd
7485 exe "sil! keepalt wq!"
7486 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007487" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007488 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007489 endif
7490 endfor
7491
7492 " unmark marked file list
7493 call s:NetrwUnmarkList(curbufnr,curdir)
7494
7495 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007496 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007497" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7498 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007499 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007500 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007501 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007502
Bram Moolenaar15146672011-10-20 22:22:38 +02007503" call Dret("s:NetrwMarkFileVimCmd")
7504endfun
7505
7506" ---------------------------------------------------------------------
7507" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7508" as the marked file(s) (toggles suffix presence)
7509" Uses the local marked file list.
7510fun! s:NetrwMarkHideSfx(islocal)
7511" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007512 let svpos = winsaveview()
7513" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007514 let curbufnr = bufnr("%")
7515
7516 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7517 if exists("s:netrwmarkfilelist_{curbufnr}")
7518
7519 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007520" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007521 " construct suffix pattern
7522 if fname =~ '\.'
7523 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7524 else
7525 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7526 endif
7527 " determine if its in the hiding list or not
7528 let inhidelist= 0
7529 if g:netrw_list_hide != ""
7530 let itemnum = 0
7531 let hidelist= split(g:netrw_list_hide,',')
7532 for hidepat in hidelist
7533 if sfxpat == hidepat
7534 let inhidelist= 1
7535 break
7536 endif
7537 let itemnum= itemnum + 1
7538 endfor
7539 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007540" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007541 if inhidelist
7542 " remove sfxpat from list
7543 call remove(hidelist,itemnum)
7544 let g:netrw_list_hide= join(hidelist,",")
7545 elseif g:netrw_list_hide != ""
7546 " append sfxpat to non-empty list
7547 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7548 else
7549 " set hiding list to sfxpat
7550 let g:netrw_list_hide= sfxpat
7551 endif
7552 endfor
7553
7554 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007555 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007556" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7557 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007558 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007559 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007560 endif
7561
7562" call Dret("s:NetrwMarkHideSfx")
7563endfun
7564
7565" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007566" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7567" Uses the global markfilelist
7568fun! s:NetrwMarkFileGrep(islocal)
7569" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007570 let svpos = winsaveview()
7571" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007572 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007573 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007574
7575 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007576" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007577 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007578 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007579 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007580" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007581 let netrwmarkfilelist= "*"
7582 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007583
Bram Moolenaarff034192013-04-24 18:51:19 +02007584 " ask user for pattern
7585 call inputsave()
7586 let pat= input("Enter pattern: ","")
7587 call inputrestore()
7588 let patbang = ""
7589 if pat =~ '^!'
7590 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007591 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007592 endif
7593 if pat =~ '^\i'
7594 let pat = escape(pat,'/')
7595 let pat = '/'.pat.'/'
7596 else
7597 let nonisi = pat[0]
7598 endif
7599
7600 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007601" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007602 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007603 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007604 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007605 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007606" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7607 return
7608 endtry
7609 echo "(use :cn, :cp to navigate, :Rex to return)"
7610
7611 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007612" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7613 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007614
7615 if exists("nonisi")
7616 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007617" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007618 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007619 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007620 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007621 endif
7622
7623" call Dret("s:NetrwMarkFileGrep")
7624endfun
7625
7626" ---------------------------------------------------------------------
7627" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7628" uses the global marked file list
7629" s:netrwmfloc= 0: target directory is remote
7630" = 1: target directory is local
7631fun! s:NetrwMarkFileMove(islocal)
7632" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007633 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007634 let curbufnr = bufnr("%")
7635
7636 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007637 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007638 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007639" call Dret("s:NetrwMarkFileMove")
7640 return
7641 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007642" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007643
Bram Moolenaar446cb832008-06-24 21:56:24 +00007644 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007645 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007646" call Dret("s:NetrwMarkFileCopy 0")
7647 return 0
7648 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007649" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007650
7651 if a:islocal && s:netrwmftgt_islocal
7652 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007653" call Decho("move from local to local",'~'.expand("<slnum>"))
7654" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007655 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007656 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7657" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7658 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007659 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007660 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007661" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007662 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007663 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007664" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007665 if g:netrw_localmovecmd =~ '\s'
7666 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7667 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7668 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007669" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007670 else
7671 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007672" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007673 endif
7674 else
7675 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007676" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007677 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007678 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007679 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7680 let fname= substitute(fname,'/','\\','g')
7681 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007682" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007683 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007684 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007685 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007686 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 +01007687 else
7688 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7689 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007690 break
7691 endif
7692 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007693
7694 elseif a:islocal && !s:netrwmftgt_islocal
7695 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007696" call Decho("move from local to remote",'~'.expand("<slnum>"))
7697" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007698 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007699 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007700" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007701 for fname in mflist
7702 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7703 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7704 endfor
7705 unlet mflist
7706
7707 elseif !a:islocal && s:netrwmftgt_islocal
7708 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007709" call Decho("move from remote to local",'~'.expand("<slnum>"))
7710" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007711 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007712 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007713" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007714 for fname in mflist
7715 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7716 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7717 endfor
7718 unlet mflist
7719
7720 elseif !a:islocal && !s:netrwmftgt_islocal
7721 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007722" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7723" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007724 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007725 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007726" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007727 for fname in mflist
7728 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7729 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7730 endfor
7731 unlet mflist
7732 endif
7733
7734 " -------
7735 " cleanup
7736 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007737" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007738
7739 " remove markings from local buffer
7740 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7741
7742 " refresh buffers
7743 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007744" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007745 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007746 endif
7747 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007748" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007749 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007750 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007751 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007752" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007753 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007754 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007755
Bram Moolenaar446cb832008-06-24 21:56:24 +00007756" call Dret("s:NetrwMarkFileMove")
7757endfun
7758
7759" ---------------------------------------------------------------------
7760" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7761" using the hardcopy command. Local marked-file list only.
7762fun! s:NetrwMarkFilePrint(islocal)
7763" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7764 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007765
7766 " sanity check
7767 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007768 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007769" call Dret("s:NetrwMarkFilePrint")
7770 return
7771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007772" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7773 let curdir= s:NetrwGetCurdir(a:islocal)
7774
Bram Moolenaar446cb832008-06-24 21:56:24 +00007775 if exists("s:netrwmarkfilelist_{curbufnr}")
7776 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007777 call s:NetrwUnmarkList(curbufnr,curdir)
7778 for fname in netrwmarkfilelist
7779 if a:islocal
7780 if g:netrw_keepdir
7781 let fname= s:ComposePath(curdir,fname)
7782 endif
7783 else
7784 let fname= curdir.fname
7785 endif
7786 1split
7787 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007788" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007789 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007790" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007791 hardcopy
7792 q
7793 endfor
7794 2match none
7795 endif
7796" call Dret("s:NetrwMarkFilePrint")
7797endfun
7798
7799" ---------------------------------------------------------------------
7800" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7801" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007802" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007803fun! s:NetrwMarkFileRegexp(islocal)
7804" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7805
7806 " get the regular expression
7807 call inputsave()
7808 let regexp= input("Enter regexp: ","","file")
7809 call inputrestore()
7810
7811 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007812 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007813" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007814 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007815" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007816 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007817 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007818 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007819 else
7820 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007821 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007822 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007823" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007824
7825 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007826 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 if fname =~ '^'.fnameescape(curdir)
7828" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7829 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7830 else
7831" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7832 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7833 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007834 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007835
7836 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007837" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007838
7839 " convert displayed listing into a filelist
7840 let eikeep = &ei
7841 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007842 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007843 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007844" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007845 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007846 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007847 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007848 sil NetrwKeepj norm! "ap
7849 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007850 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007851 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007852 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007853 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007854 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007855 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007856 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007857 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007858 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007859 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007860 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7861 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007862 call histdel("/",-1)
7863 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007864 endif
7865 " convert regexp into the more usual glob-style format
7866 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007867" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007868 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007869 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007870 let filelist= getline(1,line("$"))
7871 q!
7872 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007873 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007874 endfor
7875 unlet filelist
7876 let @a = areg
7877 let &ei = eikeep
7878 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007879 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880
7881" call Dret("s:NetrwMarkFileRegexp")
7882endfun
7883
7884" ---------------------------------------------------------------------
7885" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7886" Uses the local marked file list.
7887fun! s:NetrwMarkFileSource(islocal)
7888" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7889 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007890
7891 " sanity check
7892 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007893 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007894" call Dret("s:NetrwMarkFileSource")
7895 return
7896 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7898 let curdir= s:NetrwGetCurdir(a:islocal)
7899
Bram Moolenaar446cb832008-06-24 21:56:24 +00007900 if exists("s:netrwmarkfilelist_{curbufnr}")
7901 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007902 call s:NetrwUnmarkList(curbufnr,curdir)
7903 for fname in netrwmarkfilelist
7904 if a:islocal
7905 if g:netrw_keepdir
7906 let fname= s:ComposePath(curdir,fname)
7907 endif
7908 else
7909 let fname= curdir.fname
7910 endif
7911 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007912" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007913 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007914 endfor
7915 2match none
7916 endif
7917" call Dret("s:NetrwMarkFileSource")
7918endfun
7919
7920" ---------------------------------------------------------------------
7921" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7922" Uses the global markfilelist
7923fun! s:NetrwMarkFileTag(islocal)
7924" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007925 let svpos = winsaveview()
7926" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007927 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007928 let curbufnr = bufnr("%")
7929
Bram Moolenaarff034192013-04-24 18:51:19 +02007930 " sanity check
7931 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007932 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007933" call Dret("s:NetrwMarkFileTag")
7934 return
7935 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007936" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007937
Bram Moolenaar446cb832008-06-24 21:56:24 +00007938 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007939" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
7940 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007941 call s:NetrwUnmarkAll()
7942
7943 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007944
7945" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
7946 call system(g:netrw_ctags." ".netrwmarkfilelist)
7947 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7949 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007950
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007952 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007953 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007954 let curdir= b:netrw_curdir
7955 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007956 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007957 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007958" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007959 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007960 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007961 wq!
7962 endif
7963 2match none
7964 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007965" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7966 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007967 endif
7968
7969" call Dret("s:NetrwMarkFileTag")
7970endfun
7971
7972" ---------------------------------------------------------------------
7973" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007974" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007975" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007976" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007977" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007978fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007979" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
7980 let svpos = winsaveview()
7981" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007982 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007983 let hadtgt = exists("s:netrwmftgt")
7984 if !exists("w:netrw_bannercnt")
7985 let w:netrw_bannercnt= b:netrw_bannercnt
7986 endif
7987
7988 " set up target
7989 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007990" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007991 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7992 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007993" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007994 unlet s:netrwmftgt s:netrwmftgt_islocal
7995 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007996 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007997 endif
7998 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007999" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8000 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008001" call Dret("s:NetrwMarkFileTgt : removed target")
8002 return
8003 else
8004 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008005" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008007
8008 else
8009 " get word under cursor.
8010 " * If directory, use it for the target.
8011 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008012" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013 let curword= s:NetrwGetWord()
8014 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008015 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008017" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008018 elseif !a:islocal && tgtdir =~ '/$'
8019 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008020" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 else
8022 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008023" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024 endif
8025 endif
8026 if a:islocal
8027 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8028 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008029" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008030 endif
8031 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008032 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008033 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8034 endif
8035 let s:netrwmftgt_islocal= a:islocal
8036
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008037 " need to do refresh so that the banner will be updated
8038 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008039 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008040" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008041 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008042 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008043" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008044 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008045 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8046 else
8047 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8048 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008049" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8050 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008053 endif
8054
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008055" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8056" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008057" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8058endfun
8059
8060" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008061" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8062fun! s:NetrwGetCurdir(islocal)
8063" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8064
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008065 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008066 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8067" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8068 elseif !exists("b:netrw_curdir")
8069 let b:netrw_curdir= getcwd()
8070" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8071 endif
8072
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008073" 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 +01008074 if b:netrw_curdir !~ '\<\a\{3,}://'
8075 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008076" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008077 if g:netrw_keepdir == 0
8078 call s:NetrwLcd(curdir)
8079 endif
8080 endif
8081
8082" call Dret("s:NetrwGetCurdir <".curdir.">")
8083 return b:netrw_curdir
8084endfun
8085
8086" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008087" s:NetrwOpenFile: query user for a filename and open it {{{2
8088fun! s:NetrwOpenFile(islocal)
8089" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008090 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008091 call inputsave()
8092 let fname= input("Enter filename: ")
8093 call inputrestore()
8094 if fname !~ '[/\\]'
8095 if exists("b:netrw_curdir")
8096 if exists("g:netrw_quiet")
8097 let netrw_quiet_keep = g:netrw_quiet
8098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008099 let g:netrw_quiet = 1
8100 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008101 let s:rexposn_{bufnr("%")}= winsaveview()
8102" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008103 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008104 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008105 else
8106 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8107 endif
8108 if exists("netrw_quiet_keep")
8109 let g:netrw_quiet= netrw_quiet_keep
8110 else
8111 unlet g:netrw_quiet
8112 endif
8113 endif
8114 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008115 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008116 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008117 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008118" call Dret("s:NetrwOpenFile")
8119endfun
8120
8121" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008122" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8123" For the mapping to this function be made via
8124" netrwPlugin, you'll need to have had
8125" g:netrw_usetab set to non-zero.
8126fun! netrw#Shrink()
8127" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8128 let curwin = winnr()
8129 let wiwkeep = &wiw
8130 set wiw=1
8131
8132 if &ft == "netrw"
8133 if winwidth(0) > g:netrw_wiw
8134 let t:netrw_winwidth= winwidth(0)
8135 exe "vert resize ".g:netrw_wiw
8136 wincmd l
8137 if winnr() == curwin
8138 wincmd h
8139 endif
8140" call Decho("vert resize 0",'~'.expand("<slnum>"))
8141 else
8142 exe "vert resize ".t:netrw_winwidth
8143" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8144 endif
8145
8146 elseif exists("t:netrw_lexbufnr")
8147 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8148 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8149 let t:netrw_winwidth= winwidth(0)
8150 exe "vert resize ".g:netrw_wiw
8151 wincmd l
8152 if winnr() == curwin
8153 wincmd h
8154 endif
8155" call Decho("vert resize 0",'~'.expand("<slnum>"))
8156 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8157 exe "vert resize ".t:netrw_winwidth
8158" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8159 else
8160 call netrw#Lexplore(0,0)
8161 endif
8162
8163 else
8164 call netrw#Lexplore(0,0)
8165 endif
8166 let wiw= wiwkeep
8167
8168" call Dret("netrw#Shrink")
8169endfun
8170
8171" ---------------------------------------------------------------------
8172" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8173fun! s:NetSortSequence(islocal)
8174" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8175
8176 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008177 let svpos= winsaveview()
8178" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008179 call inputsave()
8180 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8181 call inputrestore()
8182
8183 " refresh the listing
8184 let g:netrw_sort_sequence= newsortseq
8185 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008186" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8187 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188 let @@= ykeep
8189
8190" call Dret("NetSortSequence")
8191endfun
8192
8193" ---------------------------------------------------------------------
8194" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8195" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008196" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008197fun! s:NetrwUnmarkList(curbufnr,curdir)
8198" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8199
8200 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008201 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008202 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8203 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8204 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8205 call remove(s:netrwmarkfilelist,idx) " remove from global list
8206 endfor
8207 if s:netrwmarkfilelist == []
8208 unlet s:netrwmarkfilelist
8209 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008210
Bram Moolenaar446cb832008-06-24 21:56:24 +00008211 " getting rid of the local marked-file lists is easy
8212 unlet s:netrwmarkfilelist_{a:curbufnr}
8213 endif
8214 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8215 unlet s:netrwmarkfilemtch_{a:curbufnr}
8216 endif
8217 2match none
8218" call Dret("s:NetrwUnmarkList")
8219endfun
8220
8221" ---------------------------------------------------------------------
8222" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8223fun! s:NetrwUnmarkAll()
8224" call Dfunc("s:NetrwUnmarkAll()")
8225 if exists("s:netrwmarkfilelist")
8226 unlet s:netrwmarkfilelist
8227 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008228 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008229 2match none
8230" call Dret("s:NetrwUnmarkAll")
8231endfun
8232
8233" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008234" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008235fun! s:NetrwUnmarkAll2()
8236" call Dfunc("s:NetrwUnmarkAll2()")
8237 redir => netrwmarkfilelist_let
8238 let
8239 redir END
8240 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008242 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8243 for flist in netrwmarkfilelist_list
8244 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8245 unlet s:netrwmarkfilelist_{curbufnr}
8246 unlet s:netrwmarkfilemtch_{curbufnr}
8247 endfor
8248" call Dret("s:NetrwUnmarkAll2")
8249endfun
8250
8251" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008252" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8253"
8254" Marked files are in two types of lists:
8255" s:netrwmarkfilelist -- holds complete paths to all marked files
8256" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8257"
8258" Marked files suitable for use with 2match are in:
8259" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008260fun! s:NetrwUnMarkFile(islocal)
8261" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008262 let svpos = winsaveview()
8263" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008264 let curbufnr = bufnr("%")
8265
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008266 " unmark marked file list
8267 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8268 if exists("s:netrwmarkfilelist")
8269" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008270 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008271 endif
8272
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008273 let ibuf= 1
8274 while ibuf < bufnr("$")
8275 if exists("s:netrwmarkfilelist_".ibuf)
8276 unlet s:netrwmarkfilelist_{ibuf}
8277 unlet s:netrwmarkfilemtch_{ibuf}
8278 endif
8279 let ibuf = ibuf + 1
8280 endwhile
8281 2match none
8282
Bram Moolenaar446cb832008-06-24 21:56:24 +00008283" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008284"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8285call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008286" call Dret("s:NetrwUnMarkFile")
8287endfun
8288
8289" ---------------------------------------------------------------------
8290" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8291fun! s:NetrwMenu(domenu)
8292
8293 if !exists("g:NetrwMenuPriority")
8294 let g:NetrwMenuPriority= 80
8295 endif
8296
Bram Moolenaaradc21822011-04-01 18:03:16 +02008297 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008298" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8299
8300 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008301" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008302 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008303 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8304 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8305 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8306 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8307 if g:netrw_dirhistmax > 0
8308 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8309 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8310 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8311 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8312 else
8313 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8314 endif
8315 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8316 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8317 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8318 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8319 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8320 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8321 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8322 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8323 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8324 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8325 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8326 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8327 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8328 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8329 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 +01008330 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 +02008331 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8332 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8333 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8334 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8335 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8336 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8337 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8338 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8339 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8340 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8341 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8342 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8343 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8344 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8345 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8346 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8347 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8348 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8349 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8350 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8351 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8352 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8353 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8354 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8355 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8356 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8357 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8358 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8359 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8360 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>'
8361 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>'
8362 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>'
8363 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8364 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>'
8365 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>'
8366 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 +01008367 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 +02008368 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8369 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008370 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008371 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8372 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008373
8374 elseif !a:domenu
8375 let s:netrwcnt = 0
8376 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008377 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008378 exe curwin."wincmd w"
8379
8380 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008381" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008382 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008383" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008384 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008385 endif
8386 endif
8387" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008388 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008389 endif
8390
8391endfun
8392
8393" ---------------------------------------------------------------------
8394" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8395" Used by the O maps (as <SID>NetrwObtain())
8396fun! s:NetrwObtain(islocal)
8397" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8398
Bram Moolenaar97d62492012-11-15 21:28:22 +01008399 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008400 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008401 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008402 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008403 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8404 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008405 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008406 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008407 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008408
8409" call Dret("NetrwObtain")
8410endfun
8411
8412" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008413" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8414" If there's only one window, then the window will first be split.
8415" Returns:
8416" choice = 0 : didn't have to choose
8417" choice = 1 : saved modified file in window first
8418" choice = 2 : didn't save modified file, opened window
8419" choice = 3 : cancel open
8420fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008421" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008422
Bram Moolenaar97d62492012-11-15 21:28:22 +01008423 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008424 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008425 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008426
8427 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008428 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008429 let lastwinnr = winnr("$")
8430 let curword = s:NetrwGetWord()
8431 let choice = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008432 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008433 let curdir = s:treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008434" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008435
Bram Moolenaar8d043172014-01-23 14:24:41 +01008436 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008437 if lastwinnr == 1
8438 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008439" 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 +02008440 " g:netrw_preview=0: preview window shown in a horizontally split window
8441 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008442 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008443 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008444 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008445" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008446 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008447 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008448 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008449 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008450" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008451 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008452 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008453 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008454" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455
8456 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008457 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008458 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008459 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008460 wincmd p
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008461" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008462
8463 " prevwinnr: the window number of the "prev" window
8464 " prevbufnr: the buffer number of the buffer in the "prev" window
8465 " bnrcnt : the qty of windows open on the "prev" buffer
8466 let prevwinnr = winnr()
8467 let prevbufnr = bufnr("%")
8468 let prevbufname = bufname("%")
8469 let prevmod = &mod
8470 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008471 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008472" 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 +01008473
8474 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008475 " and it doesn't appear in any other extant window, then ask the
8476 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008477 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008478" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008479 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008480" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008481 exe prevwinnr."wincmd w"
8482
8483 if bnrcnt == 1 && &hidden == 0
8484 " only one copy of the modified buffer in a window, and
8485 " hidden not set, so overwriting will lose the modified file. Ask first...
8486 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008487" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008488 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008489
8490 if choice == 1
8491 " Yes -- write file & then browse
8492 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008493 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008494 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008495 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008496 exe origwin."wincmd w"
8497 let &ei = eikeep
8498 let @@ = ykeep
8499" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008500 return choice
8501 endif
8502
8503 elseif choice == 2
8504 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008505" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008506 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008507
8508 else
8509 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008510" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008511 exe origwin."wincmd w"
8512 let &ei= eikeep
8513 let @@ = ykeep
8514" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008515 return choice
8516 endif
8517 endif
8518 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008519 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008520 endif
8521
8522 " restore b:netrw_curdir (window split/enew may have lost it)
8523 let b:netrw_curdir= curdir
8524 if a:islocal < 2
8525 if a:islocal
8526 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8527 else
8528 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8529 endif
8530 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008531 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008532" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008533 return choice
8534endfun
8535
8536" ---------------------------------------------------------------------
8537" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8538" Always assumed to be local -> remote
8539" call s:NetrwUpload(filename, target)
8540" call s:NetrwUpload(filename, target, fromdirectory)
8541fun! s:NetrwUpload(fname,tgt,...)
8542" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8543
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008544 if a:tgt =~ '^\a\{3,}://'
8545 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008546 else
8547 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008549" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008550
8551 if a:0 > 0
8552 let fromdir= a:1
8553 else
8554 let fromdir= getcwd()
8555 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008556" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008557
8558 if type(a:fname) == 1
8559 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008560" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008562" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8563 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8564" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008565 if a:tgt =~ '/$'
8566 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008567" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008568 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008569 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008570" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008571 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008572" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 endif
8574 q!
8575
8576 elseif type(a:fname) == 3
8577 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008578" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 let curdir= getcwd()
8580 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008581 if s:NetrwLcd(fromdir)
8582" call Dret("s:NetrwUpload : lcd failure")
8583 return
8584 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008585 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008586 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587 if exists("g:netrw_port") && g:netrw_port != ""
8588 let useport= " ".g:netrw_scpport." ".g:netrw_port
8589 else
8590 let useport= ""
8591 endif
8592 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8593 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008594 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 +02008595 if s:NetrwLcd(curdir)
8596" call Dret("s:NetrwUpload : lcd failure")
8597 return
8598 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599
8600 elseif a:tgt =~ '^ftp:'
8601 call s:NetrwMethod(a:tgt)
8602
8603 if b:netrw_method == 2
8604 " handle uploading a list of files via ftp+.netrc
8605 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008606 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008607" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008608
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008609 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008610" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008611
8612 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008613 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008614" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615 endif
8616
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008617 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008618" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008619
Bram Moolenaaradc21822011-04-01 18:03:16 +02008620 if tgtdir == ""
8621 let tgtdir= '/'
8622 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008623 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008624" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008625
8626 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008627 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8628" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008629 endfor
8630
8631 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008632 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 +00008633 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008634" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8635 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636 endif
8637 " 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 +01008638 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008639 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8641 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8642 else
8643 bw!|q
8644 endif
8645
8646 elseif b:netrw_method == 3
8647 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8648 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008649 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008650 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008651 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008652
8653 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008654 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008655" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008656 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008657 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008658" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008659 endif
8660
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008661 if exists("g:netrw_uid") && g:netrw_uid != ""
8662 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008663 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008664" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008665 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008666 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008667 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008668" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008669 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008670 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008671" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008672 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008673 endif
8674
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008675 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008676" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008677
8678 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008679 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008680" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008681 endif
8682
8683 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008684 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008685" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008686 endif
8687
8688 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008689 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008690" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008691 endfor
8692
8693 " perform ftp:
8694 " -i : turns off interactive prompting from ftp
8695 " -n unix : DON'T use <.netrc>, even though it exists
8696 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008697 NetrwKeepj norm! 1Gdd
8698 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008699 " 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 +01008700 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008701 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008702 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8703 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008704 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008705 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8706 let &debug = debugkeep
8707 let mod = 1
8708 else
8709 bw!|q
8710 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008711 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008712" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008713 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008714 endif
8715 else
8716 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8717 endif
8718 endif
8719
8720" call Dret("s:NetrwUpload")
8721endfun
8722
8723" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008724" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008725fun! s:NetrwPreview(path) range
8726" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008727" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8728" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008729 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008730 NetrwKeepj call s:NetrwOptionsSave("s:")
8731 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8732 NetrwKeepj call s:NetrwOptionsSafe(1)
8733 else
8734 NetrwKeepj call s:NetrwOptionsSafe(0)
8735 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008736 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008737" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008738 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008739" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8740 if g:netrw_preview
8741 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008742 let pvhkeep = &pvh
8743 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8744 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008745" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8746 else
8747 " horizontal split
8748 let pvhkeep = &pvh
8749 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8750 let &pvh = winheight(0) - winsz
8751" 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 +02008752 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008753 " g:netrw_preview g:netrw_alto
8754 " 1 : vert 1: top -- preview window is vertically split off and on the left
8755 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8756 " 0 : 1: top -- preview window is horizontally split off and on the top
8757 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8758 "
8759 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowse() check via
8760 " the BufEnter event set up in netrwPlugin.vim
8761" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8762 let eikeep = &ei
8763 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008764 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008765 let &ei= eikeep
8766" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008767 if exists("pvhkeep")
8768 let &pvh= pvhkeep
8769 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008770 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008771 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772 endif
8773 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008774 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 +00008775 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008776 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008777 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778" call Dret("NetrwPreview")
8779endfun
8780
8781" ---------------------------------------------------------------------
8782" s:NetrwRefresh: {{{2
8783fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008784" 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 +00008785 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008786 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008787" call Decho("setl ma noro",'~'.expand("<slnum>"))
8788" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008789 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008790 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8791 if !exists("w:netrw_treetop")
8792 if exists("b:netrw_curdir")
8793 let w:netrw_treetop= b:netrw_curdir
8794 else
8795 let w:netrw_treetop= getcwd()
8796 endif
8797 endif
8798 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8799 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008800
8801 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008802 let screenposn = winsaveview()
8803" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008804
8805" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8806" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8807 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008809 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008810 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008811 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008812 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008813
8814 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008815" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8816 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008817
8818 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008819 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8820 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8821" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8822 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8823 else
8824" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8825 2match none
8826 endif
8827 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828
Bram Moolenaar97d62492012-11-15 21:28:22 +01008829" restore
8830 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008831" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832endfun
8833
8834" ---------------------------------------------------------------------
8835" s:NetrwRefreshDir: refreshes a directory by name {{{2
8836" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008837" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008839" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008840 if g:netrw_fastbrowse == 0
8841 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008842" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008843 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008844" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008845
8846 if tgtwin > 0
8847 " tgtwin is being displayed, so refresh it
8848 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008849" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008850 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008851 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008852 exe curwin."wincmd w"
8853
8854 elseif bufnr(a:dirname) > 0
8855 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008856" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
8857 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 endif
8859
8860 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008861" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008862 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008863 endif
8864" call Dret("s:NetrwRefreshDir")
8865endfun
8866
8867" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008868" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8869" window number to do its editing in.
8870" Supports [count]C where the count, if present, is used to specify
8871" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008872fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008873" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008874 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008875" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008876 if a:1 == "" " :NetrwC win#
8877 let g:netrw_chgwin= winnr()
8878 else " :NetrwC
8879 let g:netrw_chgwin= a:1
8880 endif
8881 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008882 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008883 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008884 let g:netrw_chgwin= winnr()
8885 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008886 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008887" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008888endfun
8889
8890" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008891" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8892" What this function does is to compute a priority for the patterns
8893" in the g:netrw_sort_sequence. It applies a substitute to any
8894" "files" that satisfy each pattern, putting the priority / in
8895" front. An "*" pattern handles the default priority.
8896fun! s:NetrwSetSort()
8897" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008898 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008899 if w:netrw_liststyle == s:LONGLIST
8900 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8901 else
8902 let seqlist = g:netrw_sort_sequence
8903 endif
8904 " sanity check -- insure that * appears somewhere
8905 if seqlist == ""
8906 let seqlist= '*'
8907 elseif seqlist !~ '\*'
8908 let seqlist= seqlist.',*'
8909 endif
8910 let priority = 1
8911 while seqlist != ""
8912 if seqlist =~ ','
8913 let seq = substitute(seqlist,',.*$','','e')
8914 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8915 else
8916 let seq = seqlist
8917 let seqlist = ""
8918 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008919 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008920 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008921 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008922 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008924 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008925 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008926" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008927
8928 " sanity check
8929 if w:netrw_bannercnt > line("$")
8930 " apparently no files were left after a Hiding pattern was used
8931" call Dret("SetSort : no files left after hiding")
8932 return
8933 endif
8934 if seq == '*'
8935 let starpriority= spriority
8936 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008937 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008938 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008939 " sometimes multiple sorting patterns will match the same file or directory.
8940 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008941 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8942 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008943 endif
8944 let priority = priority + 1
8945 endwhile
8946 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008947 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8948 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008949 endif
8950
8951 " Following line associated with priority -- items that satisfy a priority
8952 " pattern get prefixed by ###/ which permits easy sorting by priority.
8953 " Sometimes files can satisfy multiple priority patterns -- only the latest
8954 " priority pattern needs to be retained. So, at this point, these excess
8955 " priority prefixes need to be removed, but not directories that happen to
8956 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008957 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8958 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008959 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960
8961" call Dret("SetSort")
8962endfun
8963
Bram Moolenaarff034192013-04-24 18:51:19 +02008964" ---------------------------------------------------------------------
8965" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8966" Implements [count]Tb (bookhist<b>)
8967" [count]Th (bookhist<h>)
8968" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008969fun! s:NetrwSetTgt(islocal,bookhist,choice)
8970" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008971
8972 if a:bookhist == 'b'
8973 " supports choosing a bookmark as a target using a qb-generated list
8974 let choice= a:choice - 1
8975 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008976 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008977 else
8978 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8979 endif
8980
8981 elseif a:bookhist == 'h'
8982 " supports choosing a history stack entry as a target using a qb-generated list
8983 let choice= (a:choice % g:netrw_dirhistmax) + 1
8984 if exists("g:netrw_dirhist_".choice)
8985 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008986 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008987 else
8988 echomsg "Sorry, history#".a:choice." not available!"
8989 endif
8990 endif
8991
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008992 " refresh the display
8993 if !exists("b:netrw_curdir")
8994 let b:netrw_curdir= getcwd()
8995 endif
8996 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8997
Bram Moolenaarff034192013-04-24 18:51:19 +02008998" call Dret("s:NetrwSetTgt")
8999endfun
9000
Bram Moolenaar446cb832008-06-24 21:56:24 +00009001" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009002" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009003fun! s:NetrwSortStyle(islocal)
9004" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009005 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009006 let svpos= winsaveview()
9007" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009008
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009009 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 +01009010 NetrwKeepj norm! 0
9011 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009012" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9013 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009014
9015" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9016endfun
9017
9018" ---------------------------------------------------------------------
9019" s:NetrwSplit: mode {{{2
9020" =0 : net and o
9021" =1 : net and t
9022" =2 : net and v
9023" =3 : local and o
9024" =4 : local and t
9025" =5 : local and v
9026fun! s:NetrwSplit(mode)
9027" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9028
Bram Moolenaar97d62492012-11-15 21:28:22 +01009029 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009030 call s:SaveWinVars()
9031
9032 if a:mode == 0
9033 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009034 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009035 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009036" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009037 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009038 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009039 NetrwKeepj call s:RestoreWinVars()
9040 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009041 unlet s:didsplit
9042
9043 elseif a:mode == 1
9044 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009045 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009046" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009047 tabnew
9048 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009049 NetrwKeepj call s:RestoreWinVars()
9050 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009051 unlet s:didsplit
9052
9053 elseif a:mode == 2
9054 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009055 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009056 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009057" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009058 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009060 NetrwKeepj call s:RestoreWinVars()
9061 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009062 unlet s:didsplit
9063
9064 elseif a:mode == 3
9065 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009066 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009067 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009068" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009069 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009070 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009071 NetrwKeepj call s:RestoreWinVars()
9072 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009073 unlet s:didsplit
9074
9075 elseif a:mode == 4
9076 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009078 let eikeep = &ei
9079 let netrw_winnr = winnr()
9080 let netrw_line = line(".")
9081 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009082 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009083 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009084 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009085 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9086 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009087 let &ei = eikeep
9088 let netrw_curdir = s:NetrwTreeDir(0)
9089" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009090 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009091 let b:netrw_curdir = netrw_curdir
9092 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009093 NetrwKeepj call s:RestoreWinVars()
9094 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009095 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009096 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009097 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9098 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009099 let &ei= eikeep
9100 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009101 unlet s:didsplit
9102
9103 elseif a:mode == 5
9104 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009105 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009106 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009107" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009108 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009109 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009110 NetrwKeepj call s:RestoreWinVars()
9111 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112 unlet s:didsplit
9113
9114 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009115 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009116 endif
9117
Bram Moolenaar97d62492012-11-15 21:28:22 +01009118 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009119" call Dret("s:NetrwSplit")
9120endfun
9121
9122" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009123" s:NetrwTgtMenu: {{{2
9124fun! s:NetrwTgtMenu()
9125 if !exists("s:netrw_menucnt")
9126 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009127 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009128" call Dfunc("s:NetrwTgtMenu()")
9129
9130 " the following test assures that gvim is running, has menus available, and has menus enabled.
9131 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9132 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009133" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009134 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9135 endif
9136 if !exists("s:netrw_initbookhist")
9137 call s:NetrwBookHistRead()
9138 endif
9139
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009140 " try to cull duplicate entries
9141 let tgtdict={}
9142
Bram Moolenaarff034192013-04-24 18:51:19 +02009143 " target bookmarked places
9144 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009145" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009146 let cnt= 1
9147 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009148 if has_key(tgtdict,bmd)
9149 let cnt= cnt + 1
9150 continue
9151 endif
9152 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009153 let ebmd= escape(bmd,g:netrw_menu_escape)
9154 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009155" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009156 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 +02009157 let cnt= cnt + 1
9158 endfor
9159 endif
9160
9161 " target directory browsing history
9162 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009163" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009164 let histcnt = 1
9165 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009166 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009167 if exists("g:netrw_dirhist_{histcnt}")
9168 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009169 if has_key(tgtdict,histentry)
9170 let histcnt = histcnt + 1
9171 continue
9172 endif
9173 let tgtdict[histentry] = histcnt
9174 let ehistentry = escape(histentry,g:netrw_menu_escape)
9175" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009176 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 +02009177 endif
9178 let histcnt = histcnt + 1
9179 endwhile
9180 endif
9181 endif
9182" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009183endfun
9184
9185" ---------------------------------------------------------------------
9186" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9187" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009188fun! s:NetrwTreeDir(islocal)
9189" 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 +02009190" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9191" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9192" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009193
Bram Moolenaar8d043172014-01-23 14:24:41 +01009194 if exists("s:treedir")
9195 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
9196 let treedir= s:treedir
9197 unlet s:treedir
9198" call Dret("s:NetrwTreeDir ".treedir)
9199 return treedir
9200 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009201
Bram Moolenaar8d043172014-01-23 14:24:41 +01009202 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9203 let b:netrw_curdir= getcwd()
9204 endif
9205 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009206" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009207
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009208 let s:treecurpos= winsaveview()
9209" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9210
9211 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009212" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9213" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009214
9215 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009216 let curline= substitute(getline('.'),"\t -->.*$",'','')
9217 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009218" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009219 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009220" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9221 elseif curline =~ '@$'
9222" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9223 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9224" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009225 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009226" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009227 let treedir= ""
9228 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229
9230 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009231" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9232" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009233" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009234 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009235" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009236 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009237" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9238 sil! NetrwKeepj %d _
9239" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009240 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009241" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009242" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009243 endif
9244
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009245" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009246 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9247" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009248
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009249 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9250" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9251" let newdir = w:netrw_treetop.'/'.potentialdir
9252" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9253" let treedir = s:NetrwTreePath(newdir)
9254" let w:netrw_treetop = newdir
9255" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9256" else
9257" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009258 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009259" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009261
9262 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009263 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009264" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009265
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009266" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 return treedir
9268endfun
9269
9270" ---------------------------------------------------------------------
9271" s:NetrwTreeDisplay: recursive tree display {{{2
9272fun! s:NetrwTreeDisplay(dir,depth)
9273" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9274
9275 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009276 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009277
9278 " install ../ and shortdir
9279 if a:depth == ""
9280 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009281" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009282 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009283 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009284 if a:dir == w:netrw_treetop
9285 let shortdir= a:dir
9286 else
9287 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9288 endif
9289 call setline(line("$")+1,a:depth.shortdir)
9290 else
9291 let shortdir= substitute(a:dir,'^.*/','','e')
9292 call setline(line("$")+1,a:depth.shortdir.'/')
9293 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009294" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009295
9296 " append a / to dir if its missing one
9297 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009298
9299 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009300 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009301" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009302
Bram Moolenaar85850f32019-07-19 22:05:51 +02009303 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9304 if g:netrw_hide == 1
9305 " hide given patterns
9306 let listhide= split(g:netrw_list_hide,',')
9307" call Decho("listhide=".string(listhide))
9308 for pat in listhide
9309 call filter(w:netrw_treedict[dir],'v:val !~ "'.pat.'"')
9310 endfor
9311
9312 elseif g:netrw_hide == 2
9313 " show given patterns (only)
9314 let listhide= split(g:netrw_list_hide,',')
9315" call Decho("listhide=".string(listhide))
9316 let entries=[]
9317 for entry in w:netrw_treedict[dir]
9318 for pat in listhide
9319 if entry =~ pat
9320 call add(entries,entry)
9321 break
9322 endif
9323 endfor
9324 endfor
9325 let w:netrw_treedict[dir]= entries
9326 endif
9327 if depth != ""
9328 " always remove "." and ".." entries when there's depth
9329 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9330 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9331 endif
9332
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009333" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009334 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009335 if dir =~ '/$'
9336 let direntry= substitute(dir.entry,'[@/]$','','e')
9337 else
9338 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9339 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009340" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009341 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009342" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009343 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009344 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009345" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9346 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9347 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9348" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009349 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009350 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009351" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009352 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009353 endif
9354 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009355" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009356
Bram Moolenaar446cb832008-06-24 21:56:24 +00009357" call Dret("NetrwTreeDisplay")
9358endfun
9359
9360" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009361" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9362fun! s:NetrwRefreshTreeDict(dir)
9363" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009364 if !exists("w:netrw_treedict")
9365" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9366 return
9367 endif
9368
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009369 for entry in w:netrw_treedict[a:dir]
9370 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9371" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9372
9373 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9374" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9375 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009376 let liststar = s:NetrwGlob(direntry,'*',1)
9377 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009378 let w:netrw_treedict[direntry] = liststar + listdotstar
9379" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9380
9381 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9382" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9383 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009384 let liststar = s:NetrwGlob(direntry.'/','*',1)
9385 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009386 let w:netrw_treedict[direntry]= liststar + listdotstar
9387" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9388
9389 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9390" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9391 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009392 let liststar = s:NetrwGlob(direntry.'/','*',1)
9393 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009394" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9395
9396 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009397" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009398 endif
9399 endfor
9400" call Dret("s:NetrwRefreshTreeDict")
9401endfun
9402
9403" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009404" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009405" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009406fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009407 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00009408" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009409" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9410" 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>"))
9411" 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 +00009412
9413 " update the treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009414" call Decho("update the treetop",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009415 if !exists("w:netrw_treetop")
9416 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009417" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009418 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
9419 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009420" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009421 endif
9422
Bram Moolenaar446cb832008-06-24 21:56:24 +00009423 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009424 " insure that we have a treedict, albeit empty
9425" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009426 let w:netrw_treedict= {}
9427 endif
9428
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009429 " update the dictionary for the current directory
9430" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009431" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009432 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009433 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009434" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009435 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009436
9437 " if past banner, record word
9438 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9439 let fname= expand("<cword>")
9440 else
9441 let fname= ""
9442 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009443" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9444" 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 +00009445
9446 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009447 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009448" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009449
9450 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9451 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009453 1d
9454 endwhile
9455
Bram Moolenaar13600302014-05-22 18:26:40 +02009456 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457
9458" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009459 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009460 endif
9461endfun
9462
9463" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009464" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009465" Normally, treetop is w:netrw_treetop, but a
9466" user of the function ( netrw#SetTreetop() )
9467" wipes that out prior to calling this function
9468fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009469" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9470 if line(".") < w:netrw_bannercnt + 2
9471 let treedir= a:treetop
9472 if treedir !~ '/$'
9473 let treedir= treedir.'/'
9474 endif
9475" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9476 return treedir
9477 endif
9478
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009479 let svpos = winsaveview()
9480" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009481 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009482" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009483 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009484" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9485 let curline= getline('.')
9486" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9487 if curline =~ '/$'
9488" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9489 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9490" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9491 elseif curline =~ '@\s\+-->'
9492" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9493 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9494 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9495" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009496 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009497" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009498 let treedir= ""
9499 endif
9500 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9502" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009503 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9504 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9505 let treedir= dirname.treedir
9506 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009507" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009508 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009509" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009510 if a:treetop =~ '/$'
9511 let treedir= a:treetop.treedir
9512 else
9513 let treedir= a:treetop.'/'.treedir
9514 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009515" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009516 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009517" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009518" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9519 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009520" call Dret("s:NetrwTreePath <".treedir.">")
9521 return treedir
9522endfun
9523
9524" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009525" s:NetrwWideListing: {{{2
9526fun! s:NetrwWideListing()
9527
9528 if w:netrw_liststyle == s:WIDELIST
9529" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9530 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009531 " cpf: characters per filename
9532 " fpl: filenames per line
9533 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009534 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009535" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009536 let b:netrw_cpf= 0
9537 if line("$") >= w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009538 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9539 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009540 else
9541" call Dret("NetrwWideListing")
9542 return
9543 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009544 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009545" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009546
9547 " determine qty files per line (fpl)
9548 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9549 if w:netrw_fpl <= 0
9550 let w:netrw_fpl= 1
9551 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009552" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009553
9554 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009555 " fpc: files per column of wide listing
9556 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009557 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009558 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9559 let newcolstart = w:netrw_bannercnt + fpc
9560 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009561" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009562 if has("clipboard")
9563 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009564 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009565 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009566 while line("$") >= newcolstart
9567 if newcolend > line("$") | let newcolend= line("$") | endif
9568 let newcolqty= newcolend - newcolstart
9569 exe newcolstart
9570 if newcolqty == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009571 exe "sil! NetrwKeepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009572 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009573 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009574 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009575 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009576 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009577 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009578 if has("clipboard")
9579 sil! let @*= keepregstar
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009580 sil! let @+= keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01009581 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009582 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9583 NetrwKeepj call histdel("/",-1)
9584 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9585 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009586" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009587 exe "setl ".g:netrw_bufsettings
Bram Moolenaar85850f32019-07-19 22:05:51 +02009588" 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 +00009589" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009590 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009591 else
9592 if hasmapto("w","n")
9593 sil! nunmap <buffer> w
9594 endif
9595 if hasmapto("b","n")
9596 sil! nunmap <buffer> b
9597 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009598 endif
9599
9600endfun
9601
9602" ---------------------------------------------------------------------
9603" s:PerformListing: {{{2
9604fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009605" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9606" 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 +02009607" 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>"))
9608 sil! NetrwKeepj %d _
9609" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009610
Bram Moolenaar15146672011-10-20 22:22:38 +02009611 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009612" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009613 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009614
Bram Moolenaar85850f32019-07-19 22:05:51 +02009615 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009616 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009617" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009618
9619" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009620" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009621" endif " Decho
9622
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009623" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009624 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9625 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009626" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9627 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009628 endif
9629
9630 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009631 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009632
9633 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009634 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009635" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009636 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009637 if exists("g:netrw_pchk")
9638 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9639 " failure detections.
9640 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009641 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009642 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9643 endif
9644 if exists("g:netrw_pchk")
9645 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9646 else
9647 let curdir= b:netrw_curdir
9648 endif
9649 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9650 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9651 else
9652 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009653 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009654 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009655 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009656 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009657" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009658 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009659 let w:netrw_bannercnt= 1
9660 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009661" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9662" 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 +00009663
Bram Moolenaar85850f32019-07-19 22:05:51 +02009664 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009665 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009666 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009667 let sortby= sortby." reversed"
9668 endif
9669
9670 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009671 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009672" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009673 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009674" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009675 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009676 NetrwKeepj put ='\" Sorted by '.sortby
9677 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009678 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9679 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009680" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009681 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009682 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009683 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9684 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009685 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009686" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009687" 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 +00009688 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009689
Bram Moolenaar85850f32019-07-19 22:05:51 +02009690 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009691 if g:netrw_banner
9692 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009693" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009694 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009695 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009696 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009697 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009698 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009699 endif
9700 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009702" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009703 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009704 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009705 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009706
9707 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009708 if g:netrw_banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02009709" 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 +01009710 if g:netrw_list_hide != "" && g:netrw_hide
9711 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009712 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009713 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009714 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009715 endif
9716 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009717 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009718 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009719
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009720" 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 +01009721 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009722" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009723 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009724" 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 +01009725 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009726 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009727" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009728" 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 +00009729 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009730
9731 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009732 if g:netrw_banner
9733 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009734 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009735" 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 +01009736" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009737" 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 +01009738 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009739
Bram Moolenaar446cb832008-06-24 21:56:24 +00009740 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009742 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009743 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009744 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009745 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009746 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009747" 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 +01009748" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9749 return
9750 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009751 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009752
9753 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009754 if !exists("w:netrw_bannercnt")
9755 let w:netrw_bannercnt= 0
9756 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009757" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9758" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9759" 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 +01009760
Bram Moolenaar5c736222010-01-06 20:54:52 +01009761 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009762" call Decho("manipulate directory listing (hide)",'~'.expand("<slnum>"))
9763" 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 +00009764 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009765 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009766 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009767 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009768" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009769
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009770 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009771 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009772" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009773 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009774
Bram Moolenaar5c736222010-01-06 20:54:52 +01009775 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009776" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009777 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009778 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009779 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009780 else
9781 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009782 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009783 endif
9784 endif
9785 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009786" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009787 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9788 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009789
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009790 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009791 " exten: sort by extension
9792 " The histdel(...,-1) calls remove the last search from the search history
9793" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009794 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9795 NetrwKeepj call histdel("/",-1)
9796 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9797 NetrwKeepj call histdel("/",-1)
9798 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9799 NetrwKeepj call histdel("/",-1)
9800 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9801" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009802 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009803 " normal direction sorting
9804 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9805 else
9806 " reverse direction sorting
9807 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9808 endif
9809 endif
9810 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9811 NetrwKeepj call histdel("/",-1)
9812
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009814 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009815" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009816 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009817" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009818 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009819 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009820" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009821 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009822 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009823 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9824 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009825 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009826 endif
9827
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009828 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009829" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009830 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009831 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009832 call histdel("/",-1)
9833 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834 endif
9835 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009836" 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 +00009837
9838 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009839" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9840" 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 +01009841 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009842" 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 +01009843 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009844" 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 +00009845
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009846 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009847 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009848" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009849 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009850 endif
9851
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009852 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009853 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009854" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9855 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009856 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009857" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9858 else
9859" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9860" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9861" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9862" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009863 endif
9864
9865 " record previous current directory
9866 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009867" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009868
9869 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009870" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9871" 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 +01009872 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009873" 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 +02009874 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009875" 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 +00009876
9877 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009879 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009880" 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 +01009881 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009882" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009883 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9884 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009885" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886
Bram Moolenaar8d043172014-01-23 14:24:41 +01009887 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009888" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9889" 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 +01009890" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9891 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009892 unlet s:treecurpos
9893 endif
9894
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895" 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>"))
9896" 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 +00009897" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9898endfun
9899
9900" ---------------------------------------------------------------------
9901" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009902fun! s:SetupNetrwStatusLine(statline)
9903" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9904
9905 if !exists("s:netrw_setup_statline")
9906 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009907" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009908
9909 if !exists("s:netrw_users_stl")
9910 let s:netrw_users_stl= &stl
9911 endif
9912 if !exists("s:netrw_users_ls")
9913 let s:netrw_users_ls= &laststatus
9914 endif
9915
9916 " set up User9 highlighting as needed
9917 let keepa= @a
9918 redir @a
9919 try
9920 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009921 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009922 if &bg == "dark"
9923 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9924 else
9925 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9926 endif
9927 endtry
9928 redir END
9929 let @a= keepa
9930 endif
9931
9932 " set up status line (may use User9 highlighting)
9933 " insure that windows have a statusline
9934 " make sure statusline is displayed
9935 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009936 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009938 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009939
9940" call Dret("SetupNetrwStatusLine : stl=".&stl)
9941endfun
9942
Bram Moolenaar85850f32019-07-19 22:05:51 +02009943" =========================================
9944" Remote Directory Browsing Support: {{{1
9945" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009946
9947" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009948" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9949" This function assumes that a long listing will be received. Size, time,
9950" and reverse sorts will be requested of the server but not otherwise
9951" enforced here.
9952fun! s:NetrwRemoteFtpCmd(path,listcmd)
9953" 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 +01009954" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009955 " sanity check: {{{3
9956 if !exists("w:netrw_method")
9957 if exists("b:netrw_method")
9958 let w:netrw_method= b:netrw_method
9959 else
9960 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9961" call Dret("NetrwRemoteFtpCmd")
9962 return
9963 endif
9964 endif
9965
9966 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9967 let ffkeep= &ff
9968 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009969" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009970
9971 " clear off any older non-banner lines " {{{3
9972 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009973" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9974 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009975
9976 ".........................................
9977 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9978 " ftp + <.netrc>: Method #2
9979 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009980 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009981 endif
9982 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009983 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009984" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009985 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009987" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009988 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009989" 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>"))
9990 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 +01009991 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009992" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9993 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 +01009994 endif
9995
9996 ".........................................
9997 elseif w:netrw_method == 3 " {{{3
9998 " ftp + machine,id,passwd,filename: Method #3
9999 setl ff=unix
10000 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010001 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010002 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010003 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010004 endif
10005
10006 " handle userid and password
10007 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010008" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010009 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10010 call NetUserPass("ftp:".host)
10011 endif
10012 if exists("g:netrw_uid") && g:netrw_uid != ""
10013 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010014 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010015 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010016 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010017 endif
10018 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010019 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010020 endif
10021 endif
10022
10023 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010024 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010025 endif
10026 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010027 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010028" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010029 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010030 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010031
10032 " perform ftp:
10033 " -i : turns off interactive prompting from ftp
10034 " -n unix : DON'T use <.netrc>, even though it exists
10035 " -n win32: quit being obnoxious about password
10036 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010037" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010038 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010039" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010040" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10041" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010042 endif
10043
10044 ".........................................
10045 elseif w:netrw_method == 9 " {{{3
10046 " sftp username@machine: Method #9
10047 " s:netrw_sftp_cmd
10048 setl ff=unix
10049
10050 " restore settings
10051 let &ff= ffkeep
10052" call Dret("NetrwRemoteFtpCmd")
10053 return
10054
10055 ".........................................
10056 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010057 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010058 endif
10059
10060 " cleanup for Windows " {{{3
10061 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010062 sil! NetrwKeepj %s/\r$//e
10063 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010064 endif
10065 if a:listcmd == "dir"
10066 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010067 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10068 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10069 NetrwKeepj call histdel("/",-1)
10070 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010071 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 +010010072 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10073 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010074 endif
10075 endif
10076
10077 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10078 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010079 exe 'NetrwKeepj '.w:netrw_bannercnt
10080 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010081 endif
10082 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010083 exe 'NetrwKeepj '.w:netrw_bannercnt
10084 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010085 endif
10086
10087 " restore settings " {{{3
10088 let &ff= ffkeep
10089" call Dret("NetrwRemoteFtpCmd")
10090endfun
10091
10092" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010093" s:NetrwRemoteListing: {{{2
10094fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010095" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010096
Bram Moolenaara6878372014-03-22 21:02:50 +010010097 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10098 let w:netrw_bannercnt= s:bannercnt
10099 endif
10100 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
10101 let w:netrw_bannercnt= s:bannercnt
10102 endif
10103
Bram Moolenaar446cb832008-06-24 21:56:24 +000010104 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010105
Bram Moolenaar446cb832008-06-24 21:56:24 +000010106 " sanity check:
10107 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010108" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010109 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010110" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010111 if !exists("g:netrw_quiet")
10112 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10113 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010114 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010115" call Dret("s:NetrwRemoteListing -1")
10116 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010117 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010118
Bram Moolenaar8d043172014-01-23 14:24:41 +010010119 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010121 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010122 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010123 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 +000010124 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010125 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 +000010126 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010127 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010128
Bram Moolenaar85850f32019-07-19 22:05:51 +020010129 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010130" call Dret("s:NetrwRemoteListing -1")
10131 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010132 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010133" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010134
Bram Moolenaar446cb832008-06-24 21:56:24 +000010135 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010136" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010137 let w:netrw_method= b:netrw_method
10138 endif
10139
Bram Moolenaar13600302014-05-22 18:26:40 +020010140 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010141 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010143 let s:method = "ftp"
10144 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010145 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010146 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010147 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010148 let listcmd= g:netrw_ftp_sizelist_cmd
10149 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010151 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010152" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010153
Bram Moolenaara6878372014-03-22 21:02:50 +010010154 " report on missing file or directory messages
10155 if search('[Nn]o such file or directory\|Failed to change directory')
10156 let mesg= getline(".")
10157 if exists("w:netrw_bannercnt")
10158 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010159 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010160 setl noma
10161 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010162 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010163 call netrw#ErrorMsg(s:WARNING,mesg,96)
10164" call Dret("s:NetrwRemoteListing : -1")
10165 return -1
10166 endif
10167
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010168 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 +000010169 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010170" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010171 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010172
10173 " cleanup
10174 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010175 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10176 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010177 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010178 sil! NetrwKeepj %s/\r$//e
10179 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010180
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010181 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010182 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010183 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010184 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010185" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010186 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010187" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010188 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010189 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010190 exe "sil! NetrwKeepj ".line1
10191 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010192
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010193" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010194 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010195" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010196 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10197 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010198 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010199" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010200 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10201 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10202 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10203 NetrwKeepj call histdel("/",-1)
10204 NetrwKeepj call histdel("/",-1)
10205 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010206 endif
10207 endif
10208
Bram Moolenaar13600302014-05-22 18:26:40 +020010209 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010210 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010211" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010212 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010213" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010214 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010215" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10216 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010217 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010218 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10219 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10220 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10221 NetrwKeepj call histdel("/",-1)
10222 NetrwKeepj call histdel("/",-1)
10223 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010224 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010225 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10226 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010227 endif
10228 else
10229 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010230" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010231 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010232 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010233" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10234 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10235" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010236 endif
10237 endif
10238
10239 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010240 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010241" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010242 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10243 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010244 endif
10245 endif
10246
10247 if w:netrw_liststyle == s:LONGLIST
10248 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010249" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010250
10251 if s:method == "ftp"
10252 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010253 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010254 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010255 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010256 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010257 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010258 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010259 sil! NetrwKeepj 1
10260 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010261 let line2= line(".")
10262 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010263 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010264 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010265 endif
10266 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010267 exe "sil! NetrwKeepj ".line1
10268 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010269 endif
10270
10271 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010272" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010273 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 +000010274 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010275" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010276 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010277 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010278 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10279 NetrwKeepj call histdel("/",-1)
10280 NetrwKeepj call histdel("/",-1)
10281 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010282 endif
10283 endif
10284
10285" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010286" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010287" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010288
10289" call Dret("s:NetrwRemoteListing 0")
10290 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010291endfun
10292
Bram Moolenaar446cb832008-06-24 21:56:24 +000010293" ---------------------------------------------------------------------
10294" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10295fun! s:NetrwRemoteRm(usrhost,path) range
10296" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010297" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010298 let svpos= winsaveview()
10299" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010300
10301 let all= 0
10302 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10303 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010304" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010305 for fname in s:netrwmarkfilelist_{bufnr("%")}
10306 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010307 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010308 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010309 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010310 let all= 1
10311 endif
10312 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010313 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010314
10315 else
10316 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010317" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010318
10319 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010320 let keepsol = &l:sol
10321 setl nosol
10322 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010323
10324 " remove multiple files and directories
10325 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010326 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010327 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010328 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010329 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010330 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010331 let all= 1
10332 endif
10333 let ctr= ctr + 1
10334 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010335 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010336 endif
10337
10338 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010339" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010340 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010341" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10342 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010343
10344" call Dret("s:NetrwRemoteRm")
10345endfun
10346
10347" ---------------------------------------------------------------------
10348" s:NetrwRemoteRmFile: {{{2
10349fun! s:NetrwRemoteRmFile(path,rmfile,all)
10350" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10351
10352 let all= a:all
10353 let ok = ""
10354
10355 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10356 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010357" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010358 if !all
10359 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010360" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010361 call inputsave()
10362 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10363 call inputrestore()
10364 echohl NONE
10365 if ok == ""
10366 let ok="no"
10367 endif
10368 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010369 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010370 let all= 1
10371 endif
10372 endif
10373
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010374 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010375" 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 +000010376 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010377" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010378 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010379 if path =~ '^\a\{3,}://'
10380 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010382 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010383 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10384 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010385" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010386 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010387" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010389 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010390 let ok="q"
10391 else
10392 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010393" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10394" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10395" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010396 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010397 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010398 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010399 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010400 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010401" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010403 if v:shell_error != 0
10404 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +020010405 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 +010010406 else
10407 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10408 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010409 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010410 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010411 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 endif
10414 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010415 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010416" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010417 endif
10418
10419 else
10420 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010421" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010422 if !all
10423 call inputsave()
10424 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10425 call inputrestore()
10426 if ok == ""
10427 let ok="no"
10428 endif
10429 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010430 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010431 let all= 1
10432 endif
10433 endif
10434
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010435 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010436 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010437 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010438 else
10439 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010440 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10441" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010442 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010443" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010444
10445 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010446" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10447 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10448" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010449 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010450" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010451
10452 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010454 endif
10455 endif
10456 endif
10457
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010458 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010459" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 endif
10461 endif
10462
10463" call Dret("s:NetrwRemoteRmFile ".ok)
10464 return ok
10465endfun
10466
10467" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468" s:NetrwRemoteRename: rename a remote file or directory {{{2
10469fun! s:NetrwRemoteRename(usrhost,path) range
10470" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10471
10472 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010473 let svpos = winsaveview()
10474" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010475 let ctr = a:firstline
10476 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10477
10478 " rename files given by the markfilelist
10479 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10480 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010481" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 if exists("subfrom")
10483 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010484" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010485 else
10486 call inputsave()
10487 let newname= input("Moving ".oldname." to : ",oldname)
10488 call inputrestore()
10489 if newname =~ '^s/'
10490 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10491 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10492 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010493" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494 endif
10495 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010496
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010498 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010499 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010500 let oldname= s:ShellEscape(a:path.oldname)
10501 let newname= s:ShellEscape(a:path.newname)
10502" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010503 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010504 endif
10505
10506 endfor
10507 call s:NetrwUnMarkFile(1)
10508
10509 else
10510
10511 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010512 let keepsol= &l:sol
10513 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010515 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516
10517 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010518" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519
10520 call inputsave()
10521 let newname= input("Moving ".oldname." to : ",oldname)
10522 call inputrestore()
10523
10524 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10525 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10526 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010527 let oldname= s:ShellEscape(a:path.oldname)
10528 let newname= s:ShellEscape(a:path.newname)
10529" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010530 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 endif
10532
10533 let ctr= ctr + 1
10534 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010535 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 endif
10537
10538 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010539 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010540" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10541 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542
10543" call Dret("NetrwRemoteRename")
10544endfun
10545
Bram Moolenaar85850f32019-07-19 22:05:51 +020010546" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547" Local Directory Browsing Support: {{{1
10548" ==========================================
10549
10550" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010551" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010552" Should accept: file://localhost/etc/fstab
10553" file:///etc/fstab
10554" file:///c:/WINDOWS/clock.avi
10555" file:///c|/WINDOWS/clock.avi
10556" file://localhost/c:/WINDOWS/clock.avi
10557" file://localhost/c|/WINDOWS/clock.avi
10558" file://c:/foo.txt
10559" file:///c:/foo.txt
10560" 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 +020010561fun! netrw#FileUrlEdit(fname)
10562" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010563 let fname = a:fname
10564 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010565" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010566 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010567" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010568 endif
10569 if (has("win32") || has("win95") || has("win64") || has("win16"))
10570 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010571" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010572 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010573" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010574 endif
10575 endif
10576 let fname2396 = netrw#RFC2396(fname)
10577 let fname2396e= fnameescape(fname2396)
10578 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10579 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010580" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010581 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010583 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10584 endif
10585 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010586
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010587" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10588" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010589 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010590 exe 'NetrwKeepj keepalt edit '.plainfname
10591 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10592
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010593" 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 +020010594" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010595 exe "sil doau BufReadPost ".fname2396e
10596endfun
10597
10598" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599" netrw#LocalBrowseCheck: {{{2
10600fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010601 " This function is called by netrwPlugin.vim's s:LocalBrowse(), s:NetrwRexplore(),
10602 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10603 "
10604 " unfortunate interaction -- split window debugging can't be used here, must use
10605 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10606 " another call to LocalBrowseCheck() when attempts to write
10607 " to the DBG buffer are made.
10608 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010609 " The &ft == "netrw" test was installed because the BufEnter event
10610 " would hit when re-entering netrw windows, creating unexpected
10611 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010612" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010613" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010614" 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 +020010615" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010616" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10617" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010618
Bram Moolenaar97d62492012-11-15 21:28:22 +010010619 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010620 if isdirectory(s:NetrwFile(a:dirname))
10621" 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 +010010622
Bram Moolenaar97d62492012-11-15 21:28:22 +010010623 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010624" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10625" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010626 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010627
Bram Moolenaar446cb832008-06-24 21:56:24 +000010628 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010629" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010630 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010631
Bram Moolenaar5c736222010-01-06 20:54:52 +010010632 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010634 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010635 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010637" 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 +010010638" call Dret("netrw#LocalBrowseCheck")
10639 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010640 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010641
Bram Moolenaar85850f32019-07-19 22:05:51 +020010642 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010643 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10644 " AND IF the listing style is not a tree listing
10645 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010646" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010647 let ibuf = 1
10648 let buflast = bufnr("$")
10649 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010650 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10651 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010652 endif
10653 let ibuf= ibuf + 1
10654 endwhile
10655 endif
10656 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010657" 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>"))
10658" 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 +000010659 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010660" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661endfun
10662
10663" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010664" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010665" performed any shell command. The idea is to cause all local-browsing
10666" buffers to be refreshed after a user has executed some shell command,
10667" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010668fun! s:LocalBrowseRefresh()
10669" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010670" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10671" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010672
Bram Moolenaar446cb832008-06-24 21:56:24 +000010673 " determine which buffers currently reside in a tab
10674 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010675" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010676 return
10677 endif
10678 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010679" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010680 return
10681 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010682 if exists("s:netrw_events") && s:netrw_events == 1
10683 " s:LocalFastBrowser gets called (indirectly) from a
10684 let s:netrw_events= 2
10685" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10686 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010687 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010688 let itab = 1
10689 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010690 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010691 while itab <= tabpagenr("$")
10692 let buftablist = buftablist + tabpagebuflist()
10693 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010694 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010695 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010696" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10697" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010698 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10699 " | refresh any netrw window
10700 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010701 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010702 let ibl = 0
10703 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010704" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010705 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10706 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010707 " (ibuf not shown in a current window AND
10708 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010709" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10710 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010711 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010712" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010713 continue
10714 elseif index(tabpagebuflist(),ibuf) != -1
10715 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010716" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010717 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010718 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010719 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10720 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10721 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10722 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010723" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010724 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10725 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10726 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010727 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010728 endif
10729 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010730" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010731 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010732" call Decho("restore window: win_gotoid(".curwinid.")")
10733 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010734 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010735
Bram Moolenaara6878372014-03-22 21:02:50 +010010736" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010737endfun
10738
10739" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010740" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10741"
10742" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010743" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010744" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10745" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010746" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010747"
10748" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10749" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010750" (re-using a buffer may not be as accurate)
10751"
10752" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
10753" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10754" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10755" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10756" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010757fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020010758" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
10759" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10760" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
10761" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010762
10763 " initialize browselist, a list of buffer numbers that the local browser has used
10764 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010766 let s:netrw_browselist= []
10767 endif
10768
10769 " append current buffer to fastbrowse list
10770 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010772 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010773" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010774 endif
10775
10776 " enable autocmd events to handle refreshing/removing local browser buffers
10777 " If local browse buffer is currently showing: refresh it
10778 " If local browse buffer is currently hidden : wipe it
10779 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10780 " =1 : medium speed, re-use directory listing for remote only
10781 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010782 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10783 let s:netrw_events= 1
10784 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010785 au!
10786 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010787" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010788 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010789 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010790" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010791 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010792 endif
10793 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010794
10795 " user must have changed fastbrowse to its fast setting, so remove
10796 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010797 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010798" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010799 unlet s:netrw_events
10800 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010801 au!
10802 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010803 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010804 endif
10805
Bram Moolenaar85850f32019-07-19 22:05:51 +020010806" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010807endfun
10808
10809" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010810" s:LocalListing: does the job of "ls" for local directories {{{2
10811fun! s:LocalListing()
10812" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010813" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10814" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10815" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010816
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010817" 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
10818" 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
10819" 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 +010010820
10821 " get the list of files contained in the current directory
10822 let dirname = b:netrw_curdir
10823 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010824 let filelist = s:NetrwGlob(dirname,"*",0)
10825 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010826" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010827
10828 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010830 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
10831 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010832" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010833 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010834" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010835 endif
10836
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010837" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010838" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010839" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010840
10841 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
10842 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10843 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010844" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
10845" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010846 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010847" 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 +010010848
10849 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010850" call Decho(" ",'~'.expand("<slnum>"))
10851" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010852" call DechoBuf(bufnr("%"),"COMBAK#1")
Bram Moolenaara6878372014-03-22 21:02:50 +010010853
10854 if getftype(filename) == "link"
10855 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010856" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010857 let pfile= filename."@"
10858
10859 elseif getftype(filename) == "socket"
10860 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010861" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010862 let pfile= filename."="
10863
10864 elseif getftype(filename) == "fifo"
10865 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010866" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010867 let pfile= filename."|"
10868
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010869 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010870 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010871" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010872 let pfile= filename."/"
10873
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010874 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010875 if (has("win32") || has("win95") || has("win64") || has("win16"))
10876 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10877 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010878" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010879 let pfile= filename."*"
10880 else
10881 " normal file
10882 let pfile= filename
10883 endif
10884 elseif executable(filename)
10885 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010886" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010887 let pfile= filename."*"
10888 else
10889 " normal file
10890 let pfile= filename
10891 endif
10892
10893 else
10894 " normal file
10895 let pfile= filename
10896 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010897" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010898
10899 if pfile =~ '//$'
10900 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010901" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010902 endif
10903 let pfile= strpart(pfile,dirnamelen)
10904 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010905" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
10906" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010907
10908 if w:netrw_liststyle == s:LONGLIST
10909 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010910 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010911 let sz= s:NetrwHumanReadable(sz)
10912 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010913 let fsz = strpart(" ",1,15-strlen(sz)).sz
10914 let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
10915 let pfile = longfile.fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010916" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010917 endif
10918
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010919 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010920 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010921" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010922 let t = getftime(filename)
10923 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010924" call Decho("exe NetrwKeepj put ='".ft.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010925 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010926 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010927
10928 elseif g:netrw_sort_by =~ "^s"
10929 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010930" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010931 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010932 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010933 let sz= s:NetrwHumanReadable(sz)
10934 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010935 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010937 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010938 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010939
10940 else
10941 " sort by name
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010942" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010943 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010944 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010945" call DechoBuf(bufnr("%"),"COMBAK#2")
Bram Moolenaara6878372014-03-22 21:02:50 +010010946 endfor
10947
10948 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010949 sil! NetrwKeepj g/^$/d
10950 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010951 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010952" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010953 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10954
10955" call Dret("s:LocalListing")
10956endfun
10957
10958" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010959" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10960fun! s:NetrwLocalExecute(cmd)
10961" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10962 let ykeep= @@
10963 " sanity check
10964 if !executable(a:cmd)
10965 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10966 let @@= ykeep
10967" call Dret("s:NetrwLocalExecute")
10968 return
10969 endif
10970
10971 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010972" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010973 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010974" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010975
10976 " strip any ansi escape sequences off
10977 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10978
10979 " show user the result(s)
10980 echomsg result
10981 let @@= ykeep
10982
10983" call Dret("s:NetrwLocalExecute")
10984endfun
10985
10986" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010987" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010988fun! s:NetrwLocalRename(path) range
10989" call Dfunc("NetrwLocalRename(path<".a:path.">)")
10990
10991 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010992 let ykeep = @@
10993 let ctr = a:firstline
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010994 let svpos = winsaveview()
10995" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010996
10997 " rename files given by the markfilelist
10998 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10999 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011000" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011001 if exists("subfrom")
11002 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011004 else
11005 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011006 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011007 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011008 if newname =~ ''
11009 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11010 let newname = substitute(newname,'^.*','','')
11011 elseif newname =~ ''
11012 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11013 let newname = substitute(newname,'[^/]*','','')
11014 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011015 if newname =~ '^s/'
11016 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11017 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011018" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011019 let newname = substitute(oldname,subfrom,subto,'')
11020 endif
11021 endif
11022 call rename(oldname,newname)
11023 endfor
11024 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011025
Bram Moolenaar97d62492012-11-15 21:28:22 +010011026 else
11027
11028 " attempt to rename files/directories
11029 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011030 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011031
11032 " sanity checks
11033 if line(".") < w:netrw_bannercnt
11034 let ctr= ctr + 1
11035 continue
11036 endif
11037 let curword= s:NetrwGetWord()
11038 if curword == "./" || curword == "../"
11039 let ctr= ctr + 1
11040 continue
11041 endif
11042
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011043 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011044 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011045" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011046
11047 call inputsave()
11048 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11049 call inputrestore()
11050
11051 call rename(oldname,newname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011052" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011053
11054 let ctr= ctr + 1
11055 endwhile
11056 endif
11057
11058 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011059" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011060 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011061" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11062 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011063 let @@= ykeep
11064
11065" call Dret("NetrwLocalRename")
11066endfun
11067
11068" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011069" s:NetrwLocalRm: {{{2
11070fun! s:NetrwLocalRm(path) range
11071" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011072" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011073
11074 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011075 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011076 let ret = 0
11077 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011078 let svpos = winsaveview()
11079" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011080
11081 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11082 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011083" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011084 for fname in s:netrwmarkfilelist_{bufnr("%")}
11085 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011086 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011087 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011088 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011089 let all= 1
11090 endif
11091 endfor
11092 call s:NetrwUnMarkFile(1)
11093
11094 else
11095 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011097
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011098 let keepsol= &l:sol
11099 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011100 let ctr = a:firstline
11101 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011102 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011103
11104 " sanity checks
11105 if line(".") < w:netrw_bannercnt
11106 let ctr= ctr + 1
11107 continue
11108 endif
11109 let curword= s:NetrwGetWord()
11110 if curword == "./" || curword == "../"
11111 let ctr= ctr + 1
11112 continue
11113 endif
11114 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011115 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011116 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011117 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011118 let all= 1
11119 endif
11120 let ctr= ctr + 1
11121 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011123 endif
11124
11125 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011126" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011127 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011128 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011129" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11130 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011131 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011132 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011133
11134" call Dret("s:NetrwLocalRm")
11135endfun
11136
11137" ---------------------------------------------------------------------
11138" s:NetrwLocalRmFile: remove file fname given the path {{{2
11139" Give confirmation prompt unless all==1
11140fun! s:NetrwLocalRmFile(path,fname,all)
11141" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011142
Bram Moolenaar446cb832008-06-24 21:56:24 +000011143 let all= a:all
11144 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011145 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011146 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
11147" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011148
11149 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11150 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011152 if !all
11153 echohl Statement
11154 call inputsave()
11155 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11156 call inputrestore()
11157 echohl NONE
11158 if ok == ""
11159 let ok="no"
11160 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011161" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011162 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011163" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011164 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011165 let all= 1
11166 endif
11167 endif
11168
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011169 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011170 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011171" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011172 endif
11173
11174 else
11175 " attempt to remove directory
11176 if !all
11177 echohl Statement
11178 call inputsave()
11179 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11180 call inputrestore()
11181 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11182 if ok == ""
11183 let ok="no"
11184 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011185 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011186 let all= 1
11187 endif
11188 endif
11189 let rmfile= substitute(rmfile,'[\/]$','','e')
11190
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011191 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +020011192 if v:version < 704 || (v:version == 704 && !has("patch1107"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011193" " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
11194 call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
11195" " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011196
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011197 if v:shell_error != 0
11198" " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11199 let errcode= s:NetrwDelete(rmfile)
11200" " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011201
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011202 if errcode != 0
11203 if has("unix")
11204" " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11205 call system("rm ".s:ShellEscape(rmfile))
11206 if v:shell_error != 0 && !exists("g:netrw_quiet")
11207 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
11208 let ok="no"
11209 endif
11210 elseif !exists("g:netrw_quiet")
11211 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011212 let ok="no"
11213 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011214 endif
11215 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011216 else
11217 if delete(rmfile,"d")
11218 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
11219 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011220 endif
11221 endif
11222 endif
11223
11224" call Dret("s:NetrwLocalRmFile ".ok)
11225 return ok
11226endfun
11227
Bram Moolenaar85850f32019-07-19 22:05:51 +020011228" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011229" Support Functions: {{{1
11230
Bram Moolenaar488c6512005-08-11 20:09:58 +000011231" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011232" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11233" 0: marked file list of current buffer
11234" 1: marked file target
11235fun! netrw#Access(ilist)
11236 if a:ilist == 0
11237 if exists("s:netrwmarkfilelist_".bufnr('%'))
11238 return s:netrwmarkfilelist_{bufnr('%')}
11239 else
11240 return "no-list-buf#".bufnr('%')
11241 endif
11242 elseif a:ilist == 1
11243 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011244 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011245endfun
11246
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011247" ---------------------------------------------------------------------
11248" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11249fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011250 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011251endfun
11252
Bram Moolenaara6878372014-03-22 21:02:50 +010011253" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011254" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11255" I expect this function to be used in
11256" :PChkAssert netrw#Expose("netrwmarkfilelist")
11257" for example.
11258fun! netrw#Expose(varname)
11259" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011260 if exists("s:".a:varname)
11261 exe "let retval= s:".a:varname
11262 if exists("g:netrw_pchk")
11263 if type(retval) == 3
11264 let retval = copy(retval)
11265 let i = 0
11266 while i < len(retval)
11267 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11268 let i = i + 1
11269 endwhile
11270 endif
11271" call Dret("netrw#Expose ".string(retval))
11272 return string(retval)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011273 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011274 else
11275 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011276 endif
11277
11278" call Dret("netrw#Expose ".string(retval))
11279 return retval
11280endfun
11281
11282" ---------------------------------------------------------------------
11283" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11284fun! netrw#Modify(varname,newvalue)
11285" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11286 exe "let s:".a:varname."= ".string(a:newvalue)
11287" call Dret("netrw#Modify")
11288endfun
11289
11290" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011291" netrw#RFC2396: converts %xx into characters {{{2
11292fun! netrw#RFC2396(fname)
11293" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11294 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11295" call Dret("netrw#RFC2396 ".fname)
11296 return fname
11297endfun
11298
11299" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011300" netrw#UserMaps: supports user-specified maps {{{2
11301" see :help function()
11302"
11303" g:Netrw_UserMaps is a List with members such as:
11304" [[keymap sequence, function reference],...]
11305"
11306" The referenced function may return a string,
11307" refresh : refresh the display
11308" -other- : this string will be executed
11309" or it may return a List of strings.
11310"
11311" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011312" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011313" Related functions:
11314" netrw#Expose(varname) -- see s:varname variables
11315" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11316" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11317fun! netrw#UserMaps(islocal)
11318" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11319" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11320
11321 " set up usermaplist
11322 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11323" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11324 for umap in g:Netrw_UserMaps
11325" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11326" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11327 " if umap[0] is a string and umap[1] is a string holding a function name
11328 if type(umap[0]) == 1 && type(umap[1]) == 1
11329" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11330 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11331 else
11332 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11333 endif
11334 endfor
11335 endif
11336" call Dret("netrw#UserMaps")
11337endfun
11338
11339" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011340" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11341fun! netrw#WinPath(path)
11342" call Dfunc("netrw#WinPath(path<".a:path.">)")
11343 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11344 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011345 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011346 " remove trailing slash (Win95)
11347 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11348 " remove escaped spaces
11349 let path = substitute(path, '\ ', ' ', 'g')
11350 " convert slashes to backslashes
11351 let path = substitute(path, '/', '\', 'g')
11352 else
11353 let path= a:path
11354 endif
11355" call Dret("netrw#WinPath <".path.">")
11356 return path
11357endfun
11358
11359" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011360" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11361" cb : bl2mf=0 add marked files to buffer list
11362" cB : bl2mf=1 use bufferlist to mark files
11363" (mnemonic: cb = copy (marked files) to buffer list)
11364fun! s:NetrwBadd(islocal,bl2mf)
11365" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11366 if a:bl2mf
11367 " cB: add buffer list to marked files
11368 redir => bufl
11369 ls
11370 redir END
11371 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11372 for fname in bufl
11373 call s:NetrwMarkFile(a:islocal,fname)
11374 endfor
11375 else
11376 " cb: add marked files to buffer list
11377 for fname in s:netrwmarkfilelist_{bufnr("%")}
11378" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11379 exe "badd ".fnameescape(fname)
11380 endfor
11381 let curbufnr = bufnr("%")
11382 let curdir = s:NetrwGetCurdir(a:islocal)
11383 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11384 endif
11385" call Dret("s:NetrwBadd")
11386endfun
11387
11388" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011389" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11390fun! s:ComposePath(base,subdir)
11391" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11392
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011393 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011394" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011395 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011396 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011397 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011398 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011399 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011400 endif
11401
Bram Moolenaar85850f32019-07-19 22:05:51 +020011402 " COMBAK: test on windows with changing to root directory: :e C:/
11403 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011404" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011405 let ret= a:subdir
11406
Bram Moolenaar85850f32019-07-19 22:05:51 +020011407 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011408" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011409 if a:base =~ '[/\\]$'
11410 let ret= a:base.a:subdir
11411 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011412 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011413 endif
11414
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011415 elseif a:base =~ '^\a\{3,}://'
11416" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011417 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11418 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11419 if a:subdir == '../'
11420 if curpath =~ '[^/]/[^/]\+/$'
11421 let curpath= substitute(curpath,'[^/]\+/$','','')
11422 else
11423 let curpath=""
11424 endif
11425 let ret= urlbase.curpath
11426 else
11427 let ret= urlbase.curpath.a:subdir
11428 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011429" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11430" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11431" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011432
11433 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011434" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011435 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11436 if a:base =~ '^//'
11437 " keeping initial '//' for the benefit of network share listing support
11438 let ret= '/'.ret
11439 endif
11440 let ret= simplify(ret)
11441 endif
11442
11443" call Dret("s:ComposePath ".ret)
11444 return ret
11445endfun
11446
11447" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011448" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11449" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11450fun! s:DeleteBookmark(fname)
11451" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11452 call s:MergeBookmarks()
11453
11454 if exists("g:netrw_bookmarklist")
11455 let indx= index(g:netrw_bookmarklist,a:fname)
11456 if indx == -1
11457 let indx= 0
11458 while indx < len(g:netrw_bookmarklist)
11459 if g:netrw_bookmarklist[indx] =~ a:fname
11460 call remove(g:netrw_bookmarklist,indx)
11461 let indx= indx - 1
11462 endif
11463 let indx= indx + 1
11464 endwhile
11465 else
11466 " remove exact match
11467 call remove(g:netrw_bookmarklist,indx)
11468 endif
11469 endif
11470
11471" call Dret("s:DeleteBookmark")
11472endfun
11473
11474" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011475" s:FileReadable: o/s independent filereadable {{{2
11476fun! s:FileReadable(fname)
11477" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11478
11479 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011480 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011481 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011482 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011483 endif
11484
11485" call Dret("s:FileReadable ".ret)
11486 return ret
11487endfun
11488
11489" ---------------------------------------------------------------------
11490" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11491" Places correct suffix on end of temporary filename,
11492" using the suffix provided with fname
11493fun! s:GetTempfile(fname)
11494" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11495
11496 if !exists("b:netrw_tmpfile")
11497 " get a brand new temporary filename
11498 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011499" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011500
Bram Moolenaarc236c162008-07-13 17:41:49 +000011501 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011502" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011503
Bram Moolenaar9964e462007-05-05 17:54:07 +000011504 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011505 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11506" 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 +010011507 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011508" call Dret("s:GetTempfile getcwd<".getcwd().">")
11509 return ""
11510 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011511
Bram Moolenaar9964e462007-05-05 17:54:07 +000011512 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011513 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011514" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011515
Bram Moolenaar9964e462007-05-05 17:54:07 +000011516 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011517 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011518 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011519 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011520 if !exists("+shellslash") || !&ssl
11521 let tmpfile = substitute(tmpfile,'/','\','g')
11522 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011523 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011524 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011525 endif
11526 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011527" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011528 else
11529 " re-use temporary filename
11530 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011531" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011532 endif
11533
11534 " use fname's suffix for the temporary file
11535 if a:fname != ""
11536 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011537" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011538 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011539 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011540 elseif a:fname =~ '.txz$'
11541 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011542 else
11543 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11544 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011545" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011546 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011547" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011548 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011549" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011550 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11551 endif
11552 endif
11553
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011554" 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 +000011555" call Dret("s:GetTempfile <".tmpfile.">")
11556 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011557endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011558
11559" ---------------------------------------------------------------------
11560" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011561" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011562fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011563" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011564 if s:user == ""
11565 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11566 else
11567 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11568 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011569 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011570 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011571 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011572 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011573 else
11574 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11575 endif
11576" call Dret("s:MakeSshCmd <".sshcmd.">")
11577 return sshcmd
11578endfun
11579
11580" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011581" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11582fun! s:MakeBookmark(fname)
11583" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11584
11585 if !exists("g:netrw_bookmarklist")
11586 let g:netrw_bookmarklist= []
11587 endif
11588
11589 if index(g:netrw_bookmarklist,a:fname) == -1
11590 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011591 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011592 call add(g:netrw_bookmarklist,a:fname.'/')
11593 elseif a:fname !~ '/'
11594 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11595 else
11596 call add(g:netrw_bookmarklist,a:fname)
11597 endif
11598 call sort(g:netrw_bookmarklist)
11599 endif
11600
11601" call Dret("s:MakeBookmark")
11602endfun
11603
11604" ---------------------------------------------------------------------
11605" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11606fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011607" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011608 " get bookmarks from .netrwbook file
11609 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011610 if filereadable(s:NetrwFile(savefile))
11611" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011612 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011613" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011614 NetrwKeepj call delete(savefile)
11615 endif
11616" call Dret("s:MergeBookmarks")
11617endfun
11618
11619" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011620" s:NetrwBMShow: {{{2
11621fun! s:NetrwBMShow()
11622" call Dfunc("s:NetrwBMShow()")
11623 redir => bmshowraw
11624 menu
11625 redir END
11626 let bmshowlist = split(bmshowraw,'\n')
11627 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011628 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011629 if bmshowfuncs != []
11630 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011631 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011632 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011633 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011634 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011635 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011636" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11637endfun
11638
11639" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011640" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
11641fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011642 if !exists("w:netrw_liststyle")
11643 let w:netrw_liststyle= g:netrw_liststyle
11644 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011645" 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 +020011646
11647 if &ft != "netrw"
11648 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11649 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011650" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011651 let &l:cursorline = s:netrw_usercul
11652 let &l:cursorcolumn = s:netrw_usercuc
11653
11654 elseif g:netrw_cursor == 4
11655 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011656" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011657 setl cursorline
11658 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011659
11660 elseif g:netrw_cursor == 3
11661 " thin-long-tree: cursorline, user's cursorcolumn
11662 " wide : cursorline, cursorcolumn
11663 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011664" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011665 setl cursorline
11666 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011667 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011668" 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 +020011669 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011670 let &l:cursorcolumn = s:netrw_usercuc
11671 endif
11672
11673 elseif g:netrw_cursor == 2
11674 " thin-long-tree: cursorline, user's cursorcolumn
11675 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011676" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011677 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +020011678 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011679
11680 elseif g:netrw_cursor == 1
11681 " thin-long-tree: user's cursorline, user's cursorcolumn
11682 " wide : cursorline, user's cursorcolumn
11683 let &l:cursorcolumn = s:netrw_usercuc
11684 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011685" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011686 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011687 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011688" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011689 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011690 endif
11691
11692 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011693 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011694" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011695 let &l:cursorline = s:netrw_usercul
11696 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011697 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011698
11699" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011700endfun
11701
11702" ---------------------------------------------------------------------
11703" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11704fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011705" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011706 if exists("s:netrw_usercul")
11707 let &l:cursorline = s:netrw_usercul
11708 endif
11709 if exists("s:netrw_usercuc")
11710 let &l:cursorcolumn = s:netrw_usercuc
11711 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011712" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11713endfun
11714
11715" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011716" s:NetrwDelete: Deletes a file. {{{2
11717" Uses Steve Hall's idea to insure that Windows paths stay
11718" acceptable. No effect on Unix paths.
11719" Examples of use: let result= s:NetrwDelete(path)
11720fun! s:NetrwDelete(path)
11721" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11722
Bram Moolenaar5c736222010-01-06 20:54:52 +010011723 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011724 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
11725 if exists("+shellslash")
11726 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011727 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011728 let result = delete(path)
11729 let &shellslash = sskeep
11730 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011731" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011732 let result= delete(path)
11733 endif
11734 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011735" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011736 let result= delete(path)
11737 endif
11738 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011739 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011740 endif
11741
11742" call Dret("s:NetrwDelete ".result)
11743 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011744endfun
11745
11746" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011747" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011748fun! s:NetrwEnew(...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011749" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011750" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011751
Bram Moolenaar446cb832008-06-24 21:56:24 +000011752 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011753" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011754 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11755 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11756 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11757 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11758 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11759 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11760 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11761 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11762 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11763 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11764 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11765 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11766 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11767 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11768 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11769 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11770
Bram Moolenaar85850f32019-07-19 22:05:51 +020011771 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011772" call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011773 " when tree listing uses file TreeListing... a new buffer is made.
11774 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011775 " COMBAK: this causes a problem, see P43
11776" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011777 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011778 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011779 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011780" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011781 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011782
Bram Moolenaar446cb832008-06-24 21:56:24 +000011783 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011784" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011785 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11786 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11787 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11788 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11789 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11790 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11791 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11792 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11793 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11794 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11795 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11796 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11797 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11798 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11799 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11800 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11801
Bram Moolenaar5c736222010-01-06 20:54:52 +010011802 if a:0 > 0
11803 let b:netrw_curdir= a:1
11804 if b:netrw_curdir =~ '/$'
11805 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011806 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011807 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011808 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011809 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11810 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011811 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011812 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011813 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011814 endif
11815 endif
11816
Bram Moolenaar8d043172014-01-23 14:24:41 +010011817" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011818endfun
11819
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011820" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011821" s:NetrwExe: executes a string using "!" {{{2
11822fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011823" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011824 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020011825" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011826 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11827 set shell& shellcmdflag& shellxquote& shellxescape&
11828 set shellquote& shellpipe& shellredir& shellslash&
11829 exe a:cmd
11830 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11831 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011832" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011833 exe a:cmd
11834 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011835" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011836endfun
11837
11838" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011839" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11840fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011841 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011842" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011843 let curbuf = bufnr("%")
11844 let curwin = winnr()
11845 let iwin = 1
11846 while iwin <= winnr("$")
11847 exe iwin."wincmd w"
11848 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11849 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11850 let winvars= w:
11851 break
11852 endif
11853 let iwin= iwin + 1
11854 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011855 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011856 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011857" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011858 for k in keys(winvars)
11859 let w:{k}= winvars[k]
11860 endfor
11861 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011862" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011863 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011864endfun
11865
Bram Moolenaara6878372014-03-22 21:02:50 +010011866" ---------------------------------------------------------------------
11867" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011868" Returns: 0=success
11869" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011870fun! s:NetrwLcd(newdir)
11871" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
11872
Bram Moolenaar85850f32019-07-19 22:05:51 +020011873 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011874 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011875 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011876 catch /^Vim\%((\a\+)\)\=:E344/
11877 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11878 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011879 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011880 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11881 " forward slashes by earlier code; so check for both.
11882 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
11883 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11884 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011885 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011886 endif
11887 endif
11888 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011889 let err472= 1
11890 endtry
11891
11892 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011893 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11894 if exists("w:netrw_prvdir")
11895 let a:newdir= w:netrw_prvdir
11896 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011897 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011898" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011899 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011900" 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 +010011901 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011902 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011903" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11904 return -1
11905 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011906
Bram Moolenaar85850f32019-07-19 22:05:51 +020011907" call Dret("s:NetrwLcd 0")
11908 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011909endfun
11910
Bram Moolenaar9964e462007-05-05 17:54:07 +000011911" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011912" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11913" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11914fun! s:NetrwSaveWordPosn()
11915" call Dfunc("NetrwSaveWordPosn()")
11916 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11917" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11918endfun
11919
11920" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011921" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11922" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11923fun! s:NetrwHumanReadable(sz)
11924" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11925
11926 if g:netrw_sizestyle == 'h'
11927 if a:sz >= 1000000000
11928 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11929 elseif a:sz >= 10000000
11930 let sz = printf("%d",a:sz/1000000)."m"
11931 elseif a:sz >= 1000000
11932 let sz = printf("%.1f",a:sz/1000000.0)."m"
11933 elseif a:sz >= 10000
11934 let sz = printf("%d",a:sz/1000)."k"
11935 elseif a:sz >= 1000
11936 let sz = printf("%.1f",a:sz/1000.0)."k"
11937 else
11938 let sz= a:sz
11939 endif
11940
11941 elseif g:netrw_sizestyle == 'H'
11942 if a:sz >= 1073741824
11943 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11944 elseif a:sz >= 10485760
11945 let sz = printf("%d",a:sz/1048576)."M"
11946 elseif a:sz >= 1048576
11947 let sz = printf("%.1f",a:sz/1048576.0)."M"
11948 elseif a:sz >= 10240
11949 let sz = printf("%d",a:sz/1024)."K"
11950 elseif a:sz >= 1024
11951 let sz = printf("%.1f",a:sz/1024.0)."K"
11952 else
11953 let sz= a:sz
11954 endif
11955
11956 else
11957 let sz= a:sz
11958 endif
11959
11960" call Dret("s:NetrwHumanReadable ".sz)
11961 return sz
11962endfun
11963
11964" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011965" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11966" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11967fun! s:NetrwRestoreWordPosn()
11968" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011969 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011970" call Dret("NetrwRestoreWordPosn")
11971endfun
11972
11973" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011974" s:RestoreBufVars: {{{2
11975fun! s:RestoreBufVars()
11976" call Dfunc("s:RestoreBufVars()")
11977
11978 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11979 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11980 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11981 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11982 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11983 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11984
11985" call Dret("s:RestoreBufVars")
11986endfun
11987
11988" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011989" s:RemotePathAnalysis: {{{2
11990fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011991" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011992
Bram Moolenaara6878372014-03-22 21:02:50 +010011993 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011994 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011995 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011996 let s:user = substitute(a:dirname,dirpat,'\3','')
11997 let s:machine = substitute(a:dirname,dirpat,'\4','')
11998 let s:port = substitute(a:dirname,dirpat,'\5','')
11999 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012000 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012001 if s:machine =~ '@'
12002 let dirpat = '^\(.*\)@\(.\{-}\)$'
12003 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12004 let s:machine = substitute(s:machine,dirpat,'\2','')
12005 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012006
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012007" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12008" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12009" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12010" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12011" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12012" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012013
12014" call Dret("s:RemotePathAnalysis")
12015endfun
12016
12017" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012018" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12019" Returns status
12020" Runs system() on
12021" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012022" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012023fun! s:RemoteSystem(cmd)
12024" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12025 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012026 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 +000012027 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012028 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012029 else
12030 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12031 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12032 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012033 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012034 else
12035 let cmd= cmd.' '
12036 endif
12037 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012038" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039 let ret= system(cmd)
12040 endif
12041" call Dret("s:RemoteSystem ".ret)
12042 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012043endfun
12044
12045" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012046" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012047fun! s:RestoreWinVars()
12048" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012049 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012050 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12051 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12052 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12053 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12054 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12055 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12056 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12057 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12058 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12059 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12060 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12061 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012062 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12063 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012064 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12065 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12066 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12067" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012068endfun
12069
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012070" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012071" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12072"
12073" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12074" is true) and a command, :Rexplore, which call this function.
12075"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012076" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012077"
12078" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012079fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012080 if exists("s:netrwdrag")
12081 return
12082 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012083" 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 +010012084" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12085" 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 +010012086
12087 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012088 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012089" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012090 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012091 unlet w:netrw_rexfile
12092" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012093 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012094" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012095" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12096" 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 +020012097 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012098
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012099 " ---------------------------
12100 " :Rex issued while in a file
12101 " ---------------------------
12102
Bram Moolenaara6878372014-03-22 21:02:50 +010012103 " record current file so :Rex can return to it from netrw
12104 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012105" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012106
12107 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012108" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012109 return
12110 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012111" 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 +020012112 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012113 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012114 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012115 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012116 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012117 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012118 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012119 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012120 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012121" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12122 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012123" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12124 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012125 if exists("s:rexposn_".bufnr('%'))
12126 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012127 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012128 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012129" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012130 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012131
Bram Moolenaar85850f32019-07-19 22:05:51 +020012132 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12133 if exists("s:explore_match")
12134 exe "2match netrwMarkFile /".s:explore_match."/"
12135 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012136 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012137
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012138" 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 +010012139" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012140endfun
12141
12142" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012143" s:SaveBufVars: save selected b: variables to s: variables {{{2
12144" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012145fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012146" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012147
12148 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12149 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12150 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12151 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12152 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12153 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12154
12155" call Dret("s:SaveBufVars")
12156endfun
12157
12158" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012159" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12160fun! s:SavePosn(posndict)
12161" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12162
Bram Moolenaar85850f32019-07-19 22:05:51 +020012163 if !exists("a:posndict[bufnr('%')]")
12164 let a:posndict[bufnr("%")]= []
12165 endif
12166" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12167 call add(a:posndict[bufnr("%")],winsaveview())
12168" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012169
12170" call Dret("s:SavePosn posndict")
12171 return a:posndict
12172endfun
12173
12174" ---------------------------------------------------------------------
12175" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12176fun! s:RestorePosn(posndict)
12177" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012178 if exists("a:posndict")
12179 if has_key(a:posndict,bufnr("%"))
12180" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12181 let posnlen= len(a:posndict[bufnr("%")])
12182 if posnlen > 0
12183 let posnlen= posnlen - 1
12184" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12185 call winrestview(a:posndict[bufnr("%")][posnlen])
12186 call remove(a:posndict[bufnr("%")],posnlen)
12187" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12188 endif
12189 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012190 endif
12191" call Dret("s:RestorePosn")
12192endfun
12193
12194" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012195" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012196fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012197" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012198 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12199 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12200 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12201 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12202 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12203 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12204 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12205 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12206 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12207 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12208 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12209 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12210 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12211 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12212 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12213 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12214 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12215 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12216" call Dret("s:SaveWinVars")
12217endfun
12218
12219" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012220" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012221" To allow separate windows to have their own activities, such as
12222" Explore **/pattern, several variables have been made window-oriented.
12223" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012224" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012225" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012226fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012227" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012228 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12229 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12230 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12231 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12232 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12233 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12234 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12235 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12236 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12237 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12238" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012239endfun
12240
12241" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012242" s:SetRexDir: set directory for :Rexplore {{{2
12243fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012244" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012245 let w:netrw_rexdir = a:dirname
12246 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012247 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012248" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12249" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012250" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012251" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012252" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012253endfun
12254
12255" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012256" s:ShowLink: used to modify thin and tree listings to show links {{{2
12257fun! s:ShowLink()
12258" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012259" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12260" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012261 if exists("b:netrw_curdir")
12262 norm! $?\a
12263 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12264 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012265" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12266" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12267" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12268 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012269 let dirlen = strlen(b:netrw_curdir)
12270 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012271" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012272 endif
12273 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012274" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12275" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012276 setl noro ma
12277 call setline(".",modline)
12278 setl ro noma nomod
12279 endif
12280" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12281endfun
12282
12283" ---------------------------------------------------------------------
12284" s:ShowStyle: {{{2
12285fun! s:ShowStyle()
12286 if !exists("w:netrw_liststyle")
12287 let liststyle= g:netrw_liststyle
12288 else
12289 let liststyle= w:netrw_liststyle
12290 endif
12291 if liststyle == s:THINLIST
12292 return s:THINLIST.":thin"
12293 elseif liststyle == s:LONGLIST
12294 return s:LONGLIST.":long"
12295 elseif liststyle == s:WIDELIST
12296 return s:WIDELIST.":wide"
12297 elseif liststyle == s:TREELIST
12298 return s:TREELIST.":tree"
12299 else
12300 return 'n/a'
12301 endif
12302endfun
12303
12304" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012305" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12306" Solution from Nicolai Weibull, vim docs (:help strlen()),
12307" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012308fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012309" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12310
12311 if v:version >= 703 && exists("*strdisplaywidth")
12312 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012313
Bram Moolenaar8d043172014-01-23 14:24:41 +010012314 elseif type(g:Align_xstrlen) == 1
12315 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12316 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012317
Bram Moolenaar8d043172014-01-23 14:24:41 +010012318 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012319 " number of codepoints (Latin a + combining circumflex is two codepoints)
12320 " (comment from TM, solution from NW)
12321 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012322
Bram Moolenaar8d043172014-01-23 14:24:41 +010012323 elseif g:Align_xstrlen == 2
12324 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012325 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12326 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012327 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012328
Bram Moolenaar8d043172014-01-23 14:24:41 +010012329 elseif g:Align_xstrlen == 3
12330 " virtual length (counting, for instance, tabs as anything between 1 and
12331 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012332 " preceded by lam, one otherwise, etc.)
12333 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012334 let modkeep= &l:mod
12335 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012336 call setline(line("."),a:x)
12337 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012338 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012339 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012340 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012341
Bram Moolenaar446cb832008-06-24 21:56:24 +000012342 else
12343 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012344 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012345 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012346" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012347 return ret
12348endfun
12349
12350" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012351" s:ShellEscape: shellescape(), or special windows handling {{{2
12352fun! s:ShellEscape(s, ...)
12353 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12354 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12355 endif
12356 let f = a:0 > 0 ? a:1 : 0
12357 return shellescape(a:s, f)
12358endfun
12359
12360" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012361" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012362fun! s:TreeListMove(dir)
12363" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012364 let curline = getline('.')
12365 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12366 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12367 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12368 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12369 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12370 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12371" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12372" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12373" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12374" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12375" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12376 " COMBAK : need to handle when on a directory
12377 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012378 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012379 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012380 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012381 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012382" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012383 elseif a:dir == '[]' && nxtline != ''
12384 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012385" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012386 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12387 if nl != 0
12388 NetrwKeepj norm! k
12389 else
12390 NetrwKeepj norm! G
12391 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012392" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012393 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012394 endif
12395
12396" call Dret("s:TreeListMove")
12397endfun
12398
12399" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012400" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12401" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12402" can't be called except via emenu. But due to locale, that menu line may not be called
12403" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12404fun! s:UpdateBuffersMenu()
12405" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012406 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012407 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012408 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012409 catch /^Vim\%((\a\+)\)\=:E/
12410 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012411 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012412 endtry
12413 endif
12414" call Dret("s:UpdateBuffersMenu")
12415endfun
12416
12417" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012418" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012419" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012420fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012421" call Dfunc("s:UseBufWinVars()")
12422 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012423 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12424 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12425 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12426 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12427 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12428 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12429 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12430 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12431 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 +000012432" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012433endfun
12434
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012435" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012436" s:UserMaps: supports user-defined UserMaps {{{2
12437" * calls a user-supplied funcref(islocal,curdir)
12438" * interprets result
12439" See netrw#UserMaps()
12440fun! s:UserMaps(islocal,funcname)
12441" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12442
12443 if !exists("b:netrw_curdir")
12444 let b:netrw_curdir= getcwd()
12445 endif
12446 let Funcref = function(a:funcname)
12447 let result = Funcref(a:islocal)
12448
12449 if type(result) == 1
12450 " if result from user's funcref is a string...
12451" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12452 if result == "refresh"
12453" call Decho("refreshing display",'~'.expand("<slnum>"))
12454 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12455 elseif result != ""
12456" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12457 exe result
12458 endif
12459
12460 elseif type(result) == 3
12461 " if result from user's funcref is a List...
12462" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12463 for action in result
12464 if action == "refresh"
12465" call Decho("refreshing display",'~'.expand("<slnum>"))
12466 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12467 elseif action != ""
12468" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12469 exe action
12470 endif
12471 endfor
12472 endif
12473
12474" call Dret("s:UserMaps")
12475endfun
12476
Bram Moolenaar85850f32019-07-19 22:05:51 +020012477" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012478" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012479" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012480let &cpo= s:keepcpo
12481unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012482
Bram Moolenaar85850f32019-07-19 22:05:51 +020012483" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012484" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012485" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012486" vim:ts=8 fdm=marker