blob: 16761554450d98f554b045cb73030d54f6522666 [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 Moolenaarb0d45e72017-11-05 18:19:24 +01003" Date: Nov 03, 2017
4" Version: 162
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 Moolenaarb0d45e72017-11-05 18:19:24 +010025
26" Check that vim has patches that netrw requires.
27" Patches needed: 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 Moolenaarb0d45e72017-11-05 18:19:24 +010041
42let g:loaded_netrw = "v162"
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 Moolenaara0f849e2015-10-30 14:37:44 +010051"let g: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 Moolenaarb0d45e72017-11-05 18:19:24 +010067" 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 Moolenaar8feef4f2015-01-07 16:57:10 +0100112 sil! NetrwKeepj call s:NetrwSafeOptions()
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 Moolenaar5c736222010-01-06 20:54:52 +0100183call s:NetrwInit("g:netrw_dirhist_cnt",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 Moolenaarb0d45e72017-11-05 18:19:24 +0100193" 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100235 if executable("curl")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100236 let g:netrw_http_cmd = "curl"
Bram Moolenaarb0d45e72017-11-05 18:19:24 +0100237 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100241 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100247 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100258call 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 Moolenaar5c736222010-01-06 20:54:52 +0100320call s:NetrwInit("g:netrw_dirhist_cnt" , 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100385 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100397 let g:netrw_localcopydircmd = "cp"
398 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100399 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +0100400 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100403 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100410 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100421 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100437 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100446if 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100456 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100559call 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100920 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100945 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 Moolenaarb0d45e72017-11-05 18:19:24 +0100999 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001036 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001084 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001138 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001157 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001166" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001173" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001191" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001197" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001200" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001201 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001202" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001206" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001216 if lexwinnr != curwin
1217 exe curwin."wincmd w"
1218 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001219 unlet t:netrw_lexbufnr
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001220" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001235" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001238 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001242 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001245 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001253" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001270" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001388 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001400 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001434 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" ------------------------------------------------------------------------
1604" s:NetrwOptionRestore: restore options (based on prior s:NetrwOptionSave) {{{2
1605fun! s:NetrwOptionRestore(vt)
1606" call Dfunc("s:NetrwOptionRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001607" 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 +01001608 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001609" 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>"))
1610" 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 +01001611" call Dret("s:NetrwOptionRestore : ".a:vt."netrw_optionsave doesn't exist")
1612 return
1613 endif
1614 unlet {a:vt}netrw_optionsave
1615
1616 if exists("+acd")
1617 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001618" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001619 let curdir = getcwd()
1620 let &l:acd = {a:vt}netrw_acdkeep
1621 unlet {a:vt}netrw_acdkeep
1622 if &l:acd
1623 call s:NetrwLcd(curdir)
1624 endif
1625 endif
1626 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001627 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1628 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1629 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1630 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1631 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1632 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1633 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1634 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1635 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1636 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1637 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1638 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1639 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1640 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1641 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001642 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001643 call s:NetrwRestoreSetting(a:vt."netrw_fokeep","&l:fo")
1644 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep","&l:gd")
1645 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep","&l:hidden")
1646 call s:NetrwRestoreSetting(a:vt."netrw_imkeep","&l:im")
1647 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep","&l:isk")
1648 call s:NetrwRestoreSetting(a:vt."netrw_lskeep","&l:ls")
1649 call s:NetrwRestoreSetting(a:vt."netrw_makeep","&l:ma")
1650 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
1651 call s:NetrwRestoreSetting(a:vt."netrw_modkeep","&l:mod")
1652 call s:NetrwRestoreSetting(a:vt."netrw_nukeep","&l:nu")
1653 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep","&l:rnu")
1654 call s:NetrwRestoreSetting(a:vt."netrw_repkeep","&l:report")
1655 call s:NetrwRestoreSetting(a:vt."netrw_rokeep","&l:ro")
1656 call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
1657 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
1658 call s:NetrwRestoreSetting(a:vt."netrw_twkeep","&l:tw")
1659 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep","&l:wig")
1660 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep","&l:wrap")
1661 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1662 call s:NetrwRestoreSetting("s:yykeep","@@")
Bram Moolenaara6878372014-03-22 21:02:50 +01001663 " Problem: start with liststyle=0; press <i> : result, following line resets l:ts.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001664 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1665
Bram Moolenaara6878372014-03-22 21:02:50 +01001666 if exists("{a:vt}netrw_swfkeep")
1667 if &directory == ""
1668 " user hasn't specified a swapfile directory;
1669 " netrw will temporarily set the swapfile directory
1670 " to the current directory as returned by getcwd().
1671 let &l:directory= getcwd()
1672 sil! let &l:swf = {a:vt}netrw_swfkeep
1673 setl directory=
1674 unlet {a:vt}netrw_swfkeep
1675 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001676 if !g:netrw_use_noswf
1677 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1678 sil! let &l:swf= {a:vt}netrw_swfkeep
1679 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001680 unlet {a:vt}netrw_swfkeep
1681 endif
1682 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001683 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001684 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1685 if exists("{a:vt}netrw_dirkeep")
1686 call s:NetrwLcd(dirkeep)
1687 unlet {a:vt}netrw_dirkeep
1688 endif
1689 endif
1690 if has("clipboard")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001691 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1692 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001693 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001694 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001695
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001696" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1697" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1698" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1699" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1700" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001701 " Moved the filetype detect here from NetrwGetFile() because remote files
1702 " were having their filetype detect-generated settings overwritten by
1703 " NetrwOptionRestore.
1704 if &ft != "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001705" call Decho("filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001706 filetype detect
1707 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001708" 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 +01001709" call Dret("s:NetrwOptionRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
1710endfun
1711
1712" ---------------------------------------------------------------------
1713" s:NetrwOptionSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1714" Options get restored by s:NetrwOptionRestore()
1715" 06/08/07 : removed call to NetrwSafeOptions(), either placed
1716" immediately after NetrwOptionSave() calls in NetRead
1717" and NetWrite, or after the s:NetrwEnew() call in
1718" NetrwBrowse.
1719" vt: normally its "w:" or "s:" (a variable type)
1720fun! s:NetrwOptionSave(vt)
1721" call Dfunc("s:NetrwOptionSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001722" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
1723" 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 +01001724
1725 if !exists("{a:vt}netrw_optionsave")
1726 let {a:vt}netrw_optionsave= 1
1727 else
1728" call Dret("s:NetrwOptionSave : options already saved")
1729 return
1730 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001731" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001732
1733 " Save current settings and current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001734" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001735 let s:yykeep = @@
1736 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1737 let {a:vt}netrw_aikeep = &l:ai
1738 let {a:vt}netrw_awkeep = &l:aw
1739 let {a:vt}netrw_bhkeep = &l:bh
1740 let {a:vt}netrw_blkeep = &l:bl
Bram Moolenaar13600302014-05-22 18:26:40 +02001741 let {a:vt}netrw_btkeep = &l:bt
Bram Moolenaara6878372014-03-22 21:02:50 +01001742 let {a:vt}netrw_bombkeep = &l:bomb
1743 let {a:vt}netrw_cedit = &cedit
1744 let {a:vt}netrw_cikeep = &l:ci
1745 let {a:vt}netrw_cinkeep = &l:cin
1746 let {a:vt}netrw_cinokeep = &l:cino
1747 let {a:vt}netrw_comkeep = &l:com
1748 let {a:vt}netrw_cpokeep = &l:cpo
1749 let {a:vt}netrw_diffkeep = &l:diff
1750 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001751 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
Bram Moolenaar13600302014-05-22 18:26:40 +02001752 let {a:vt}netrw_ffkeep = &l:ff
1753 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001754 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1755 let {a:vt}netrw_gdkeep = &l:gd " gdefault
1756 let {a:vt}netrw_hidkeep = &l:hidden
1757 let {a:vt}netrw_imkeep = &l:im
1758 let {a:vt}netrw_iskkeep = &l:isk
1759 let {a:vt}netrw_lskeep = &l:ls
1760 let {a:vt}netrw_makeep = &l:ma
1761 let {a:vt}netrw_magickeep = &l:magic
1762 let {a:vt}netrw_modkeep = &l:mod
1763 let {a:vt}netrw_nukeep = &l:nu
Bram Moolenaar13600302014-05-22 18:26:40 +02001764 let {a:vt}netrw_rnukeep = &l:rnu
Bram Moolenaara6878372014-03-22 21:02:50 +01001765 let {a:vt}netrw_repkeep = &l:report
1766 let {a:vt}netrw_rokeep = &l:ro
1767 let {a:vt}netrw_selkeep = &l:sel
1768 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001769 if !g:netrw_use_noswf
1770 let {a:vt}netrw_swfkeep = &l:swf
Bram Moolenaara6878372014-03-22 21:02:50 +01001771 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001772 let {a:vt}netrw_tskeep = &l:ts
1773 let {a:vt}netrw_twkeep = &l:tw " textwidth
1774 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1775 let {a:vt}netrw_wrapkeep = &l:wrap
1776 let {a:vt}netrw_writekeep = &l:write
1777
1778 " save a few selected netrw-related variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001779" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001780 if g:netrw_keepdir
1781 let {a:vt}netrw_dirkeep = getcwd()
1782 endif
1783 if has("clipboard")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001784 sil! let {a:vt}netrw_starkeep = @*
1785 sil! let {a:vt}netrw_pluskeep = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01001786 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001787 sil! let {a:vt}netrw_slashkeep= @/
Bram Moolenaara6878372014-03-22 21:02:50 +01001788
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001789" 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 +01001790" call Dret("s:NetrwOptionSave : tab#".tabpagenr()." win#".winnr())
1791endfun
1792
1793" ------------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001794" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1795" but only if the setting value differs from the associated keepvar.
1796" Doing this means that netrw will not come up as having changed a
1797" setting last when it really didn't actually change it.
1798" Used by s:NetrwOptionRestore() to restore each netrw-senstive setting
1799" and by s:NetrwSafeOptions()
1800fun! s:NetrwRestoreSetting(keepvar,setting)
1801" call Dfunc("s:NetrwRestoreSetting(keepvar<".a:keepvar."> setting<".a:setting.">)")
1802
1803 if a:keepvar =~ '^&'
1804 exe "let keepvarval= ".a:keepvar
1805 if keepvarval != a:setting
1806 if type(a:setting) == 0
1807 exe "let ".a:keepvar."=".a:setting
1808 elseif type(a:setting) == 1
1809 exe "let ".a:keepvar."= '".a:setting."'"
1810 else
1811 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1812 endif
1813 endif
1814
1815 elseif exists(a:keepvar)
1816 exe "let keepvarval= '".a:keepvar."'"
1817 if keepvarval != a:setting
1818 if type(a:setting) == 0
1819 exe "let ".a:keepvar."= ".a:setting
1820 elseif type(a:setting) == 1
1821 exe "let ".a:keepvar."= '".a:setting."'"
1822 else
1823 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1824 endif
1825 endif
1826 exe "unlet ".a:keepvar
1827 endif
1828" call Dret("s:NetrwRestoreSetting")
1829endfun
1830
1831" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001832" s:NetrwSafeOptions: sets options to help netrw do its job {{{2
1833" Use s:NetrwSaveOptions() to save user settings
1834" Use s:NetrwOptionRestore() to restore user settings
1835fun! s:NetrwSafeOptions()
1836" call Dfunc("s:NetrwSafeOptions() win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001837" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1838" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01001839 if exists("+acd") | call s:NetrwRestoreSetting("&l:acd",0)|endif
1840 call s:NetrwRestoreSetting("&l:ai",0)
1841 call s:NetrwRestoreSetting("&l:aw",0)
1842 call s:NetrwRestoreSetting("&l:bl",0)
1843 call s:NetrwRestoreSetting("&l:bomb",0)
1844 call s:NetrwRestoreSetting("&l:bt","nofile")
1845 call s:NetrwRestoreSetting("&l:ci",0)
1846 call s:NetrwRestoreSetting("&l:cin",0)
1847 call s:NetrwRestoreSetting("&l:bh","hide")
1848 call s:NetrwRestoreSetting("&l:cino","")
1849 call s:NetrwRestoreSetting("&l:com","")
1850 if &cpo =~ 'a' | call s:NetrwRestoreSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1851 if &cpo =~ 'A' | call s:NetrwRestoreSetting("&cpo",substitute(&cpo,'A','','g')) | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001852 setl fo=nroql2
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001853 call s:NetrwRestoreSetting("&l:hid",0)
1854 call s:NetrwRestoreSetting("&l:im",0)
Bram Moolenaara6878372014-03-22 21:02:50 +01001855 setl isk+=@ isk+=* isk+=/
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001856 call s:NetrwRestoreSetting("&l:magic",1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001857 if g:netrw_use_noswf
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001858 call s:NetrwRestoreSetting("swf",0)
Bram Moolenaara6878372014-03-22 21:02:50 +01001859 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001860 call s:NetrwRestoreSetting("&l:report",10000)
1861 call s:NetrwRestoreSetting("&l:sel","inclusive")
1862 call s:NetrwRestoreSetting("&l:spell",0)
1863 call s:NetrwRestoreSetting("&l:tw",0)
1864 call s:NetrwRestoreSetting("&l:wig","")
Bram Moolenaara6878372014-03-22 21:02:50 +01001865 setl cedit&
1866 call s:NetrwCursor()
1867
1868 " allow the user to override safe options
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001869" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001870 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001871" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001872 keepalt NetrwKeepj doau FileType netrw
Bram Moolenaara6878372014-03-22 21:02:50 +01001873 endif
1874
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001875" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1876" 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 +01001877" call Dret("s:NetrwSafeOptions")
Bram Moolenaarff034192013-04-24 18:51:19 +02001878endfun
1879
1880" ---------------------------------------------------------------------
1881" NetrwStatusLine: {{{2
1882fun! NetrwStatusLine()
1883
1884" vvv NetrwStatusLine() debugging vvv
1885" let g:stlmsg=""
1886" if !exists("w:netrw_explore_bufnr")
1887" let g:stlmsg="!X<explore_bufnr>"
1888" elseif w:netrw_explore_bufnr != bufnr("%")
1889" let g:stlmsg="explore_bufnr!=".bufnr("%")
1890" endif
1891" if !exists("w:netrw_explore_line")
1892" let g:stlmsg=" !X<explore_line>"
1893" elseif w:netrw_explore_line != line(".")
1894" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1895" endif
1896" if !exists("w:netrw_explore_list")
1897" let g:stlmsg=" !X<explore_list>"
1898" endif
1899" ^^^ NetrwStatusLine() debugging ^^^
1900
1901 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")
1902 " restore user's status line
1903 let &stl = s:netrw_users_stl
1904 let &laststatus = s:netrw_users_ls
1905 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1906 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1907 return ""
1908 else
1909 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1910 endif
1911endfun
1912
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01001913" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001914" Netrw Transfer Functions: {{{1
1915" ===============================
1916
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001918" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001919" mode: =0 read remote file and insert before current line
1920" =1 read remote file and insert after current line
1921" =2 replace with remote file
1922" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001923fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001924" 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 +00001925
Bram Moolenaar5c736222010-01-06 20:54:52 +01001926 " NetRead: save options {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001927 call s:NetrwOptionSave("w:")
1928 call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001929 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001930 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1931 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1932 setl bl
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001933" call Decho("(netrw#NetRead) buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001934
Bram Moolenaar5c736222010-01-06 20:54:52 +01001935 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001936 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001937 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001938 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001939 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001940 elseif a:mode == 2 " replace with remote file
1941 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001942 elseif a:mode == 3 " skip read of file (leave as temporary)
1943 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001944 else
1945 exe a:mode
1946 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001947 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001948 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001949" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001950
Bram Moolenaar5c736222010-01-06 20:54:52 +01001951 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001952 let tmpfile= s:GetTempfile("")
1953 if tmpfile == ""
1954" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001955 return
1956 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001957
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001958 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001959
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001960 " attempt to repeat with previous host-file-etc
1961 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001962" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001963 let choice = b:netrw_lastfile
1964 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001965
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001966 else
1967 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001968" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001969
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001970 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001971 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001972 echomsg 'NetRead Usage:'
1973 echomsg ':Nread machine:path uses rcp'
1974 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1975 echomsg ':Nread "machine id password path" uses ftp'
1976 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1977 echomsg ':Nread fetch://machine/path uses fetch'
1978 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1979 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001980 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001981 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001982 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1983 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1984 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1985 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001986 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001987 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001988
Bram Moolenaar9964e462007-05-05 17:54:07 +00001989 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001990 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001991" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001992 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001993 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001994 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001995 else
1996 " case "... ... ..."
1997 let choice = strpart(choice,1,strlen(choice)-1)
1998 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001999
Bram Moolenaar9964e462007-05-05 17:54:07 +00002000 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002001 let wholechoice = wholechoice . " " . choice
2002 let ichoice = ichoice + 1
2003 if ichoice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002004 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002005 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002006 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002007" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002008 return
2009 endif
2010 let choice= a:{ichoice}
2011 endwhile
2012 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2013 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002014 endif
2015 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002017" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002018 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002019
Bram Moolenaar5c736222010-01-06 20:54:52 +01002020 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002021 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002022 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002023" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002024 return
2025 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002026 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002027
Bram Moolenaar8d043172014-01-23 14:24:41 +01002028 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002029" 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 +02002030 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002031" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002032 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002033" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002034 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002035 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002036
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002037 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002038 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002039 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002040 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2041 echo "(netrw) Processing your read request..."
2042 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002043
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002044 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002045 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002046 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002047" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002048 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002049 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002050 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002051 " ER: the tmpfile is full path: rcp sees C:\... as host C
2052 if s:netrw_has_nt_rcp == 1
2053 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2054 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2055 else
2056 " Any way needed it machine contains a '.'
2057 let uid_machine = g:netrw_machine .'.'. $USERNAME
2058 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002060 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2061 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2062 else
2063 let uid_machine = g:netrw_machine
2064 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002066 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 +00002067 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002068 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002069
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002070 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002071 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002073" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002074 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002075 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002076 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002077 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002078 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002079" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002080 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002081 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002082" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002083 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002084 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002085" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002086 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002087 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 +00002088 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002089 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002090 endif
2091 " 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 +00002092 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002093 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002094 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002095 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002096 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002097 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002098 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002099 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002100 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2101 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002102 q!
2103 endif
2104 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002105 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002107
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002108 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002109 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002110 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2111 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002112" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002113 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002114 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002115 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002116 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002118 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002119" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002120 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002121 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002122" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002124
Bram Moolenaar97d62492012-11-15 21:28:22 +01002125 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002126 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002127 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002128" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002129 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002130 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002131 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002132" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002133 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002134 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002135" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002136 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002137 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002138
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002139 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002140 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002141" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002142 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002143 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002144 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002145" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002146 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002147 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002148" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002149
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002150 " perform ftp:
2151 " -i : turns off interactive prompting from ftp
2152 " -n unix : DON'T use <.netrc>, even though it exists
2153 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002154 NetrwKeepj norm! 1Gdd
2155 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2157 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002158" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002159 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002160 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002161 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002162 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002163 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002164 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002166
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002167 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002168 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002169 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002170" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002172 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 else
2174 let useport= ""
2175 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002176 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2177 " This is workaround to avoid mis-handle windows local-path:
2178 if g:netrw_scp_cmd =~ '^scp' && (has("win32") || has("win95") || has("win64") || has("win16"))
2179 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2180 else
2181 let tmpfile_get = tmpfile
2182 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002183 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 +00002184 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002185 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002186
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002188 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002189 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002190" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002191 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002192 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002193 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002194 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002195" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002196 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002197 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002198
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002199 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2200 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002202 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002203 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 +00002204 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002205 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 +00002206 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002207 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002208
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002210 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002211" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002212 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2213 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002214" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2215" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2216 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 +00002217 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002218" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002219 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002220 endif
2221 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002222" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002223 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002224
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002225 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002226 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002227 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002228" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229
Bram Moolenaar5c736222010-01-06 20:54:52 +01002230 if !executable(g:netrw_dav_cmd)
2231 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2232" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2233 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002235 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002236 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 +01002237 else
2238 " Construct execution string (four lines) which will be passed through filter
2239 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2240 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002241 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002242 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002244 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002245 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002246 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002247 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002248 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002249 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002250 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2251 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002252
Bram Moolenaar5c736222010-01-06 20:54:52 +01002253 " perform cadaver operation:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002254 NetrwKeepj norm! 1Gdd
2255 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002256 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002257 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002258 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002260
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002262 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002263 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002264" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002265 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 +00002266 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002267 let b:netrw_lastfile = choice
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: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002271 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002272 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002273" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002275 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002276 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002277 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002278" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002279 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002280 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002281 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002282 let netrw_option= "http"
2283 else
2284 let netrw_option= "ftp"
2285 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002286" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002287
Bram Moolenaar446cb832008-06-24 21:56:24 +00002288 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002289 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 +00002290 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002291 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 +00002292 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002293
Bram Moolenaar446cb832008-06-24 21:56:24 +00002294 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002296" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002297 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002298
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002299 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002300 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002301 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002302" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2303 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 +00002304 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002305 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002306
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002308 " NetRead: (file) NetRead Method #10 {{{3
2309 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002310" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2311 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002312 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2313 let b:netrw_lastfile = choice
2314
2315 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002316 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002317 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002318 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002319 endif
2320 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002321
Bram Moolenaar5c736222010-01-06 20:54:52 +01002322 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002323 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002324" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002325 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 unlet b:netrw_fname
2327 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002328 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 +01002329" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002330 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002331 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002332 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002333
Bram Moolenaar9964e462007-05-05 17:54:07 +00002334" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002335endfun
2336
2337" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002338" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002339fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002340" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002341
Bram Moolenaar5c736222010-01-06 20:54:52 +01002342 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002343 let mod= 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00002344 call s:NetrwOptionSave("w:")
2345 call s:NetrwSafeOptions()
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaar5c736222010-01-06 20:54:52 +01002347 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002348 let tmpfile= s:GetTempfile("")
2349 if tmpfile == ""
2350" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002351 return
2352 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002353
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002354 if a:0 == 0
2355 let ichoice = 0
2356 else
2357 let ichoice = 1
2358 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002359
Bram Moolenaar9964e462007-05-05 17:54:07 +00002360 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002361" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002362 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002363 " For binary writes, always write entire file.
2364 " (line numbers don't really make sense for that).
2365 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002366" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002368 elseif g:netrw_cygwin
2369 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002370 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002371" 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 +01002372 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002373 else
2374 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002375" 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 +01002376 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002377 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002378
Bram Moolenaar9964e462007-05-05 17:54:07 +00002379 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002380 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002381 " on the temporary file's name. Deletion of the temporary file during
2382 " cleanup then causes an error message.
2383 0file!
2384 endif
2385
Bram Moolenaar5c736222010-01-06 20:54:52 +01002386 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002387 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002388
Bram Moolenaar9964e462007-05-05 17:54:07 +00002389 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 " attempt to repeat with previous host-file-etc
2391 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002392" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 let choice = b:netrw_lastfile
2394 let ichoice= ichoice + 1
2395 else
2396 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002397
Bram Moolenaar8d043172014-01-23 14:24:41 +01002398 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002399 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002400 echomsg 'NetWrite Usage:"'
2401 echomsg ':Nwrite machine:path uses rcp'
2402 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2403 echomsg ':Nwrite "machine id password path" uses ftp'
2404 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2405 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2406 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2407 echomsg ':Nwrite rcp://machine/path uses rcp'
2408 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2409 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2410 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002411 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002412 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002413
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002414 elseif match(choice,"^\"") != -1
2415 if match(choice,"\"$") != -1
2416 " case "..."
2417 let choice=strpart(choice,1,strlen(choice)-2)
2418 else
2419 " case "... ... ..."
2420 let choice = strpart(choice,1,strlen(choice)-1)
2421 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002422
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002423 while match(choice,"\"$") == -1
2424 let wholechoice= wholechoice . " " . choice
2425 let ichoice = ichoice + 1
2426 if choice > a:0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002427 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002428 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002429 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002430" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002431 return
2432 endif
2433 let choice= a:{ichoice}
2434 endwhile
2435 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2436 endif
2437 endif
2438 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002439 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002440" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002441
Bram Moolenaar9964e462007-05-05 17:54:07 +00002442 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002443 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002444 if !exists("b:netrw_method") || b:netrw_method < 0
2445" call Dfunc("netrw#NetWrite : unsupported method")
2446 return
2447 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002448
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002449 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002450 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002451 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002452 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2453 echo "(netrw) Processing your write request..."
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002454" call Decho("(netrw) Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002455 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002456
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002457 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002458 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002459 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002460" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002461 if s:netrw_has_nt_rcp == 1
2462 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2463 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2464 else
2465 let uid_machine = g:netrw_machine .'.'. $USERNAME
2466 endif
2467 else
2468 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2469 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2470 else
2471 let uid_machine = g:netrw_machine
2472 endif
2473 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002474 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 +00002475 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002476
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002477 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002478 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002479 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002480" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002481 let netrw_fname = b:netrw_fname
2482
2483 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2484 let bhkeep = &l:bh
2485 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002486 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002487 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002488
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002489" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002490 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002491 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002492" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002493 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002494 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002495" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002496 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002497 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002498" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002500 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 +00002501 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002502" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2503 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 endif
2505 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2506 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002507 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002508 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002509 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002510 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002512
2513 " remove enew buffer (quietly)
2514 let filtbuf= bufnr("%")
2515 exe curbuf."b!"
2516 let &l:bh = bhkeep
2517 exe filtbuf."bw!"
2518
Bram Moolenaar071d4272004-06-13 20:20:40 +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 + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002523 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002524 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002525" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002526 let netrw_fname = b:netrw_fname
2527 let bhkeep = &l:bh
2528
2529 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2530 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002531 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002532 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002533 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002534
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002535 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002536 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002537" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002538 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002539 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002540" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002541 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002542 if exists("g:netrw_uid") && g:netrw_uid != ""
2543 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002544 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002545" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002546 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002547 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002548 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002549" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002550 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002551 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002552" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002553 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002554 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002555 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002556" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002557 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002558 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002559" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002560 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002561 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002562" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002563 " save choice/id/password for future use
2564 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002565
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002566 " perform ftp:
2567 " -i : turns off interactive prompting from ftp
2568 " -n unix : DON'T use <.netrc>, even though it exists
2569 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002570 NetrwKeepj norm! 1Gdd
2571 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002572 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2573 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002574 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002575 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002576 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002577 let mod=1
2578 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002579
2580 " remove enew buffer (quietly)
2581 let filtbuf= bufnr("%")
2582 exe curbuf."b!"
2583 let &l:bh= bhkeep
2584 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002585
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002586 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002587 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002588 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002590 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002591 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002592 else
2593 let useport= ""
2594 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002595 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 +00002596 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002597
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002598 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002599 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002600 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002602 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2603 if executable(curl)
2604 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002605 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 +01002606 elseif !exists("g:netrw_quiet")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002607 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">".",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002608 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002609
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002610 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002611 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002612 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002613" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002614
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002615 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002616 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2617 let bhkeep = &l:bh
2618
2619 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2620 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002621 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002622 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002623
Bram Moolenaarff034192013-04-24 18:51:19 +02002624 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002625 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002626 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002627 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002628 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002629 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002630 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002631 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002632 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002633 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002634
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002635 " perform cadaver operation:
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002636 NetrwKeepj norm! 1Gdd
2637 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002638
2639 " remove enew buffer (quietly)
2640 let filtbuf= bufnr("%")
2641 exe curbuf."b!"
2642 let &l:bh = bhkeep
2643 exe filtbuf."bw!"
2644
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002645 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002646
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002647 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002648 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002649 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002650" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002651 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 +00002652 let b:netrw_lastfile = choice
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: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002656 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002657" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002658 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002659 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2660 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2661 else
2662 let uid_machine = g:netrw_machine
2663 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002664
2665 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2666 let bhkeep = &l:bh
2667 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002668 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002669 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002670
Bram Moolenaarff034192013-04-24 18:51:19 +02002671 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002672 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002674 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002675 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002676 let filtbuf= bufnr("%")
2677 exe curbuf."b!"
2678 let &l:bh = bhkeep
2679 exe filtbuf."bw!"
2680 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002681
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002682 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002683 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002684 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002685 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002686 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002689
Bram Moolenaar5c736222010-01-06 20:54:52 +01002690 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002691" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002692 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002693" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002694 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002695 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002696 call s:NetrwOptionRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002697
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002698 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002699 " restore modifiability; usually equivalent to set nomod
2700 let &mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002701" 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 +02002702 elseif !exists("leavemod")
2703 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002704" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002705 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706" 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 +00002707 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002708
Bram Moolenaar9964e462007-05-05 17:54:07 +00002709" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710endfun
2711
2712" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002713" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002714" uses NetRead to get a copy of the file into a temporarily file,
2715" then sources that file,
2716" then removes that file.
2717fun! netrw#NetSource(...)
2718" call Dfunc("netrw#NetSource() a:0=".a:0)
2719 if a:0 > 0 && a:1 == '?'
2720 " give help
2721 echomsg 'NetSource Usage:'
2722 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2723 echomsg ':Nsource fetch://machine/path uses fetch'
2724 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002725 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002726 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2727 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2728 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2729 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2730 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002731 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002732 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002733 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002734 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002735" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002736 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002737" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002738 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002739" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002740 if delete(s:netrw_tmpfile)
2741 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2742 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002743 unlet s:netrw_tmpfile
2744 else
2745 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2746 endif
2747 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002748 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002749 endif
2750" call Dret("netrw#NetSource")
2751endfun
2752
Bram Moolenaar8d043172014-01-23 14:24:41 +01002753" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002754" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2755" (implements the :Ntree command)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002756fun! netrw#SetTreetop(iscmd,...)
2757" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2758" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002759
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002760 " iscmd==0: netrw#SetTreetop called using gn mapping
2761 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2762" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002763 " clear out the current tree
2764 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002765" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002766 let inittreetop= w:netrw_treetop
2767 unlet w:netrw_treetop
2768 endif
2769 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002770" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002771 unlet w:netrw_treedict
2772 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002773" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002774
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002775 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002776 let treedir= s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002777" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002778 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779 if isdirectory(s:NetrwFile(a:1))
2780" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002781 let treedir= a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002782 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar8d043172014-01-23 14:24:41 +01002783 let treedir= b:netrw_curdir."/".a:1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002784" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786 " normally the cursor is left in the message window.
2787 " However, here this results in the directory being listed in the message window, which is not wanted.
2788 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002789 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002790 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaara6878372014-03-22 21:02:50 +01002791 let treedir= "."
Bram Moolenaar8d043172014-01-23 14:24:41 +01002792 endif
2793 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002794" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002795
2796 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002797 let islocal= expand("%") !~ '^\a\{3,}://'
2798" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002799
2800 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002801 if islocal
2802 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2803 else
2804 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2805 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002806
Bram Moolenaara6878372014-03-22 21:02:50 +01002807" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002808endfun
2809
Bram Moolenaar9964e462007-05-05 17:54:07 +00002810" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002811" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812" readcmd == %r : replace buffer with newly read file
2813" == 0r : read file at top of buffer
2814" == r : read file after current line
2815" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002816fun! s:NetrwGetFile(readcmd, tfile, method)
2817" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002818
2819 " readcmd=='t': simply do nothing
2820 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002821" 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 +00002822" call Dret("NetrwGetFile : skip read of <".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002823 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002824 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002825
Bram Moolenaar9964e462007-05-05 17:54:07 +00002826 " get name of remote filename (ie. url and all)
2827 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002828" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002829
Bram Moolenaar9964e462007-05-05 17:54:07 +00002830 if exists("*NetReadFixup")
2831 " for the use of NetReadFixup (not otherwise used internally)
2832 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002833 endif
2834
Bram Moolenaar9964e462007-05-05 17:54:07 +00002835 if a:readcmd[0] == '%'
2836 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002837" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002838
2839 " rename the current buffer to the temp file (ie. tfile)
2840 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002841 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002842 else
2843 let tfile= a:tfile
2844 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002845 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846
2847 " edit temporary file (ie. read the temporary file in)
2848 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002849" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 call zip#Browse(tfile)
2851 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002854 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002857 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002858" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002859 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002860 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002862 call tar#Browse(tfile)
2863 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002864" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002865 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002866 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002867" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002868 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002869 endif
2870
2871 " rename buffer back to remote filename
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002872 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002873
Bram Moolenaar97d62492012-11-15 21:28:22 +01002874 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002875 " Note that isk must not include a "/" for scripts.vim
2876 " to process this detection correctly.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002877" call Decho("detect filetype of local version of remote file",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002878 let iskkeep= &l:isk
2879 setl isk-=/
Bram Moolenaar97d62492012-11-15 21:28:22 +01002880 let &l:isk= iskkeep
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002881" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002882 let line1 = 1
2883 let line2 = line("$")
2884
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 elseif !&ma
2886 " 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 +01002887 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002889 return
2890
Bram Moolenaar9964e462007-05-05 17:54:07 +00002891 elseif s:FileReadable(a:tfile)
2892 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002894 let curline = line(".")
2895 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002897 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002898 let line1= curline + 1
2899 let line2= line("$") - lastline + 1
2900
2901 else
2902 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2904" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002905 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002906" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002907 return
2908 endif
2909
2910 " User-provided (ie. optional) fix-it-up command
2911 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002912" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002913 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002914" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002916 endif
2917
Bram Moolenaaradc21822011-04-01 18:03:16 +02002918 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002919 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002920 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002921 endif
2922
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002923" 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 +00002924
2925 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002926" redraw!
2927
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002928" 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 +00002929" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002930endfun
2931
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002933" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002934" Input:
2935" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2936" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002937" b:netrw_method= 1: rcp
2938" 2: ftp + <.netrc>
2939" 3: ftp + machine, id, password, and [path]filename
2940" 4: scp
2941" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002942" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002943" 7: rsync
2944" 8: fetch
2945" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002946" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002947" g:netrw_machine= hostname
2948" b:netrw_fname = filename
2949" g:netrw_port = optional port number (for ftp)
2950" g:netrw_choice = copy of input url (choice)
2951fun! s:NetrwMethod(choice)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002952" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002953
Bram Moolenaar251e1912011-06-19 05:09:16 +02002954 " sanity check: choice should have at least three slashes in it
2955 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2956 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2957 let b:netrw_method = -1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01002958" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002959 return
2960 endif
2961
Bram Moolenaar5c736222010-01-06 20:54:52 +01002962 " record current g:netrw_machine, if any
2963 " curmachine used if protocol == ftp and no .netrc
2964 if exists("g:netrw_machine")
2965 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002967 else
2968 let curmachine= "N O T A HOST"
2969 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002970 if exists("g:netrw_port")
2971 let netrw_port= g:netrw_port
2972 endif
2973
2974 " insure that netrw_ftp_cmd starts off every method determination
2975 " with the current g:netrw_ftp_cmd
2976 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002977
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002978 " initialization
2979 let b:netrw_method = 0
2980 let g:netrw_machine = ""
2981 let b:netrw_fname = ""
2982 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002983 let g:netrw_choice = a:choice
2984
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002985 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002986 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002987 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2988 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002989 " rcpurm : rcp://[user@]host/filename Use rcp
2990 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002991 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002992 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002993 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002994 " rsyncurm : rsync://host[:port]/path Use rsync
2995 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2996 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002997 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002998 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2999 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003000 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3001 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003002 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003003 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003004 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003005 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003006 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003007 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003008 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003009 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003010
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003011" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003012 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003013 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003014 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003015" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003016 let b:netrw_method = 1
3017 let userid = substitute(a:choice,rcpurm,'\1',"")
3018 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3019 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003020 if userid != ""
3021 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003023
Bram Moolenaaradc21822011-04-01 18:03:16 +02003024 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003025 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003026" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003027 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003028 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3029 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3030 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003031
Bram Moolenaar15146672011-10-20 22:22:38 +02003032 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003033 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003034" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003035 let b:netrw_method = 5
3036 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3037 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003038 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003039
Bram Moolenaaradc21822011-04-01 18:03:16 +02003040 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003041 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003042" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003043 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003044 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003045 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3046 else
3047 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3048 endif
3049 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003050
Bram Moolenaaradc21822011-04-01 18:03:16 +02003051 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003052 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003053" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003054 let b:netrw_method = 7
3055 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3056 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003057
Bram Moolenaaradc21822011-04-01 18:03:16 +02003058 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003059 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003060" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003061 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003062 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3063 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3064 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003065" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003066 if userid != ""
3067 let g:netrw_uid= userid
3068 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003069
Bram Moolenaaradc21822011-04-01 18:03:16 +02003070 if curmachine != g:netrw_machine
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003071 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003072 call NetUserPass("ftp:".g:netrw_machine)
3073 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003074 " if there's a change in hostname, require password re-entry
3075 unlet s:netrw_passwd
3076 endif
3077 if exists("netrw_port")
3078 unlet netrw_port
3079 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003080 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003081
Bram Moolenaar446cb832008-06-24 21:56:24 +00003082 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003083 let b:netrw_method = 3
3084 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003085 let host= substitute(g:netrw_machine,'\..*$','','')
3086 if exists("s:netrw_hup[host]")
3087 call NetUserPass("ftp:".host)
3088
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003089 elseif (has("win32") || has("win95") || has("win64") || has("win16")) && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003090" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3091" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003092 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003093 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003094" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003095 endif
3096 let b:netrw_method= 2
3097 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003098" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003099 let b:netrw_method= 2
3100 else
3101 if !exists("g:netrw_uid") || g:netrw_uid == ""
3102 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003103 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003105 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 endif
3107 let b:netrw_method= 3
3108 endif
3109 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003110
Bram Moolenaaradc21822011-04-01 18:03:16 +02003111 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003113" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 let b:netrw_method = 8
3115 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3116 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3117 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3118 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003119
Bram Moolenaaradc21822011-04-01 18:03:16 +02003120 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003122" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3125 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003126 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003128 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003129
Bram Moolenaaradc21822011-04-01 18:03:16 +02003130 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003132" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003133 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let b:netrw_method = 3
3135 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3136 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003137
Bram Moolenaar9964e462007-05-05 17:54:07 +00003138 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 let b:netrw_method = 2
3140 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3141 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3142 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003143
Bram Moolenaaradc21822011-04-01 18:03:16 +02003144 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003145 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003146" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 let b:netrw_method = 9
3148 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3149 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003150
Bram Moolenaaradc21822011-04-01 18:03:16 +02003151 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003152 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003153" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003154 let b:netrw_method = 1
3155 let userid = substitute(a:choice,rcphf,'\2',"")
3156 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3157 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003158" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3159" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3160" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3161" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 if userid != ""
3163 let g:netrw_uid= userid
3164 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003165
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003166 " Method#10: file://user@hostname/...path-to-file {{{3
3167 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003168" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003169 let b:netrw_method = 10
3170 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003171" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003172
Bram Moolenaaradc21822011-04-01 18:03:16 +02003173 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003175 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003176 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003177 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003180 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003181
Bram Moolenaar81695252004-12-29 20:58:21 +00003182 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003183 " remove any leading [:#] from port number
3184 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3185 elseif exists("netrw_port")
3186 " retain port number as implicit for subsequent ftp operations
3187 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003188 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003189
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003190" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3191" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3192" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3193" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003194" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003195" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003196" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003197" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003198" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003199" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003200" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003201" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203
3204" ------------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +00003205" NetReadFixup: this sort of function is typically written by the user {{{2
3206" to handle extra junk that their system's ftp dumps
3207" into the transfer. This function is provided as an
3208" example and as a fix for a Windows 95 problem: in my
3209" experience, win95's ftp always dumped four blank lines
3210" at the end of the transfer.
3211if has("win95") && exists("g:netrw_win95ftp") && g:netrw_win95ftp
3212 fun! NetReadFixup(method, line1, line2)
3213" call Dfunc("NetReadFixup(method<".a:method."> line1=".a:line1." line2=".a:line2.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003214
3215 " sanity checks -- attempt to convert inputs to integers
3216 let method = a:method + 0
3217 let line1 = a:line1 + 0
3218 let line2 = a:line2 + 0
3219 if type(method) != 0 || type(line1) != 0 || type(line2) != 0 || method < 0 || line1 <= 0 || line2 <= 0
3220" call Dret("NetReadFixup")
3221 return
3222 endif
3223
Bram Moolenaar9964e462007-05-05 17:54:07 +00003224 if method == 3 " ftp (no <.netrc>)
3225 let fourblanklines= line2 - 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01003226 if fourblanklines >= line1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003227 exe "sil NetrwKeepj ".fourblanklines.",".line2."g/^\s*$/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003228 call histdel("/",-1)
3229 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003230 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003231
Bram Moolenaar9964e462007-05-05 17:54:07 +00003232" call Dret("NetReadFixup")
3233 endfun
3234endif
3235
3236" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003237" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003238" Usage: :call NetUserPass() -- will prompt for userid and password
3239" :call NetUserPass("uid") -- will prompt for password
3240" :call NetUserPass("uid","password") -- sets global userid and password
3241" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3242" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243fun! NetUserPass(...)
3244
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003245" call Dfunc("NetUserPass() a:0=".a:0)
3246
3247 if !exists('s:netrw_hup')
3248 let s:netrw_hup= {}
3249 endif
3250
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003252 " case: no input arguments
3253
3254 " change host and username if not previously entered; get new password
3255 if !exists("g:netrw_machine")
3256 let g:netrw_machine= input('Enter hostname: ')
3257 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003259 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003260 let g:netrw_uid= input('Enter username: ')
3261 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003262 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003263 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003264
3265 " set up hup database
3266 let host = substitute(g:netrw_machine,'\..*$','','')
3267 if !exists('s:netrw_hup[host]')
3268 let s:netrw_hup[host]= {}
3269 endif
3270 let s:netrw_hup[host].uid = g:netrw_uid
3271 let s:netrw_hup[host].passwd = s:netrw_passwd
3272
3273 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003274 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003275
3276 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003277 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003278 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003279" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003280 let host = substitute(a:1,'^ftp:','','')
3281 let host = substitute(host,'\..*','','')
3282 if exists("s:netrw_hup[host]")
3283 let g:netrw_uid = s:netrw_hup[host].uid
3284 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003285" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3286" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003287 else
3288 let g:netrw_uid = input("Enter UserId: ")
3289 let s:netrw_passwd = inputsecret("Enter Password: ")
3290 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003291
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003292 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003293 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003294" 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 +02003295 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003296 if g:netrw_machine =~ '[0-9.]\+'
3297 let host= g:netrw_machine
3298 else
3299 let host= substitute(g:netrw_machine,'\..*$','','')
3300 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003301 else
3302 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003303 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003304 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003305" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003306 if exists("g:netrw_passwd")
3307 " ask for password if one not previously entered
3308 let s:netrw_passwd= g:netrw_passwd
3309 else
3310 let s:netrw_passwd = inputsecret("Enter Password: ")
3311 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003312 endif
3313
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003314" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003315 if exists("host")
3316 if !exists('s:netrw_hup[host]')
3317 let s:netrw_hup[host]= {}
3318 endif
3319 let s:netrw_hup[host].uid = g:netrw_uid
3320 let s:netrw_hup[host].passwd = s:netrw_passwd
3321 endif
3322
3323 elseif a:0 == 2
3324 let g:netrw_uid = a:1
3325 let s:netrw_passwd = a:2
3326
3327 elseif a:0 == 3
3328 " enter hostname, user-id, and password into the hup dictionary
3329 let host = substitute(a:1,'^\a\+:','','')
3330 let host = substitute(host,'\..*$','','')
3331 if !exists('s:netrw_hup[host]')
3332 let s:netrw_hup[host]= {}
3333 endif
3334 let s:netrw_hup[host].uid = a:2
3335 let s:netrw_hup[host].passwd = a:3
3336 let g:netrw_uid = s:netrw_hup[host].uid
3337 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003338" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3339" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003341
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003342" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003345" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003346" Shared Browsing Support: {{{1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003347" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003349" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003350" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3351fun! s:ExplorePatHls(pattern)
3352" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3353 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003354" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003355 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003356" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003357 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3358" call Dret("s:ExplorePatHls repat<".repat.">")
3359 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003360endfun
3361
3362" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003363" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003364" 0: (user: <mb>) bookmark current directory
3365" 1: (user: <gb>) change to the bookmarked directory
3366" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003367" 3: (browsing) records current directory history
3368" 4: (user: <u>) go up (previous) directory, using history
3369" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003370" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003371fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003372" call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhist_cnt." histmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003373 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3374" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3375 return
3376 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003377
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003378 let ykeep = @@
3379 let curbufnr = bufnr("%")
3380
Bram Moolenaar9964e462007-05-05 17:54:07 +00003381 if a:chg == 0
3382 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003383" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003384 if exists("s:netrwmarkfilelist_{curbufnr}")
3385 call s:NetrwBookmark(0)
3386 echo "bookmarked marked files"
3387 else
3388 call s:MakeBookmark(a:curdir)
3389 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003390 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003391
3392 elseif a:chg == 1
3393 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003394" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003395 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003396" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003397 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003398 else
3399 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3400 endif
3401
3402 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003403" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003404 let didwork= 0
3405 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003406" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003407 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003408" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003409 let cnt= 1
3410 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003411" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003412 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003413 let didwork = 1
3414 let cnt = cnt + 1
3415 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003416 endif
3417
3418 " list directory history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003419 let cnt = g:netrw_dirhist_cnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003420 let first = 1
3421 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003422 if g:netrw_dirhistmax > 0
3423 while ( first || cnt != g:netrw_dirhist_cnt )
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003424" call Decho("first=".first." cnt=".cnt." dirhist_cnt=".g:netrw_dirhist_cnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003425 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003426" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003427 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003428 let didwork= 1
3429 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003430 let histcnt = histcnt + 1
3431 let first = 0
3432 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003433 if cnt < 0
3434 let cnt= cnt + g:netrw_dirhistmax
3435 endif
3436 endwhile
3437 else
3438 let g:netrw_dirhist_cnt= 0
3439 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003440 if didwork
3441 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3442 endif
3443
3444 elseif a:chg == 3
3445 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003446" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003447 if !exists("g:netrw_dirhist_cnt") || !exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}") || g:netrw_dirhist_{g:netrw_dirhist_cnt} != a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003448 if g:netrw_dirhistmax > 0
3449 let g:netrw_dirhist_cnt = ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
3450 let g:netrw_dirhist_{g:netrw_dirhist_cnt} = a:curdir
3451 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003452" call Decho("save dirhist#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003453 endif
3454
3455 elseif a:chg == 4
3456 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003457" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003458 if g:netrw_dirhistmax > 0
Bram Moolenaarff034192013-04-24 18:51:19 +02003459 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003460 if g:netrw_dirhist_cnt < 0
3461 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
3462 endif
3463 else
3464 let g:netrw_dirhist_cnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003465 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003466 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003467" call Decho("changedir u#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003468 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003469 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003470" call Decho("setl ma noro",'~'.expand("<slnum>"))
3471 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003472 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003473" call Decho("setl nomod",'~'.expand("<slnum>"))
3474" 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 +00003475 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003476" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003477 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003478 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003479 if g:netrw_dirhistmax > 0
Bram Moolenaarff034192013-04-24 18:51:19 +02003480 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003481 else
3482 let g:netrw_dirhist_cnt= 0
3483 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003484 echo "Sorry, no predecessor directory exists yet"
3485 endif
3486
3487 elseif a:chg == 5
3488 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003489" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003490 if g:netrw_dirhistmax > 0
3491 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt + 1 ) % g:netrw_dirhistmax
3492 if exists("g:netrw_dirhist_{g:netrw_dirhist_cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003493" call Decho("changedir U#".g:netrw_dirhist_cnt."<".g:netrw_dirhist_{g:netrw_dirhist_cnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003494 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003495" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003496 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003497 sil! NetrwKeepj %d _
3498" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3499" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003500 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003501" 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 +02003502 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt}),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003504 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhist_cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003505 else
3506 let g:netrw_dirhist_cnt= ( g:netrw_dirhist_cnt - 1 ) % g:netrw_dirhistmax
3507 if g:netrw_dirhist_cnt < 0
3508 let g:netrw_dirhist_cnt= g:netrw_dirhist_cnt + g:netrw_dirhistmax
3509 endif
3510 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003511 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003512 else
3513 let g:netrw_dirhist_cnt= 0
3514 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003515 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003516
3517 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003518" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003519 if exists("s:netrwmarkfilelist_{curbufnr}")
3520 call s:NetrwBookmark(1)
3521 echo "removed marked files from bookmarks"
3522 else
3523 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003524 let iremove = v:count
3525 let dremove = g:netrw_bookmarklist[iremove - 1]
3526" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003527 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003528" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3529 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3530 echo "removed ".dremove." from g:netrw_bookmarklist"
3531" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003532 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003533" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003534 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003535 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003536 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003537 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003538" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003539endfun
3540
3541" ---------------------------------------------------------------------
3542" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003543" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003544" Sister function: s:NetrwBookHistSave()
3545fun! s:NetrwBookHistRead()
3546" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003547 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3548" " call Dret("s:NetrwBookHistRead - suppressed due to g:netrw_dirhistmax")
3549 return
3550 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003551 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01003552 if !exists("s:netrw_initbookhist")
3553 let home = s:NetrwHome()
3554 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003555 if filereadable(s:NetrwFile(savefile))
3556" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003557 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003558 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003559 if g:netrw_dirhistmax > 0
3560 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003561 if filereadable(s:NetrwFile(savefile))
3562" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003563 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 endif
3565 let s:netrw_initbookhist= 1
3566 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003567 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003568 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003569 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01003570" call Dret("s:NetrwBookHistRead")
3571endfun
3572
3573" ---------------------------------------------------------------------
3574" s:NetrwBookHistSave: this function saves bookmarks and history {{{2
3575" Sister function: s:NetrwBookHistRead()
3576" I used to do this via viminfo but that appears to
3577" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003578" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3579" will be saved.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003580fun! s:NetrwBookHistSave()
3581" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003582 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003583" call Dret("s:NetrwBookHistSave : dirhistmax=".g:netrw_dirhistmax)
3584 return
3585 endif
3586
Bram Moolenaar5c736222010-01-06 20:54:52 +01003587 let savefile= s:NetrwHome()."/.netrwhist"
3588 1split
3589 call s:NetrwEnew()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003590 if g:netrw_use_noswf
3591 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3592 else
3593 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3594 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003595 setl nocin noai noci magic nospell nohid wig= noaw
3596 setl ma noro write
3597 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003598 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003599
3600 " save .netrwhist -- no attempt to merge
Bram Moolenaarff034192013-04-24 18:51:19 +02003601 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003602 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
3603 call setline(2,"let g:netrw_dirhist_cnt =".g:netrw_dirhist_cnt)
3604 let lastline = line("$")
3605 let cnt = 1
3606 while cnt <= g:netrw_dirhist_cnt
3607 call setline((cnt+lastline),'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3608 let cnt= cnt + 1
3609 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003610 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003611
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003612 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003613 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
3614 " merge and write .netrwbook
3615 let savefile= s:NetrwHome()."/.netrwbook"
3616
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003617 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003618 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003619 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003620 for bdm in booklist
3621 if index(g:netrw_bookmarklist,bdm) == -1
3622 call add(g:netrw_bookmarklist,bdm)
3623 endif
3624 endfor
3625 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003626 endif
3627
3628 " construct and save .netrwbook
3629 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003630 exe "sil! w! ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003631 endif
3632 let bgone= bufnr("%")
3633 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003634 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003635
3636" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003637endfun
3638
3639" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003640" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3641" list of the contents of a local or remote directory. It is assumed that the
3642" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3643" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003644" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003645fun! s:NetrwBrowse(islocal,dirname)
3646 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003647" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003648" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3649" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003650" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003651
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003652 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3653 " This is useful when one edits a local file, then :e ., then :Rex
3654 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3655 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003656" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003657 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003658
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003659 " s:NetrwBrowse : initialize history {{{3
3660 if !exists("s:netrw_initbookhist")
3661 NetrwKeepj call s:NetrwBookHistRead()
3662 endif
3663
3664 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003665 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003666 let dirname= simplify(a:dirname)
3667 else
3668 let dirname= a:dirname
3669 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003670
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003671 " repoint t:netrw_lexbufnr if appropriate
3672 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3673" call Decho("set repointlexbufnr to true!")
3674 let repointlexbufnr= 1
3675 endif
3676
Bram Moolenaar446cb832008-06-24 21:56:24 +00003677 if exists("s:netrw_skipbrowse")
3678 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003679" 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 +01003680" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003681 return
3682 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003683
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003684 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003685 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003686 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003687" call Dret("s:NetrwBrowse : missing shellescape()")
3688 return
3689 endif
3690 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003691 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003692" call Dret("s:NetrwBrowse : missing fnameescape()")
3693 return
3694 endif
3695
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003696 " s:NetrwBrowse : save options: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003697 call s:NetrwOptionSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003698
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003699 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003700 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3701 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3702" call Decho("clearing marked files",'~'.expand("<slnum>"))
3703 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3704 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003705 endif
3706
3707 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003708 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003709" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3710" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003711 if s:NetrwLcd(dirname)
3712" call Dret("s:NetrwBrowse : lcd failure")
3713 return
3714 endif
3715 " call s:NetrwSafeOptions() " tst953 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003716" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003717
Bram Moolenaar5c736222010-01-06 20:54:52 +01003718 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003719 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003720" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003721 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003722" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003723 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003724 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003725 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003726" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003727
3728 " remove any filetype indicator from end of dirname, except for the
3729 " "this is a directory" indicator (/).
3730 " There shouldn't be one of those here, anyway.
3731 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003732" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003733 call s:RemotePathAnalysis(dirname)
3734
3735 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3736 call s:NetrwEnew(dirname)
3737 call s:NetrwSafeOptions()
3738 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003739" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003740 let b:netrw_curdir = dirname
3741 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003742 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003743 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3744 sil call netrw#NetRead(2,url)
3745 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003746" call Decho("url<".url.">",'~'.expand("<slnum>"))
3747" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3748" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003749 if s:path =~ '.bz2'
3750 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3751 elseif s:path =~ '.gz'
3752 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3753 elseif s:path =~ '.gz'
3754 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3755 else
3756 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3757 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003758 endif
3759
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003760 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003761 call s:SetBufWinVars()
3762 call s:NetrwOptionRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003763" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003764 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003765" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003766
Bram Moolenaar446cb832008-06-24 21:56:24 +00003767" call Dret("s:NetrwBrowse : file<".s:fname.">")
3768 return
3769 endif
3770
Bram Moolenaaradc21822011-04-01 18:03:16 +02003771 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003772 call s:UseBufWinVars()
3773
3774 " set up some variables {{{3
3775 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003776 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003777 let s:last_sort_by = g:netrw_sort_by
3778
3779 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003780 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003781
Bram Moolenaar97d62492012-11-15 21:28:22 +01003782 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003783" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003784 let svpos = winsaveview()
3785" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003786 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003787
Bram Moolenaar446cb832008-06-24 21:56:24 +00003788 " maintain markfile highlighting
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003789 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3790 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3791" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3792" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3793 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3794 else
3795" " call Decho("2match none",'~'.expand("<slnum>"))
3796 2match none
3797 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003798 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003799 if reusing && line("$") > 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00003800 call s:NetrwOptionRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003801" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003802 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003803" 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 +01003804" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003805 return
3806 endif
3807
3808 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003809" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003810 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003811 if b:netrw_curdir =~ '[/\\]$'
3812 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3813 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01003814 if b:netrw_curdir =~ '\a:$' && (has("win32") || has("win95") || has("win64") || has("win16"))
3815 let b:netrw_curdir= b:netrw_curdir."/"
3816 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817 if b:netrw_curdir == ''
3818 if has("amiga")
3819 " On the Amiga, the empty string connotes the current directory
3820 let b:netrw_curdir= getcwd()
3821 else
3822 " under unix, when the root directory is encountered, the result
3823 " from the preceding substitute is an empty string.
3824 let b:netrw_curdir= '/'
3825 endif
3826 endif
3827 if !a:islocal && b:netrw_curdir !~ '/$'
3828 let b:netrw_curdir= b:netrw_curdir.'/'
3829 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003830" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003831
3832 " ------------
3833 " (local only) {{{3
3834 " ------------
3835 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003836" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003837
3838 " Set up ShellCmdPost handling. Append current buffer to browselist
3839 call s:LocalFastBrowser()
3840
3841 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3842 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003843" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3844" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003845 if !exists("&l:acd") || !&l:acd
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003846 if s:NetrwLcd(b:netrw_curdir)
3847" call Dret("s:NetrwBrowse : lcd failure")
3848 return
3849 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003850 endif
3851 endif
3852
3853 " --------------------------------
3854 " remote handling: {{{3
3855 " --------------------------------
3856 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003857" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003858
Bram Moolenaar97d62492012-11-15 21:28:22 +01003859 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003860" 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 +02003861 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003862 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003864 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3865 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3866 if dirname !~ '/$'
3867 let dirname= dirname.'/'
3868 endif
3869 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003870" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003871 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003872 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003873" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003874 endif
3875
3876 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3877 if dirname !~ dirpat
3878 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003879 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003880 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003882" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003883 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003884" 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 +00003885" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
3886 return
3887 endif
3888 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003889" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003890 endif " (additional remote handling)
3891
3892 " -----------------------
3893 " Directory Listing: {{{3
3894 " -----------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003895 NetrwKeepj call s:NetrwMaps(a:islocal)
3896 NetrwKeepj call s:NetrwCommands(a:islocal)
3897 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003898
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003899 " restore option(s)
3900 call s:NetrwOptionRestore("w:")
3901" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3902
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003903 " If there is a rexposn: restore position with rexposn
3904 " Otherwise : set rexposn
3905 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003906" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
3907 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3908 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3909 NetrwKeepj exe w:netrw_bannercnt
3910 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003911 else
3912 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3913 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003914 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003915 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003916" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01003917 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003918 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003919
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01003920 " repoint t:netrw_lexbufnr if appropriate
3921 if exists("repointlexbufnr")
3922 let t:netrw_lexbufnr= bufnr("%")
3923" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
3924 endif
3925
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003926 " restore position
3927 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003928" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
3929 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003930 endif
3931
Bram Moolenaara6878372014-03-22 21:02:50 +01003932 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003933 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow, medium speed).
Bram Moolenaara6878372014-03-22 21:02:50 +01003934 " However, s:NetrwBrowse() causes the FocusGained event to fire the firstt time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3936" 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 +02003937" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003938 return
3939endfun
3940
3941" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003942" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3943" may not apply correctly; ie. netrw's idea of the current directory may
3944" differ from vim's. This function insures that netrw's idea of the current
3945" directory is used.
3946fun! s:NetrwFile(fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003947" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003948" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3949" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3950" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3951" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003952
3953 " clean up any leading treedepthstring
3954 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3955 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003956" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003957 else
3958 let fname= a:fname
3959 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003960
3961 if g:netrw_keepdir
3962 " vim's idea of the current directory possibly may differ from netrw's
3963 if !exists("b:netrw_curdir")
3964 let b:netrw_curdir= getcwd()
3965 endif
3966
3967 if !exists("g:netrw_cygwin") && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003968 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003969 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003970 let ret= fname
3971" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003972 else
3973 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003974 let ret= s:ComposePath(b:netrw_curdir,fname)
3975" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003976 endif
3977
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003978 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003980 let ret= fname
3981" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003982 else
3983 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003984 let ret= s:ComposePath(b:netrw_curdir,fname)
3985" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003986 endif
3987 else
3988 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003989 let ret= fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003990" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003991" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3992" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003993 endif
3994
3995" call Dret("s:NetrwFile ".ret)
3996 return ret
3997endfun
3998
3999" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004000" s:NetrwFileInfo: supports qf (query for file information) {{{2
4001fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004002" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004003 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004005 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004006 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004007 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004008 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004009 let lsopt= "-lsadh --si"
4010 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004011 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004012
4013 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004014 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004015" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004016
Bram Moolenaara6878372014-03-22 21:02:50 +01004017 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004018 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004019" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004020
4021 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004022 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004023" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004024
Bram Moolenaar446cb832008-06-24 21:56:24 +00004025 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004026" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004027 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004028" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004029 endif
4030 else
4031 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4033 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004034 let fname= substitute(a:fname,".$","","")
4035 else
4036 let fname= a:fname
4037 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004038 let t = getftime(s:NetrwFile(fname))
4039 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004040 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004041 let sz= s:NetrwHumanReadable(sz)
4042 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004043 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4044" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004045 endif
4046 else
4047 echo "sorry, \"qf\" not supported yet for remote files"
4048 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004049 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004050" call Dret("s:NetrwFileInfo")
4051endfun
4052
4053" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004054" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4055fun! s:NetrwFullPath(filename)
4056" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4057 let filename= a:filename
4058 if filename !~ '^/'
4059 let filename= resolve(getcwd().'/'.filename)
4060 endif
4061 if filename != "/" && filename =~ '/$'
4062 let filename= substitute(filename,'/$','','')
4063 endif
4064" " call Dret("s:NetrwFullPath <".filename.">")
4065 return filename
4066endfun
4067
4068" ---------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004069" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004070" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004071" 1=re-used buffer (buffer not cleared)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004072fun! s:NetrwGetBuffer(islocal,dirname)
4073" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004074" 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 Moolenaarb0d45e72017-11-05 18:19:24 +01004075" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004076 let dirname= a:dirname
4077
4078 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004079" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004080 if !exists("s:netrwbuf")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004081" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004082 let s:netrwbuf= {}
4083 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004084" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4085" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4086
4087 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4088 let bufnum = -1
4089
4090 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4091 if has_key(s:netrwbuf,"NetrwTreeListing")
4092 let bufnum= s:netrwbuf["NetrwTreeListing"]
4093 else
4094 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4095 endif
4096" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4097 if !bufexists(bufnum)
4098 call remove(s:netrwbuf,"NetrwTreeListing"])
4099 let bufnum= -1
4100 endif
4101 elseif bufnr("NetrwTreeListing") != -1
4102 let bufnum= bufnr("NetrwTreeListing")
4103" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4104 else
4105" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4106 let bufnum= -1
4107 endif
4108
4109 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004110 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004111" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004112 if !bufexists(bufnum)
4113 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4114 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004115 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004116
Bram Moolenaar446cb832008-06-24 21:56:24 +00004117 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004118" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004119 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004120 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004121" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004122
4123 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004124 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004125" 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 +00004126 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004127" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004128 " name the buffer
4129 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4130 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004131" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004132 let w:netrw_treebufnr = bufnr("%")
4133 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004134 if g:netrw_use_noswf
4135 setl nobl bt=nofile noswf
4136 else
4137 setl nobl bt=nofile
4138 endif
4139 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4140 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4141 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4142 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004143" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004144 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004145 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004146 " enter the new buffer into the s:netrwbuf dictionary
4147 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4148" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4149" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004150 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004151" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004152
4153 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004154" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004155 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004156 setl ei=all
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004157 if getline(2) =~# '^" Netrw Directory Listing'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158" call Decho(" getline(2)<".getline(2).'> matches "Netrw Directory Listing" : using keepalt b '.bufnum,'~'.expand("<slnum>"))
4159 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004160 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho(" getline(2)<".getline(2).'> does not match "Netrw Directory Listing" : using b '.bufnum,'~'.expand("<slnum>"))
4162 exe "sil! NetrwKeepj noswapfile keepalt b ".bufnum
Bram Moolenaar446cb832008-06-24 21:56:24 +00004163 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004165 if bufname("%") == '.'
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004166 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004167 endif
4168 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004169
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170 if line("$") <= 1 && getline(1) == ""
4171 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004172 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173" 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>"))
4174" 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 +01004175" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4176 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004177
Bram Moolenaar97d62492012-11-15 21:28:22 +01004178 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004179" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004180 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004181 sil NetrwKeepj %d _
4182" 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>"))
4183" 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 +01004184" 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 +00004185 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004186
Bram Moolenaar446cb832008-06-24 21:56:24 +00004187 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004188" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4189" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004190 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004191 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004192 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004193" 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>"))
4194" 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 +01004195" 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 +00004196 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004197
Bram Moolenaar446cb832008-06-24 21:56:24 +00004198 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004199" 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>"))
4200" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4201" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004202 return 1
4203 endif
4204 endif
4205
4206 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4207 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4208 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4209 " med 1 D H
4210 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004211" 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 +00004212 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004213 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004214 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215
4216 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004217" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4218" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4219 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004220
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004221" 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>"))
4222" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4223" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004224 return 0
4225endfun
4226
4227" ---------------------------------------------------------------------
4228" s:NetrwGetcwd: get the current directory. {{{2
4229" Change backslashes to forward slashes, if any.
4230" If doesc is true, escape certain troublesome characters
4231fun! s:NetrwGetcwd(doesc)
4232" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4233 let curdir= substitute(getcwd(),'\\','/','ge')
4234 if curdir !~ '[\/]$'
4235 let curdir= curdir.'/'
4236 endif
4237 if a:doesc
4238 let curdir= fnameescape(curdir)
4239 endif
4240" call Dret("NetrwGetcwd <".curdir.">")
4241 return curdir
4242endfun
4243
4244" ---------------------------------------------------------------------
4245" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4246fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004247" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4248" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4249 let keepsol= &l:sol
4250 setl nosol
4251
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252 call s:UseBufWinVars()
4253
4254 " insure that w:netrw_liststyle is set up
4255 if !exists("w:netrw_liststyle")
4256 if exists("g:netrw_liststyle")
4257 let w:netrw_liststyle= g:netrw_liststyle
4258 else
4259 let w:netrw_liststyle= s:THINLIST
4260 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004261" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262 endif
4263
4264 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4265 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004266" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004267 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004268 let dirname= "./"
4269 let curline= getline('.')
4270
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004271 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004272 NetrwKeepj norm s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004273 let s:netrw_skipbrowse= 1
4274 echo 'Pressing "s" also works'
4275
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004276 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004277 let s:netrw_skipbrowse= 1
4278 echo 'Press "S" to edit sorting sequence'
4279
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004280 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004281 NetrwKeepj norm ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004282 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004283
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004284 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004285 NetrwKeepj norm a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004286 let s:netrw_skipbrowse= 1
4287 echo 'Pressing "a" also works'
4288
4289 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004290 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004291 endif
4292
4293 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004294" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004295 NetrwKeepj norm! 0
4296 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004297
4298 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004299" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004300 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004301 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4302
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004303 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004304" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004305 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004306 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004307
4308 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004309" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004310 let dirname= getline('.')
4311
4312 if !exists("b:netrw_cpf")
4313 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004314 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 +01004315 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004316" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317 endif
4318
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004319" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004321" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4322" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004324 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325 else
4326 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004327 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004328 endif
4329 let rega= @a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004330 let eofname= filestart + b:netrw_cpf + 1
4331 if eofname <= col("$")
4332 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004333 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004334 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004335 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004336 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337 let dirname = @a
4338 let @a = rega
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004339" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004341" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 endif
4343
4344 " symlinks are indicated by a trailing "@". Remove it before further processing.
4345 let dirname= substitute(dirname,"@$","","")
4346
4347 " executables are indicated by a trailing "*". Remove it before further processing.
4348 let dirname= substitute(dirname,"\*$","","")
4349
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004350 let &l:sol= keepsol
4351
Bram Moolenaar446cb832008-06-24 21:56:24 +00004352" call Dret("s:NetrwGetWord <".dirname.">")
4353 return dirname
4354endfun
4355
4356" ---------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004357" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4358" g:netrw_bufsettings will be used after the listing is produced.
4359" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004360fun! s:NetrwListSettings(islocal)
4361" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004363 let fname= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004364" " call Decho("(NetrwListSettings) setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004365 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4366 setl bt=nofile nobl ma nonu nowrap noro nornu
4367 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004368 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004369 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004370 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004371" call Dredir("ls!","s:NetrwListSettings")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004372" call Decho("(NetrwListSettings) exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004373 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004374 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004375 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004376 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004377 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004378 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004379 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004380" 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 +00004381" call Dret("s:NetrwListSettings")
4382endfun
4383
4384" ---------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004385" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004386" islocal=0: remote browsing
4387" =1: local browsing
4388fun! s:NetrwListStyle(islocal)
4389" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004390
Bram Moolenaar97d62492012-11-15 21:28:22 +01004391 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392 let fname = s:NetrwGetWord()
4393 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004394 let svpos = winsaveview()
4395" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004396 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004397" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4398" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4399" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004400
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004401 " repoint t:netrw_lexbufnr if appropriate
4402 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4403" call Decho("set repointlexbufnr to true!")
4404 let repointlexbufnr= 1
4405 endif
4406
Bram Moolenaar446cb832008-06-24 21:56:24 +00004407 if w:netrw_liststyle == s:THINLIST
4408 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004409" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004410 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4411
4412 elseif w:netrw_liststyle == s:LONGLIST
4413 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004414" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004415 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4416
4417 elseif w:netrw_liststyle == s:WIDELIST
4418 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004419" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004420 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4421
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004422 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004423" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004424 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4425
4426 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004427 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004428 let g:netrw_liststyle = s:THINLIST
4429 let w:netrw_liststyle = g:netrw_liststyle
4430 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4431 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004432 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004433" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004434
4435 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004436" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4437 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004438 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004439" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004440 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004441" 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 +00004442
4443 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004444" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004445 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4446 NetrwKeepj call s:NetrwCursor()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004448 " repoint t:netrw_lexbufnr if appropriate
4449 if exists("repointlexbufnr")
4450 let t:netrw_lexbufnr= bufnr("%")
4451" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4452 endif
4453
Bram Moolenaar13600302014-05-22 18:26:40 +02004454 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004455" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4456 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004457 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004458
4459" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4460endfun
4461
4462" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004463" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4464fun! s:NetrwBannerCtrl(islocal)
4465" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4466
Bram Moolenaar97d62492012-11-15 21:28:22 +01004467 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004468 " toggle the banner (enable/suppress)
4469 let g:netrw_banner= !g:netrw_banner
4470
4471 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004472 let svpos= winsaveview()
4473" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004474 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4475
4476 " keep cursor on the filename
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004477 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4478 let fname= s:NetrwGetWord()
4479 sil NetrwKeepj $
4480 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4481" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4482 if result <= 0 && exists("w:netrw_bannercnt")
4483 exe "NetrwKeepj ".w:netrw_bannercnt
4484 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004485 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004486 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004487" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4488endfun
4489
4490" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004491" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4492"
4493" No bang: enters files/directories into Netrw's bookmark system
4494" No argument and in netrw buffer:
4495" if there are marked files: bookmark marked files
4496" otherwise : bookmark file/directory under cursor
4497" No argument and not in netrw buffer: bookmarks current open file
4498" Has arguments: globs them individually and bookmarks them
4499"
4500" With bang: deletes files/directories from Netrw's bookmark system
4501fun! s:NetrwBookmark(del,...)
4502" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4503 if a:0 == 0
4504 if &ft == "netrw"
4505 let curbufnr = bufnr("%")
4506
4507 if exists("s:netrwmarkfilelist_{curbufnr}")
4508 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004509" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004510 let svpos = winsaveview()
4511" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004513 for fname in s:netrwmarkfilelist_{curbufnr}
4514 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4515 endfor
4516 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4517 call s:NetrwUnmarkList(curbufnr,curdir)
4518 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004519" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4520 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004521 else
4522 let fname= s:NetrwGetWord()
4523 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4524 endif
4525
4526 else
4527 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004528" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004529 let fname= expand("%")
4530 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4531 endif
4532
4533 else
4534 " bookmark specified files
4535 " attempts to infer if working remote or local
4536 " by deciding if the current file begins with an url
4537 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004538 let islocal= expand("%") !~ '^\a\{3,}://'
4539" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004540 let i = 1
4541 while i <= a:0
4542 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004543 if v:version > 704 || (v:version == 704 && has("patch656"))
4544 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004545 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004546 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004547 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004548 else
4549 let mbfiles= [a:{i}]
4550 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004551" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004552 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004553" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004554 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4555 endfor
4556 let i= i + 1
4557 endwhile
4558 endif
4559
4560 " update the menu
4561 call s:NetrwBookmarkMenu()
4562
4563" call Dret("s:NetrwBookmark")
4564endfun
4565
4566" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004567" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4568" .2.[cnt] for bookmarks, and
4569" .3.[cnt] for history
4570" (see s:NetrwMenu())
4571fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004572 if !exists("s:netrw_menucnt")
4573 return
4574 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004575" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhist_cnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576
4577 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004578 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004579 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004580" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004581 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4582 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004583 endif
4584 if !exists("s:netrw_initbookhist")
4585 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004586 endif
4587
4588 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004589 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004590 let cnt= 1
4591 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004592" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004593 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004594
4595 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004596 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004597
4598 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004599 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 +01004600 let cnt= cnt + 1
4601 endfor
4602
4603 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004604
4605 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004606 if g:netrw_dirhistmax > 0
4607 let cnt = g:netrw_dirhist_cnt
4608 let first = 1
4609 let histcnt = 0
4610 while ( first || cnt != g:netrw_dirhist_cnt )
4611 let histcnt = histcnt + 1
4612 let priority = g:netrw_dirhist_cnt + histcnt
4613 if exists("g:netrw_dirhist_{cnt}")
4614 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004616 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4617 endif
4618 let first = 0
4619 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4620 if cnt < 0
4621 let cnt= cnt + g:netrw_dirhistmax
4622 endif
4623 endwhile
4624 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004625
Bram Moolenaar9964e462007-05-05 17:54:07 +00004626 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004627" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004628endfun
4629
4630" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004631" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4632" directory and a new directory name. Also, if the
4633" "new directory name" is actually a file,
4634" NetrwBrowseChgDir() edits the file.
4635fun! s:NetrwBrowseChgDir(islocal,newdir,...)
4636" 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 +01004637" 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 +00004638
Bram Moolenaar97d62492012-11-15 21:28:22 +01004639 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004640 if !exists("b:netrw_curdir")
4641 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4642 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004643 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004644" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4645" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004646" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004647" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004648 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004649 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004650" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004651
Bram Moolenaar97d62492012-11-15 21:28:22 +01004652 " NetrwBrowseChgDir: save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004653" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01004654 call s:SavePosn(s:netrw_posn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004655 NetrwKeepj call s:NetrwOptionSave("s:")
4656 NetrwKeepj call s:NetrwSafeOptions()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004657 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004658 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004659 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004660 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004661 endif
4662 let newdir = a:newdir
4663 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004664 let dorestore = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004665" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004666
4667 " ignore <cr>s when done in the banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004668" call Decho('ignore [return]s when done in banner (g:netrw_banner='.g:netrw_banner.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004669 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004670" 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 +01004671 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004672 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004673" 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 +01004674 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004675" 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 +02004676 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004677 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004678 setl noma nomod nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004679 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004680" 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 +01004681 endif
4682 endif
4683" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004684" call Decho("(s:NetrwBrowseChgdir) g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004685 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004686
Bram Moolenaar446cb832008-06-24 21:56:24 +00004687 " set up o/s-dependent directory recognition pattern
4688 if has("amiga")
4689 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004690 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004691 let dirpat= '[\/]$'
4692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004693" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004694
4695 if dirname !~ dirpat
4696 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004697 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004698 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004699" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004700 endif
4701
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004702" 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 +01004703 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004704 " ------------------------------
4705 " NetrwBrowseChgDir: edit a file {{{3
4706 " ------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004707" call Decho('edit-a-file: case "handling a file": newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004708
Bram Moolenaar97d62492012-11-15 21:28:22 +01004709 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004710 let s:rexposn_{bufnr("%")}= winsaveview()
4711" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004712" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4713" 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 +01004714
Bram Moolenaar446cb832008-06-24 21:56:24 +00004715 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004716" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4717" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004718 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004719 if dirname =~ '/$'
4720 let dirname= dirname.newdir
4721 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004722 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004723 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004724" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4725" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004726 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004727" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004728 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004729 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004730 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004731 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004732" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004733 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004734 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004735" 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 Moolenaar8feef4f2015-01-07 16:57:10 +01004736 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004737 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004738 if !exists("s:didsplit")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004739" 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 +01004740 if type(g:netrw_browse_split) == 3
4741 " open file in server
4742 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004743" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004744 call s:NetrwServerEdit(a:islocal,dirname)
4745" call Dret("s:NetrwBrowseChgDir")
4746 return
4747 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004748 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004749" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004750 keepalt new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004751 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004752 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004753 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004754 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004755 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004756 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004757" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004758 keepalt rightb vert new
Bram Moolenaar5c736222010-01-06 20:54:52 +01004759 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004760 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004761 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004762 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004763 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004764 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004765" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004766 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004767 if !exists("b:netrw_curdir")
4768 let b:netrw_curdir= getcwd()
4769 endif
4770 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004771 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004772 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004773" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004774 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004775 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004776" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004777 return
4778 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004779 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004780 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004781 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004782" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004783 call s:NetrwMenu(0)
4784 " optional change to window
4785 if g:netrw_chgwin >= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004786" call Decho("edit-a-file: changing window to #".g:netrw_chgwin,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004787 if winnr("$")+1 == g:netrw_chgwin
4788 " if g:netrw_chgwin is set to one more than the last window, then
4789 " vertically split the last window to make that window available.
4790 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004791 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
Bram Moolenaar13600302014-05-22 18:26:40 +02004792 vs
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004793 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004794 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004795 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004796 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004797 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004798 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004799 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004800
Bram Moolenaar446cb832008-06-24 21:56:24 +00004801 " the point where netrw actually edits the (local) file
4802 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar8d043172014-01-23 14:24:41 +01004803 " no keepalt to support :e # to return to a directory listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004804 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004805" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004806 " some like c-^ to return to the last edited file
4807 " others like c-^ to return to the netrw buffer
4808 if exists("g:netrw_altfile") && g:netrw_altfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004809 exe "NetrwKeepj keepalt e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004810 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004811 exe "NetrwKeepj e! ".fnameescape(dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004812 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004813" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004814 call s:NetrwCursor()
Bram Moolenaar13600302014-05-22 18:26:40 +02004815 if &hidden || &bufhidden == "hide"
4816 " file came from vim's hidden storage. Don't "restore" options with it.
4817 let dorestore= 0
4818 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004819 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004820" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00004821 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004822 let dolockout= 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01004823
4824 " handle g:Netrw_funcref -- call external-to-netrw functions
4825 " This code will handle g:Netrw_funcref as an individual function reference
4826 " or as a list of function references. It will ignore anything that's not
4827 " a function reference. See :help Funcref for information about function references.
4828 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004829" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004830 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004831" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004832 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004833 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004834" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004835 for Fncref in g:Netrw_funcref
4836 if type(FncRef) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004837 NetrwKeepj call FncRef()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004838 endif
4839 endfor
4840 endif
4841 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004842 endif
4843
4844 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004845 " ----------------------------------------------------
4846 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4847 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004848" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004849 let dirname = newdir
4850 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
4851 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004852 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004853
4854 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004855 " ---------------------------------------------
4856 " NetrwBrowseChgDir: refresh the directory list {{{3
4857 " ---------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004858" call Decho('refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004859 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004860 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861
4862 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004863 " --------------------------------------
4864 " NetrwBrowseChgDir: go up one directory {{{3
4865 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866" call Decho('go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867
4868 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4869 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004870" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4871" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004872 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004873 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874 endif
4875
4876 if has("amiga")
4877 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004878" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004879 if a:islocal
4880 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4881 let dirname= substitute(dirname,'/$','','')
4882 else
4883 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4884 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004885" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004886
Bram Moolenaar8d043172014-01-23 14:24:41 +01004887 elseif !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
4888 " windows
4889 if a:islocal
4890 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4891 if dirname == ""
4892 let dirname= '/'
4893 endif
4894 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004895 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004896 endif
4897 if dirname =~ '^\a:$'
4898 let dirname= dirname.'/'
4899 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004900" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004901
Bram Moolenaar446cb832008-06-24 21:56:24 +00004902 else
4903 " unix or cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004904" call Decho('go-up: case "go up one directory": newdir == "../" and unix or cygwin','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004905 if a:islocal
4906 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4907 if dirname == ""
4908 let dirname= '/'
4909 endif
4910 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004911 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004913" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004915 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004916 norm m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004917
4918 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004919 " --------------------------------------
4920 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4921 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004922" call Decho('tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
4923 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
4924" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004925 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004926 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004927" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
4928 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004929 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004930 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004931" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004932 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004933 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004934" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004935
4936 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004937" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004938 if has_key(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004939" call Decho('tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004940 let haskey= 1
4941 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004942" call Decho('tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004943 endif
4944
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004945 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004946" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004947 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004948 if has_key(w:netrw_treedict,treedir."/")
4949 let treedir= treedir."/"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004950" call Decho('tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004951 let haskey = 1
4952 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004953" call Decho('tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004954 endif
4955 endif
4956
4957 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004958" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004959 if !haskey && treedir =~ '/$'
4960 let treedir= substitute(treedir,'/$','','')
4961 if has_key(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004962" call Decho('tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963 let haskey = 1
4964 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004965" call Decho('tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004966 endif
4967 endif
4968
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004969" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004970 if haskey
4971 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004972" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004973 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004974" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
4975" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004976 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004977 else
4978 " go down one directory
4979 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004980" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
4981" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004982 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004983 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004984" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004985 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004986
4987 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004988 " ----------------------------------------
4989 " NetrwBrowseChgDir: Go down one directory {{{3
4990 " ----------------------------------------
4991 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004992" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004993 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004994 norm m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004995 endif
4996
Bram Moolenaar97d62492012-11-15 21:28:22 +01004997 " --------------------------------------
4998 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4999 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005000 if dorestore
5001 " dorestore is zero'd when a local file was hidden or bufhidden;
5002 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005003" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005004 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005005" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005006" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005007 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005008 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005009" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005010 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005011" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5012" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005013 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005014" 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 +02005015 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005016" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5017" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005018 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005019" 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 +02005020 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005021 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005022 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005023 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005024
Bram Moolenaar446cb832008-06-24 21:56:24 +00005025" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5026 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005027endfun
5028
5029" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005030" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5031" for thin, long, and wide: cursor placed just after banner
5032" for tree, keeps cursor on current filename
5033fun! s:NetrwBrowseUpDir(islocal)
5034" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005035 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5036 " this test needed because occasionally this function seems to be incorrectly called
5037 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005038 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005039 " directories.
5040" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5041 return
5042 endif
5043
Bram Moolenaara6878372014-03-22 21:02:50 +01005044 norm! 0
5045 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005046" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005047 let curline= getline(".")
5048 let swwline= winline() - 1
5049 if exists("w:netrw_treetop")
5050 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005051 elseif exists("b:netrw_curdir")
5052 let w:netrw_treetop= b:netrw_curdir
5053 else
5054 let w:netrw_treetop= getcwd()
5055 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005056 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005057 let curfile = getline(".")
5058 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005059 if a:islocal
5060 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5061 else
5062 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5063 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005064" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5065" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5066 if w:netrw_treetop == '/'
5067 keepj call search('^\M'.curfile,"w")
5068 elseif curfile == '../'
5069 keepj call search('^\M'.curfile,"wb")
5070 else
5071" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5072 while 1
5073 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5074 let treepath= s:NetrwTreePath(w:netrw_treetop)
5075" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5076 if treepath == curpath
5077 break
5078 endif
5079 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005080 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005081
Bram Moolenaara6878372014-03-22 21:02:50 +01005082 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005083" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005084 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005085 if exists("b:netrw_curdir")
5086 let curdir= b:netrw_curdir
5087 else
5088 let curdir= expand(getcwd())
5089 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005090 if a:islocal
5091 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5092 else
5093 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5094 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005095 call s:RestorePosn(s:netrw_posn)
5096 let curdir= substitute(curdir,'^.*[\/]','','')
5097 call search('\<'.curdir.'/','wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005098 endif
5099" call Dret("s:NetrwBrowseUpDir")
5100endfun
5101
5102" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005103" netrw#BrowseX: (implements "x") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005104" given filename; typically this means given their extension.
5105" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005106fun! netrw#BrowseX(fname,remote)
5107" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.")")
5108
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005109 " if its really just a local directory, then do a "gf" instead
5110 if (a:remote == 0 && isdirectory(a:fname)) || (a:remote == 1 && a:fname =~ '/$' && a:fname !~ '^https\=:')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005111 norm! gf
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005112" call Dret("(netrw#BrowseX) did gf instead")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005113 endif
5114
Bram Moolenaar97d62492012-11-15 21:28:22 +01005115 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005116 let screenposn = winsaveview()
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005117" call Decho("(netrw#BrowseX) saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005118
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005119 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5120 let awkeep = &aw
5121 set noaw
5122
Bram Moolenaar5c736222010-01-06 20:54:52 +01005123 " special core dump handler
5124 if a:fname =~ '/core\(\.\d\+\)\=$'
5125 if exists("g:Netrw_corehandler")
5126 if type(g:Netrw_corehandler) == 2
5127 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005128" call Decho("(netrw#BrowseX) g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005129 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005130 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005131 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005132" call Decho("(netrw#BrowseX) g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005133 for Fncref in g:Netrw_corehandler
5134 if type(FncRef) == 2
5135 call FncRef(a:fname)
5136 endif
5137 endfor
5138 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005139" call Decho("(netrw#BrowseX) restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005140 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005141 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005142 let &aw= awkeep
5143" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005144 return
5145 endif
5146 endif
5147
Bram Moolenaar446cb832008-06-24 21:56:24 +00005148 " set up the filename
5149 " (lower case the extension, make a local copy of a remote file)
5150 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
5151 if has("win32") || has("win95") || has("win64") || has("win16")
5152 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005153 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005154 if exten =~ "[\\/]"
5155 let exten= ""
5156 endif
5157" call Decho("(netrw#BrowseX) exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005158
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159 if a:remote == 1
5160 " create a local copy
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005161" call Decho("(netrw#BrowseX) remote: a:remote=".a:remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005162 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005163 call netrw#NetRead(3,a:fname)
5164 " attempt to rename tempfile
5165 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005166 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005167" call Decho("(netrw#BrowseX) basename<".basename.">",'~'.expand("<slnum>"))
5168" call Decho("(netrw#BrowseX) newname <".newname.">",'~'.expand("<slnum>"))
5169 if s:netrw_tmpfile != newname && newname != ""
5170 if rename(s:netrw_tmpfile,newname) == 0
5171 " renaming succeeded
5172" call Decho("(netrw#BrowseX) renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5173 let fname= newname
5174 else
5175 " renaming failed
5176" call Decho("(netrw#BrowseX) renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5177 let fname= s:netrw_tmpfile
5178 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005179 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005180 let fname= s:netrw_tmpfile
5181 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005182 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005183" call Decho("(netrw#BrowseX) local: a:remote=".a:remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005184 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005185 " special ~ handler for local
5186 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005187" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5188 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005189 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005190 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005191" call Decho("(netrw#BrowseX) fname<".fname.">",'~'.expand("<slnum>"))
5192" call Decho("(netrw#BrowseX) exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005193
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005194 " set up redirection (avoids browser messages)
5195 " by default, g:netrw_suppress_gx_mesg is true
5196 if g:netrw_suppress_gx_mesg
5197 if &srr =~ "%s"
5198 if (has("win32") || has("win95") || has("win64") || has("win16"))
5199 let redir= substitute(&srr,"%s","nul","")
5200 else
5201 let redir= substitute(&srr,"%s","/dev/null","")
5202 endif
5203 elseif (has("win32") || has("win95") || has("win64") || has("win16"))
5204 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005205 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005206 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005207 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005208 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005209" call Decho("(netrw#BrowseX) set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005210
5211 " extract any viewing options. Assumes that they're set apart by quotes.
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005212" call Decho("(netrw#BrowseX) extract any viewing options",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005213 if exists("g:netrw_browsex_viewer")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005214" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005215 if g:netrw_browsex_viewer =~ '\s'
5216 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5217 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5218 let oviewer = ''
5219 let cnt = 1
5220 while !executable(viewer) && viewer != oviewer
5221 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5222 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5223 let cnt = cnt + 1
5224 let oviewer = viewer
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005225" call Decho("(netrw#BrowseX) !exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005226 endwhile
5227 else
5228 let viewer = g:netrw_browsex_viewer
5229 let viewopt = ""
5230 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005231" call Decho("(netrw#BrowseX) viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005232 endif
5233
5234 " execute the file handler
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005235" call Decho("(netrw#BrowseX) execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005236 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005237" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005238 let ret= netrwFileHandlers#Invoke(exten,fname)
5239
5240 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005241" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005242 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005243 let ret= v:shell_error
5244
5245 elseif has("win32") || has("win64")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005246" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005247 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005248 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005249 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005250 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005251 else
5252 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5253 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005254 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005255 let ret= v:shell_error
5256
Bram Moolenaar97d62492012-11-15 21:28:22 +01005257 elseif has("win32unix")
5258 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005259" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005260 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005261 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005262 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005263 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005264 elseif executable("cygstart")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005265 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005266 else
5267 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5268 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005269 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005270 let ret= v:shell_error
5271
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005272 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005273" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005274 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005275 let ret= v:shell_error
5276
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005277 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005278" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005279 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir)
5280 let ret= v:shell_error
5281
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005282 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
5283" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5284 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5285 let ret= v:shell_error
5286
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005287 elseif has("unix") && executable("xdg-open")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005288" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005289 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005290 let ret= v:shell_error
5291
5292 elseif has("macunix") && executable("open")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005293" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005294 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005295 let ret= v:shell_error
5296
5297 else
5298 " netrwFileHandlers#Invoke() always returns 0
5299 let ret= netrwFileHandlers#Invoke(exten,fname)
5300 endif
5301
5302 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5303 if ret
5304 let ret= netrwFileHandlers#Invoke(exten,fname)
5305 endif
5306
Bram Moolenaarc236c162008-07-13 17:41:49 +00005307 " restoring redraw! after external file handlers
5308 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005309
5310 " cleanup: remove temporary file,
5311 " delete current buffer if success with handler,
5312 " return to prior buffer (directory listing)
5313 " Feb 12, 2008: had to de-activiate removal of
5314 " temporary file because it wasn't getting seen.
5315" if a:remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005316"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005317" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005318" endif
5319
5320 if a:remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005321 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005322 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005323 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005324 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005325 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005326" redraw!
5327 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005328" call Decho("(netrw#BrowseX) restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005329 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005330 let @@ = ykeep
5331 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005332
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005333" call Dret("netrw#BrowseX")
5334endfun
5335
5336" ---------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005337" netrw#GX: gets word under cursor for gx support {{{2
5338" See also: netrw#BrowseXVis
5339" netrw#BrowseX
5340fun! netrw#GX()
5341" call Dfunc("netrw#GX()")
5342 if &ft == "netrw"
5343 let fname= s:NetrwGetWord()
5344 else
5345 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5346 endif
5347" call Dret("netrw#GX <".fname.">")
5348 return fname
5349endfun
5350
5351" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005352" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5353fun! netrw#BrowseXVis()
5354" call Dfunc("netrw#BrowseXVis()")
5355 let atkeep = @@
5356 norm! gvy
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005357" call Decho("@@<".@@.">",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005358 call netrw#BrowseX(@@,netrw#CheckIfRemote(@@))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005359 let @@ = atkeep
5360" call Dret("netrw#BrowseXVis")
5361endfun
5362
5363" ---------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005364" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5365" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5366" to become an unlisted buffer, so in that case don't bwipe it.
5367fun! s:NetrwBufRename(newname)
5368" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5369" call Dredir("ls!","s:NetrwBufRename (before rename)")
5370 let oldbufname= bufname(bufnr("%"))
5371" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5372 if oldbufname != a:newname
5373" call Decho("do renaming (oldbufname != a:newname)",'~'.expand("<slnum>"))
5374 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
5375 let oldbufnr= bufnr(oldbufname)
5376 if oldbufname != "" && oldbufnr != -1
5377 exe "bwipe! ".oldbufnr
5378 endif
5379 endif
5380" call Dredir("ls!","s:NetrwBufRename (after rename)")
5381" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5382endfun
5383
5384" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005385" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005386fun! netrw#CheckIfRemote(...)
5387" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5388 if a:0 > 0
5389 let curfile= a:1
5390 else
5391 let curfile= expand("%")
5392 endif
5393" call Decho("curfile<".curfile.">")
5394 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005395" call Dret("netrw#CheckIfRemote 1")
5396 return 1
5397 else
5398" call Dret("netrw#CheckIfRemote 0")
5399 return 0
5400 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005401endfun
5402
5403" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005404" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5405fun! s:NetrwChgPerm(islocal,curdir)
5406" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005407 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005408 call inputsave()
5409 let newperm= input("Enter new permission: ")
5410 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005411 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5412 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5413" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005414 call system(chgperm)
5415 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005416 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005417 endif
5418 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005419 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005420 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005421 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005422" call Dret("s:NetrwChgPerm")
5423endfun
5424
5425" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005426" s:CheckIfKde: checks if kdeinit is running {{{2
5427" Returns 0: kdeinit not running
5428" 1: kdeinit is running
5429fun! s:CheckIfKde()
5430" call Dfunc("s:CheckIfKde()")
5431 " seems kde systems often have gnome-open due to dependencies, even though
5432 " gnome-open's subsidiary display tools are largely absent. Kde systems
5433 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5434 if !exists("s:haskdeinit")
5435 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005436 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005437 if v:shell_error
5438 let s:haskdeinit = 0
5439 endif
5440 else
5441 let s:haskdeinit= 0
5442 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005443" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005444 endif
5445
5446" call Dret("s:CheckIfKde ".s:haskdeinit)
5447 return s:haskdeinit
5448endfun
5449
5450" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005451" s:NetrwClearExplore: clear explore variables (if any) {{{2
5452fun! s:NetrwClearExplore()
5453" call Dfunc("s:NetrwClearExplore()")
5454 2match none
5455 if exists("s:explore_match") |unlet s:explore_match |endif
5456 if exists("s:explore_indx") |unlet s:explore_indx |endif
5457 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5458 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5459 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5460 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5461 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5462 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5463 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5464" redraw!
5465 echo " "
5466 echo " "
5467" call Dret("s:NetrwClearExplore")
5468endfun
5469
5470" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005471" s:NetrwExploreListUniq: {{{2
5472fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005473" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005474
5475 " this assumes that the list is already sorted
5476 let newexplist= []
5477 for member in a:explist
5478 if !exists("uniqmember") || member != uniqmember
5479 let uniqmember = member
5480 let newexplist = newexplist + [ member ]
5481 endif
5482 endfor
5483
Bram Moolenaar15146672011-10-20 22:22:38 +02005484" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005485 return newexplist
5486endfun
5487
5488" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005489" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5490fun! s:NetrwForceChgDir(islocal,newdir)
5491" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005492 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005493 if a:newdir !~ '/$'
5494 " ok, looks like force is needed to get directory-style treatment
5495 if a:newdir =~ '@$'
5496 let newdir= substitute(a:newdir,'@$','/','')
5497 elseif a:newdir =~ '[*=|\\]$'
5498 let newdir= substitute(a:newdir,'.$','/','')
5499 else
5500 let newdir= a:newdir.'/'
5501 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005502" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005503 else
5504 " should already be getting treatment as a directory
5505 let newdir= a:newdir
5506 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005507 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005508 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005509 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005510" call Dret("s:NetrwForceChgDir")
5511endfun
5512
5513" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005514" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005515" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5516" expr : this is the expression to follow the directory. Will use s:ComposePath()
5517" pare =1: remove the current directory from the resulting glob() filelist
5518" =0: leave the current directory in the resulting glob() filelist
5519fun! s:NetrwGlob(direntry,expr,pare)
5520" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005521 if netrw#CheckIfRemote()
5522 keepalt 1sp
5523 keepalt enew
5524 let keep_liststyle = w:netrw_liststyle
5525 let w:netrw_liststyle = s:THINLIST
5526 if s:NetrwRemoteListing() == 0
5527 keepj keepalt %s@/@@
5528 let filelist= getline(1,$)
5529 q!
5530 else
5531 " remote listing error -- leave treedict unchanged
5532 let filelist= w:netrw_treedict[a:direntry]
5533 endif
5534 let w:netrw_liststyle= keep_liststyle
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005535 elseif v:version > 704 || (v:version == 704 && has("patch656"))
5536 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1,1)
5537 if a:pare
5538 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5539 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005540 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005541 let filelist= glob(s:ComposePath(fnameescape(a:direntry),a:expr),0,1)
5542 if a:pare
5543 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5544 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005545 endif
5546" call Dret("s:NetrwGlob ".string(filelist))
5547 return filelist
5548endfun
5549
5550" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005551" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5552fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005553" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005554 if a:newfile =~ '[/@*=|\\]$'
5555 let newfile= substitute(a:newfile,'.$','','')
5556 else
5557 let newfile= a:newfile
5558 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005559 if a:islocal
5560 call s:NetrwBrowseChgDir(a:islocal,newfile)
5561 else
5562 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5563 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005564" call Dret("s:NetrwForceFile")
5565endfun
5566
5567" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005568" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5569" and switches the hiding mode. The actual hiding is done by
5570" s:NetrwListHide().
5571" g:netrw_hide= 0: show all
5572" 1: show not-hidden files
5573" 2: show hidden files only
5574fun! s:NetrwHide(islocal)
5575" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005576 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005577 let svpos= winsaveview()
5578" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005579
5580 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005581" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5582" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005583
5584 " hide the files in the markfile list
5585 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005586" 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 +00005587 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5588 " remove fname from hiding list
5589 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5590 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5591 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005592" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005593 else
5594 " append fname to hiding list
5595 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5596 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5597 else
5598 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5599 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005600" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005601 endif
5602 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005603 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005604 let g:netrw_hide= 1
5605
5606 else
5607
5608 " switch between show-all/show-not-hidden/show-hidden
5609 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005610 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005611 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005612 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005613 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005614" call Dret("NetrwHide")
5615 return
5616 endif
5617 endif
5618
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005619 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005620" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5621 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005622 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005623" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005624endfun
5625
5626" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005627" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5628fun! s:NetrwHideEdit(islocal)
5629" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5630
5631 let ykeep= @@
5632 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005633 let svpos= winsaveview()
5634" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005635
5636 " get new hiding list from user
5637 call inputsave()
5638 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5639 call inputrestore()
5640 let g:netrw_list_hide= newhide
5641" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5642
5643 " refresh the listing
5644 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5645
5646 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005647" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5648 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005649 let @@= ykeep
5650
5651" call Dret("NetrwHideEdit")
5652endfun
5653
5654" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005655" s:NetrwHidden: invoked by "gh" {{{2
5656fun! s:NetrwHidden(islocal)
5657" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005658 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005659 " save current position
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005660 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005661" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005662
5663 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005664 " remove .file pattern from hiding list
5665" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005666 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005667 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005668" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005669 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5670 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005671" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005672 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5673 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005674 if g:netrw_list_hide =~ '^,'
5675 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5676 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005677
5678 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005679 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005680" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5681 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005682 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005683" call Dret("s:NetrwHidden")
5684endfun
5685
5686" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005687" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5688fun! s:NetrwHome()
5689 if exists("g:netrw_home")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005690 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005691 else
5692 " go to vim plugin home
5693 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005694 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005695 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005696 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005697 let home= basehome."/.vim"
5698 break
5699 endif
5700 endfor
5701 if home == ""
5702 " just pick the first directory
5703 let home= substitute(&rtp,',.*$','','')
5704 endif
5705 if (has("win32") || has("win95") || has("win64") || has("win16"))
5706 let home= substitute(home,'/','\\','g')
5707 endif
5708 endif
5709 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005710 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005711" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005712 if exists("g:netrw_mkdir")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005713" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005714 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005715 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005716" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005717 call mkdir(home)
5718 endif
5719 endif
5720 let g:netrw_home= home
5721 return home
5722endfun
5723
5724" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005725" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5726fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005727 if exists("s:netrwdrag")
5728 return
5729 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005730 if &ft != "netrw"
5731 return
5732 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005733" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005734
Bram Moolenaar97d62492012-11-15 21:28:22 +01005735 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005736 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005737 while getchar(0) != 0
5738 "clear the input stream
5739 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005740 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005741 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005742 let mouse_lnum = v:mouse_lnum
5743 let wlastline = line('w$')
5744 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005745" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
5746" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005747 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5748 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005749 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005750" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
5751 return
5752 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005753 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005754 " 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 +01005755 " without this test when its disabled.
5756 " 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 +01005757" 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 +01005758 if v:mouse_col > virtcol('.')
5759 let @@= ykeep
5760" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
5761 return
5762 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005763
Bram Moolenaar446cb832008-06-24 21:56:24 +00005764 if a:islocal
5765 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005766 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005767 endif
5768 else
5769 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005770 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005771 endif
5772 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005773 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005774" call Dret("s:NetrwLeftmouse")
5775endfun
5776
5777" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005778" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5779fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005780 if &ft != "netrw"
5781 return
5782 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005783" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
5784 call s:NetrwMarkFileTgt(a:islocal)
5785" call Dret("s:NetrwCLeftmouse")
5786endfun
5787
5788" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005789" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5790" a:islocal=0 : <c-r> not used, remote
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005791" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005792" a:islocal=2 : <c-r> used, remote
5793" a:islocal=3 : <c-r> used, local
5794fun! s:NetrwServerEdit(islocal,fname)
5795" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5796 let islocal = a:islocal%2 " =0: remote =1: local
5797 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005798" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005799
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005800 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005801 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005802 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005803" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005804 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005805 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005806 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5807 unlet s:netrw_browse_split_{winnr()}
5808 endif
5809 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5810" call Dret("s:NetrwServerEdit")
5811 return
5812 endif
5813
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005814" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005815 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005816" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005817
5818 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005819" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005820 let srvrname = g:netrw_browse_split[0]
5821 let tabnum = g:netrw_browse_split[1]
5822 let winnum = g:netrw_browse_split[2]
5823
5824 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005825" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005826
5827 if !ctrlr
5828 " user must have closed the server window and the user did not use <c-r>, but
5829 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005830" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005831 if exists("g:netrw_browse_split")
5832 unlet g:netrw_browse_split
5833 endif
5834 let g:netrw_browse_split= 0
5835 if exists("s:netrw_browse_split_".winnr())
5836 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5837 endif
5838 call s:NetrwBrowseChgDir(islocal,a:fname)
5839" call Dret("s:NetrwServerEdit")
5840 return
5841
5842 elseif has("win32") && executable("start")
5843 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005844" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005845 call system("start gvim --servername ".srvrname)
5846
5847 else
5848 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005849" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005850 call system("gvim --servername ".srvrname)
5851 endif
5852 endif
5853
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005854" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005855 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5856 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005857 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005858
5859 else
5860
5861 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5862
5863 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005864" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005865 if exists("g:netrw_browse_split")
5866 unlet g:netrw_browse_split
5867 endif
5868 let g:netrw_browse_split= 0
5869 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
5870" call Dret("s:NetrwServerEdit")
5871 return
5872
5873 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005874" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005875 if has("win32") && executable("start")
5876 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005877" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005878 call system("start gvim --servername ".g:netrw_servername)
5879 else
5880 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005881" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005882 call system("gvim --servername ".g:netrw_servername)
5883 endif
5884 endif
5885 endif
5886
5887 while 1
5888 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005889" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
5890 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005891 break
5892 catch /^Vim\%((\a\+)\)\=:E241/
5893 sleep 200m
5894 endtry
5895 endwhile
5896
5897 if exists("g:netrw_browse_split")
5898 if type(g:netrw_browse_split) != 3
5899 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5900 endif
5901 unlet g:netrw_browse_split
5902 endif
5903 let g:netrw_browse_split= [g:netrw_servername,1,1]
5904 endif
5905
5906 else
5907 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5908 endif
5909
5910" call Dret("s:NetrwServerEdit")
5911endfun
5912
5913" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005914" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5915fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005916 if &ft != "netrw"
5917 return
5918 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005919" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005920
Bram Moolenaar8d043172014-01-23 14:24:41 +01005921 let s:ngw= s:NetrwGetWord()
5922 call s:NetrwMarkFile(a:islocal,s:ngw)
5923
5924" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005925endfun
5926
5927" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005928" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5929" Used to mark multiple files.
5930fun! s:NetrwSLeftdrag(islocal)
5931" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5932 if !exists("s:netrwdrag")
5933 let s:netrwdrag = winnr()
5934 if a:islocal
5935 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005936 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005937 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005938 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005939 endif
5940 let ngw = s:NetrwGetWord()
5941 if !exists("s:ngw") || s:ngw != ngw
5942 call s:NetrwMarkFile(a:islocal,ngw)
5943 endif
5944 let s:ngw= ngw
5945" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5946endfun
5947
5948" ---------------------------------------------------------------------
5949" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5950fun! s:NetrwSLeftrelease(islocal)
5951" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5952 if exists("s:netrwdrag")
5953 nunmap <s-leftrelease>
5954 let ngw = s:NetrwGetWord()
5955 if !exists("s:ngw") || s:ngw != ngw
5956 call s:NetrwMarkFile(a:islocal,ngw)
5957 endif
5958 if exists("s:ngw")
5959 unlet s:ngw
5960 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005961 unlet s:netrwdrag
5962 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005963" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005964endfun
5965
5966" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967" s:NetrwListHide: uses [range]g~...~d to delete files that match comma {{{2
5968" separated patterns given in g:netrw_list_hide
5969fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005970" call Dfunc("s:NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005971" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005972 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005973
5974 " find a character not in the "hide" string to use as a separator for :g and :v commands
5975 " How-it-works: take the hiding command, convert it into a range. Duplicate
5976 " characters don't matter. Remove all such characters from the '/~...90'
5977 " string. Use the first character left as a separator character.
5978 let listhide= g:netrw_list_hide
5979 let sep = strpart(substitute('/~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005980" call Decho("sep=".sep,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005981
5982 while listhide != ""
5983 if listhide =~ ','
5984 let hide = substitute(listhide,',.*$','','e')
5985 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5986 else
5987 let hide = listhide
5988 let listhide = ""
5989 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005990" call Decho("hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005991
5992 " Prune the list by hiding any files which match
5993 if g:netrw_hide == 1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005994" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005995 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005996 elseif g:netrw_hide == 2
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01005997" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005998 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005999 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006000" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006001 endwhile
6002 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006003 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006004" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006005 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006006" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006007 endif
6008
Bram Moolenaaradc21822011-04-01 18:03:16 +02006009 " remove any blank lines that have somehow remained.
6010 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006011 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006012
Bram Moolenaar97d62492012-11-15 21:28:22 +01006013 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006014" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006015endfun
6016
6017" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006018" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006019" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006020fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006021" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006022
Bram Moolenaar97d62492012-11-15 21:28:22 +01006023 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006024 " get name of new directory from user. A bare <CR> will skip.
6025 " if its currently a directory, also request will be skipped, but with
6026 " a message.
6027 call inputsave()
6028 let newdirname= input("Please give directory name: ")
6029 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006030" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006031
6032 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006033 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006034" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006035 return
6036 endif
6037
6038 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006039" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006040
6041 " Local mkdir:
6042 " sanity checks
6043 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006044" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6045 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006046 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006047 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006048 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006049 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006050" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006051 return
6052 endif
6053 if s:FileReadable(fullnewdir)
6054 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006055 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006056 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006057 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006058" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006059 return
6060 endif
6061
6062 " requested new local directory is neither a pre-existing file or
6063 " directory, so make it!
6064 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006065 if has("unix")
6066 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6067 else
6068 call mkdir(fullnewdir,"p")
6069 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006070 else
6071 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006072 if s:NetrwLcd(b:netrw_curdir)
6073" call Dret("s:NetrwMakeDir : lcd failure")
6074 return
6075 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006076" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006077 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006078 if v:shell_error != 0
6079 let @@= ykeep
6080 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 +01006081" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006082 return
6083 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006084 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006085" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006086 if s:NetrwLcd(netrw_origdir)
6087" call Dret("s:NetrwBrowse : lcd failure")
6088 return
6089 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006090 endif
6091 endif
6092
6093 if v:shell_error == 0
6094 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006095" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006096 let svpos= winsaveview()
6097" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006098 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006099" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6100 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006101 elseif !exists("g:netrw_quiet")
6102 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6103 endif
6104" redraw!
6105
6106 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006107 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006108" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006109 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6110 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006111 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006112 if v:shell_error == 0
6113 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006114 let svpos= winsaveview()
6115" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006116 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006117" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6118 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006119 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006120 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006121 endif
6122" redraw!
6123
6124 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006125 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006126 let svpos= winsaveview()
6127" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006129 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006130" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006131 let remotepath= b:netrw_fname
6132 else
6133 let remotepath= ""
6134 endif
6135 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006136 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006137" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6138 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006139
Bram Moolenaar446cb832008-06-24 21:56:24 +00006140 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006141 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006142 let svpos= winsaveview()
6143" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006144" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006145 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006146" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006147 let remotepath= b:netrw_fname
6148 else
6149 let remotepath= ""
6150 endif
6151 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006152 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006153" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6154 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006155 endif
6156
Bram Moolenaar97d62492012-11-15 21:28:22 +01006157 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006158" call Dret("s:NetrwMakeDir")
6159endfun
6160
6161" ---------------------------------------------------------------------
6162" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6163fun! s:TreeSqueezeDir(islocal)
6164" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6165 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6166 " its a tree-listing style
6167 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006168 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006169 let depth = strchars(substitute(curdepth,' ','','g'))
6170 let srch = -1
6171" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6172" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006173" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006174" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6175 if depth >= 2
6176 NetrwKeepj norm! 0
6177 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6178 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6179" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6180" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6181 elseif depth == 1
6182 NetrwKeepj norm! 0
6183 let treedepthchr= substitute(s:treedepthstring,' ','','')
6184 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6185" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6186 endif
6187 if srch > 0
6188" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6189 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6190 exe srch
6191 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006192 endif
6193" call Dret("s:TreeSqueezeDir")
6194endfun
6195
6196" ---------------------------------------------------------------------
6197" s:NetrwMaps: {{{2
6198fun! s:NetrwMaps(islocal)
6199" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6200
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006201 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006202 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006203" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006204 if !hasmapto("<Plug>NetrwReturn")
6205 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006206" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006207 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6208 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006209" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006210 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6211 endif
6212 endif
6213 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006214" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006215 endif
6216
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006217 " generate default <Plug> maps {{{3
6218 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
6219 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir |endif
6220 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6221 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6222 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6223 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6224 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6225 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6226 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6227 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6228 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6229 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6230" ---------------------------------------------------------------------
6231" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6232" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6233" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6234" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6235" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6236" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6237" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6238" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6239" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6240" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6241" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6242" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6243" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6244" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6245" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6246" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6247" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6248" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6249" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6250" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6251" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6252" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6253" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6254" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6255" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6256" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6257" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6258" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6259" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6260" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6261" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6262" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6263" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6264" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6265" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6266" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6267" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6268" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6269" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6270" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6271" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6272" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6273" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6274" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6275" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6276" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6277" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6278
Bram Moolenaara6878372014-03-22 21:02:50 +01006279 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006280" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006281 " local normal-mode maps {{{3
6282 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6283 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6284 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6285 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6286 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6287 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6288 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6289 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6290 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6291 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6292 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6293" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006294 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6295 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6296 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006297 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006298 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006299 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6300 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6301 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6302 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006303 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6304 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6305 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6306 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6307 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6308 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6309 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6310 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6311 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6312 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6313 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6314 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6315 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006316 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006317 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006318 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6319 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6320 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6321 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6322 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006323 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006324 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006325 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6326 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006327 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6328 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6329 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006330 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006331 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006332 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6333 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006334 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006335 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006336 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6337 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6338 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006339 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6340 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006341
6342 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 +01006343 if !hasmapto('<Plug>NetrwHideEdit')
6344 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006345 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006346 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006347 if !hasmapto('<Plug>NetrwRefresh')
6348 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006349 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006350 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 +01006351 if s:didstarstar || !mapcheck("<s-down>","n")
6352 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006353 endif
6354 if s:didstarstar || !mapcheck("<s-up>","n")
6355 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006356 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006357 if !hasmapto('<Plug>NetrwTreeSqueeze')
6358 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006359 endif
6360 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006361 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6362 if g:netrw_mousemaps == 1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006363 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6364 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6365 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6366 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6367 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6368 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6369 imap <buffer> <leftmouse> <Plug>ILeftmouse
6370 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006371 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006372 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006373 nno <buffer> <silent> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006374 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006375 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006376 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
Bram Moolenaara6878372014-03-22 21:02:50 +01006377 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6378 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006379 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006380 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6381 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6382 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6383 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6384 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6385 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6386 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006387 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6388
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006389 " support user-specified maps
6390 call netrw#UserMaps(1)
6391
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006392 else
6393 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006394" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006395 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006396 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6397 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6398 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6399 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6400 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6401 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6402 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6403 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6404 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6405 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6406 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6407" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006408 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6409 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6410 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6411 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6412 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6413 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6414 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6415 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006416 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006417 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006418 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6419 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6420 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6421 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6422 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6423 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6424 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6425 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6426 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6427 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6428 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006429 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006430 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006431 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6432 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6433 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6434 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6435 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006436 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6437 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6438 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6439 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006440 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006441 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6442 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006443 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006444 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 +01006445 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6446 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6447 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6448 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6449 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6450 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6451 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6452 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6453 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006454 if !hasmapto('<Plug>NetrwHideEdit')
6455 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006456 endif
6457 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6458 if !hasmapto('<Plug>NetrwRefresh')
6459 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006460 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006461 if !hasmapto('<Plug>NetrwTreeSqueeze')
6462 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006463 endif
6464 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006465
6466 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006467 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006468
6469 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6470 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006471 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6472 nno <buffer> <silent> <Plug>NetrwLeftmouse <leftmouse>:call <SID>NetrwLeftmouse(0)<cr>
6473 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6474 nno <buffer> <silent> <Plug>NetrwCLeftmouse <leftmouse>:call <SID>NetrwCLeftmouse(0)<cr>
6475 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6476 nno <buffer> <silent> <Plug>NetrwSLeftmouse <leftmouse>:call <SID>NetrwSLeftmouse(0)<cr>
6477 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6478 nno <buffer> <silent> <Plug>NetrwSLeftdrag <leftmouse>:call <SID>NetrwSLeftdrag(0)<cr>
6479 nmap <middlemouse> <Plug>NetrwMiddlemouse
6480 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse <leftmouse>:call <SID>NetrwPrevWinOpen(0)<cr>
6481 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6482 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6483 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006484 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006485 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
Bram Moolenaara6878372014-03-22 21:02:50 +01006486 exe 'nnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6487 exe 'vnoremap <buffer> <silent> <rightmouse> <leftmouse>:call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006488 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006489 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6490 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6491 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6492 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6493 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6494 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6495 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006496 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006497
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006498 " support user-specified maps
6499 call netrw#UserMaps(0)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006500 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006501
6502" call Dret("s:NetrwMaps")
6503endfun
6504
6505" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006506" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006507" If -buffer, the command is only available from within netrw buffers
6508" Otherwise, the command is available from any window, so long as netrw
6509" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006510fun! s:NetrwCommands(islocal)
6511" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6512
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006513 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6514 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006515 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 +01006516 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006517 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006518 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006519 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006520 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006521 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006522
6523" call Dret("s:NetrwCommands")
6524endfun
6525
6526" ---------------------------------------------------------------------
6527" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6528" glob()ing only works with local files
6529fun! s:NetrwMarkFiles(islocal,...)
6530" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006531 let curdir = s:NetrwGetCurdir(a:islocal)
6532 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006533 while i <= a:0
6534 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006535 if v:version > 704 || (v:version == 704 && has("patch656"))
6536 let mffiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006537 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006538 let mffiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006539 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006540 else
6541 let mffiles= [a:{i}]
6542 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006543" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006544 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006545" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006546 call s:NetrwMarkFile(a:islocal,mffile)
6547 endfor
6548 let i= i + 1
6549 endwhile
6550" call Dret("s:NetrwMarkFiles")
6551endfun
6552
6553" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006554" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006555fun! s:NetrwMarkTarget(...)
6556" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6557 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006558 let curdir = s:NetrwGetCurdir(1)
6559 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006560 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006561 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6562 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006563 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006564" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006565 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006566 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6567 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006568 let svpos = winsaveview()
6569" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006570 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006571" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6572 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006573" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006574endfun
6575
6576" ---------------------------------------------------------------------
6577" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6578" mark and unmark files. If a markfile list exists,
6579" then the rename and delete functions will use it instead
6580" of whatever may happen to be under the cursor at that
6581" moment. When the mouse and gui are available,
6582" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006583"
6584" Creates two lists
6585" s:netrwmarkfilelist -- holds complete paths to all marked files
6586" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6587"
6588" Creates a marked file match string
6589" s:netrwmarfilemtch_# -- used with 2match to display marked files
6590"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006591" Creates a buffer version of islocal
6592" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006593fun! s:NetrwMarkFile(islocal,fname)
6594" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006595" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006596
6597 " sanity check
6598 if empty(a:fname)
6599" call Dret("s:NetrwMarkFile : emtpy fname")
6600 return
6601 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006602 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006603
Bram Moolenaar97d62492012-11-15 21:28:22 +01006604 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006605 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006606 if a:fname =~ '^\a'
6607 let leader= '\<'
6608 else
6609 let leader= ''
6610 endif
6611 if a:fname =~ '\a$'
6612 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6613 else
6614 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6615 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006616
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006617 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006618 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006619" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6620" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6621" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006622 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006623
6624 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006625 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006626" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006627 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006628 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006629
6630 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006631 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006632" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006633 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6634 if s:netrwmarkfilelist_{curbufnr} == []
6635 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006636" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006637 call s:NetrwUnmarkList(curbufnr,curdir)
6638 else
6639 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006640" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006641 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006643 for fname in s:netrwmarkfilelist_{curbufnr}
6644 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006645 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006646 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006647 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006648 endif
6649 let first= 0
6650 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006651" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006652 endif
6653 endif
6654
6655 else
6656 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006657" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006658
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006659" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006660 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006661 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6662" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006663
6664 " build initial markfile matching pattern
6665 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006666 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006667 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006668 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006669 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006670" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006671 endif
6672
6673 " handle global markfilelist
6674 if exists("s:netrwmarkfilelist")
6675 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6676 if index(s:netrwmarkfilelist,dname) == -1
6677 " append new filename to global markfilelist
6678 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006679" call Decho("append filename<".a:fname."> to global markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006680 else
6681 " remove new filename from global markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006682" call Decho("filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006683 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006684" call Decho("ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006685 if s:netrwmarkfilelist == []
6686 unlet s:netrwmarkfilelist
6687 endif
6688 endif
6689 else
6690 " initialize new global-directory markfilelist
6691 let s:netrwmarkfilelist= []
6692 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006693" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006694 endif
6695
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006696 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006697 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6698 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6699" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6700 if exists("g:did_drchip_netrwlist_syntax")
6701 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6702 endif
6703 else
6704" " call Decho("2match none",'~'.expand("<slnum>"))
6705 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006706 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006707 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006708 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02006709" 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 +00006710endfun
6711
6712" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006713" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6714" mA: move the argument list to marked file list (tomflist=1)
6715" Uses the global marked file list
6716fun! s:NetrwMarkFileArgList(islocal,tomflist)
6717" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
6718
6719 let svpos = winsaveview()
6720" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6721 let curdir = s:NetrwGetCurdir(a:islocal)
6722 let curbufnr = bufnr("%")
6723
6724 if a:tomflist
6725 " mA: move argument list to marked file list
6726 while argc()
6727 let fname= argv(0)
6728" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
6729 exe "argdel ".fnameescape(fname)
6730 call s:NetrwMarkFile(a:islocal,fname)
6731 endwhile
6732
6733 else
6734 " ma: move marked file list to argument list
6735 if exists("s:netrwmarkfilelist")
6736
6737 " for every filename in the marked list
6738 for fname in s:netrwmarkfilelist
6739" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
6740 exe "argadd ".fnameescape(fname)
6741 endfor " for every file in the marked list
6742
6743 " unmark list and refresh
6744 call s:NetrwUnmarkList(curbufnr,curdir)
6745 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
6746" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6747 NetrwKeepj call winrestview(svpos)
6748 endif
6749 endif
6750
6751" call Dret("s:NetrwMarkFileArgList")
6752endfun
6753
6754" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006755" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6756" compress/decompress files using the programs
6757" in g:netrw_compress and g:netrw_uncompress,
6758" using g:netrw_compress_suffix to know which to
6759" do. By default:
6760" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006761" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006762fun! s:NetrwMarkFileCompress(islocal)
6763" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006764 let svpos = winsaveview()
6765" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006766 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006767 let curbufnr = bufnr("%")
6768
Bram Moolenaarff034192013-04-24 18:51:19 +02006769 " sanity check
6770 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006771 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006772" call Dret("s:NetrwMarkFileCompress")
6773 return
6774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006775" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006776
Bram Moolenaar446cb832008-06-24 21:56:24 +00006777 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006778
6779 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006780 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006781 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006783 if exists("g:netrw_decompress['".sfx."']")
6784 " fname has a suffix indicating that its compressed; apply associated decompression routine
6785 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006786" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006787 let exe= netrw#WinPath(exe)
6788 if a:islocal
6789 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006790 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006791 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006792 call system(exe." ".fname)
6793 if v:shell_error
6794 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaarff034192013-04-24 18:51:19 +02006795 endif
6796 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006797 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6798 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaarff034192013-04-24 18:51:19 +02006799 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006800
Bram Moolenaarff034192013-04-24 18:51:19 +02006801 endif
6802 unlet sfx
6803
Bram Moolenaar446cb832008-06-24 21:56:24 +00006804 if exists("exe")
6805 unlet exe
6806 elseif a:islocal
6807 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006808 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006809 if v:shell_error
6810 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6811 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006812 else
6813 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006814 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006815 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006816 endfor " for every file in the marked list
6817
Bram Moolenaar446cb832008-06-24 21:56:24 +00006818 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006819 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006820" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6821 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006822 endif
6823" call Dret("s:NetrwMarkFileCompress")
6824endfun
6825
6826" ---------------------------------------------------------------------
6827" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6828" If no marked files, then set up directory as the
6829" target. Currently does not support copying entire
6830" directories. Uses the local-buffer marked file list.
6831" Returns 1=success (used by NetrwMarkFileMove())
6832" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006833fun! s:NetrwMarkFileCopy(islocal,...)
6834" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6835
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006836 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006837 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006838 if b:netrw_curdir !~ '/$'
6839 if !exists("b:netrw_curdir")
6840 let b:netrw_curdir= curdir
6841 endif
6842 let b:netrw_curdir= b:netrw_curdir."/"
6843 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006844
Bram Moolenaarff034192013-04-24 18:51:19 +02006845 " sanity check
6846 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006847 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006848" call Dret("s:NetrwMarkFileCopy")
6849 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006850 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006851" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006852
Bram Moolenaar446cb832008-06-24 21:56:24 +00006853 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006854 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006855" call Dret("s:NetrwMarkFileCopy 0")
6856 return 0
6857 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006858" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006859
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006860 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006861 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006862" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006863 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006864 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6865" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6866 return
6867 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006868
6869 " copy marked files while within the same directory (ie. allow renaming)
6870 if simplify(s:netrwmftgt) == simplify(b:netrw_curdir)
6871 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6872 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006873" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006874 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006875 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6876 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006877" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006878 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006879 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006880 let oldname = a:1
6881 else
6882 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006883" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006884 let s:recursive= 1
6885 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6886 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6887 if ret == 0
6888 break
6889 endif
6890 endfor
6891 unlet s:recursive
6892 call s:NetrwUnmarkList(curbufnr,curdir)
6893" call Dret("s:NetrwMarkFileCopy ".ret)
6894 return ret
6895 endif
6896
6897 call inputsave()
6898 let newname= input("Copy ".oldname." to : ",oldname,"file")
6899 call inputrestore()
6900 if newname == ""
6901" call Dret("s:NetrwMarkFileCopy 0")
6902 return 0
6903 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006904 let args= s:ShellEscape(oldname)
6905 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006906 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006907 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6908 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006909 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006910 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6911 let args= substitute(args,'/','\\','g')
6912 let tgt = substitute(tgt, '/','\\','g')
6913 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006914 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6915 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6916 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6917 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6918" call Decho("args <".args.">",'~'.expand("<slnum>"))
6919" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006920 if isdirectory(s:NetrwFile(args))
6921" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006922 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006923" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006924 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
6925 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6926 " contents to a target. One must append the source directory name to the target to get xcopy to
6927 " do the right thing.
6928 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006929" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006930 endif
6931 else
6932 let copycmd= g:netrw_localcopycmd
6933 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006934 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006935 let copycmd = substitute(copycmd,'\s.*$','','')
6936 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006937 let copycmd = netrw#WinPath(copycmd).copycmdargs
6938 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006939 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006940 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006941" call Decho("args <".args.">",'~'.expand("<slnum>"))
6942" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6943" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6944" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006945 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006946 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006947 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
6948 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-c)",101)
6949 else
6950 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6951 endif
6952" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006953 return 0
6954 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955
6956 elseif a:islocal && !s:netrwmftgt_islocal
6957 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006958" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006959 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006960
6961 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006962 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006963" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006964 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006965
6966 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006967 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006968" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 let curdir = getcwd()
6970 let tmpdir = s:GetTempfile("")
6971 if tmpdir !~ '/'
6972 let tmpdir= curdir."/".tmpdir
6973 endif
6974 if exists("*mkdir")
6975 call mkdir(tmpdir)
6976 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006977 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006978 if v:shell_error != 0
6979 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 +01006980" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006981 return
6982 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006983 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006984 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006985 if s:NetrwLcd(tmpdir)
6986" call Dret("s:NetrwMarkFileCopy : lcd failure")
6987 return
6988 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006989 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006990 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006991 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006992 if getcwd() == tmpdir
6993 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006994 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006995 endfor
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01006996 if s:NetrwLcd(curdir)
6997" call Dret("s:NetrwMarkFileCopy : lcd failure")
6998 return
6999 endif
7000 if v:version < 704 || (v:version == 704 && !has("patch1107"))
7001 call s:NetrwExe("sil !".g:netrw_localrmdir.g:netrw_localrmdiropt." ".s:ShellEscape(tmpdir,1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007002 if v:shell_error != 0
7003 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_localrmdir<".g:netrw_localrmdir."> to something that works",80)
7004" " call Dret("s:NetrwMarkFileCopy : failed: sil !".g:netrw_localrmdir." ".s:ShellEscape(tmpdir,1) )
7005 return
7006 endif
7007 else
7008 if delete(tmpdir,"d")
7009 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
7010 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007011 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007012 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007013 if s:NetrwLcd(curdir)
7014" call Dret("s:NetrwMarkFileCopy : lcd failure")
7015 return
7016 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007017 endif
7018 endif
7019 endif
7020
7021 " -------
7022 " cleanup
7023 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007024" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007025 " remove markings from local buffer
7026 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007027" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7028" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7029" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7030" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7031" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7032" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7033 if exists("s:recursive")
7034" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7035 else
7036" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007037 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007038 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007039 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007040 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007041 else
7042 " refresh local and targets for fast browsing
7043 if !exists("s:recursive")
7044 " remove markings from local buffer
7045" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7046 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7047 endif
7048
7049 " refresh buffers
7050 if s:netrwmftgt_islocal
7051" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7052 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7053 endif
7054 if a:islocal && s:netrwmftgt != curdir
7055" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7056 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7057 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007058 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007059
Bram Moolenaar446cb832008-06-24 21:56:24 +00007060" call Dret("s:NetrwMarkFileCopy 1")
7061 return 1
7062endfun
7063
7064" ---------------------------------------------------------------------
7065" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7066" invoke vim's diff mode on the marked files.
7067" Either two or three files can be so handled.
7068" Uses the global marked file list.
7069fun! s:NetrwMarkFileDiff(islocal)
7070" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7071 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007072
Bram Moolenaarff034192013-04-24 18:51:19 +02007073 " sanity check
7074 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007075 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007076" call Dret("s:NetrwMarkFileDiff")
7077 return
7078 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007079 let curdir= s:NetrwGetCurdir(a:islocal)
7080" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007081
Bram Moolenaara6878372014-03-22 21:02:50 +01007082 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007083 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007084 for fname in s:netrwmarkfilelist
7085 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007086 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007087" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007088 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007089 diffthis
7090 elseif cnt == 2 || cnt == 3
7091 vsplit
7092 wincmd l
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007093" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007094 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007095 diffthis
7096 else
7097 break
7098 endif
7099 endfor
7100 call s:NetrwUnmarkList(curbufnr,curdir)
7101 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007102
Bram Moolenaar446cb832008-06-24 21:56:24 +00007103" call Dret("s:NetrwMarkFileDiff")
7104endfun
7105
7106" ---------------------------------------------------------------------
7107" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7108" Uses global markfilelist
7109fun! s:NetrwMarkFileEdit(islocal)
7110" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7111
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007112 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007113 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007114
7115 " sanity check
7116 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007117 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007118" call Dret("s:NetrwMarkFileEdit")
7119 return
7120 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007121" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007122
Bram Moolenaar446cb832008-06-24 21:56:24 +00007123 if exists("s:netrwmarkfilelist_{curbufnr}")
7124 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007125 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007126 " unmark markedfile list
7127" call s:NetrwUnmarkList(curbufnr,curdir)
7128 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007129" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007130 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007131 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007132 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007133
Bram Moolenaar446cb832008-06-24 21:56:24 +00007134" call Dret("s:NetrwMarkFileEdit")
7135endfun
7136
7137" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007138" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007139fun! s:NetrwMarkFileQFEL(islocal,qfel)
7140" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7141 call s:NetrwUnmarkAll()
7142 let curbufnr= bufnr("%")
7143
7144 if !empty(a:qfel)
7145 for entry in a:qfel
7146 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007147" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007148 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007149" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007150 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7151 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7152 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7153 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007154" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007155 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7156 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007157" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007158 endif
7159 endfor
7160 echo "(use me to edit marked files)"
7161 else
7162 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7163 endif
7164
7165" call Dret("s:NetrwMarkFileQFEL")
7166endfun
7167
7168" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007169" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7170" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7171" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7172fun! s:NetrwMarkFileExe(islocal,enbloc)
7173" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007174 let svpos = winsaveview()
7175" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007176 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007177 let curbufnr = bufnr("%")
7178
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007179 if a:enbloc == 0
7180 " individually apply command to files, one at a time
7181 " sanity check
7182 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7183 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7184" call Dret("s:NetrwMarkFileExe")
7185 return
7186 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007187" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007188
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007189 if exists("s:netrwmarkfilelist_{curbufnr}")
7190 " get the command
7191 call inputsave()
7192 let cmd= input("Enter command: ","","file")
7193 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007194" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007195 if cmd == ""
7196" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7197 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007198 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007199
7200 " apply command to marked files, individually. Substitute: filename -> %
7201 " If no %, then append a space and the filename to the command
7202 for fname in s:netrwmarkfilelist_{curbufnr}
7203 if a:islocal
7204 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007205 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007206 endif
7207 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007208 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007209 endif
7210 if cmd =~ '%'
7211 let xcmd= substitute(cmd,'%',fname,'g')
7212 else
7213 let xcmd= cmd.' '.fname
7214 endif
7215 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007216" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007217 let ret= system(xcmd)
7218 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007219" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007220 let ret= s:RemoteSystem(xcmd)
7221 endif
7222 if v:shell_error < 0
7223 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7224 break
7225 else
7226 echo ret
7227 endif
7228 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007229
7230 " unmark marked file list
7231 call s:NetrwUnmarkList(curbufnr,curdir)
7232
7233 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007234 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007235" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7236 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007237 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007238 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007239 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007240
7241 else " apply command to global list of files, en bloc
7242
7243 call inputsave()
7244 let cmd= input("Enter command: ","","file")
7245 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007246" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007247 if cmd == ""
7248" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7249 return
7250 endif
7251 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007252 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007253 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007254 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007255 endif
7256 if a:islocal
7257 call system(cmd)
7258 if v:shell_error < 0
7259 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7260 endif
7261 else
7262 let ret= s:RemoteSystem(cmd)
7263 endif
7264 call s:NetrwUnmarkAll()
7265
7266 " refresh the listing
7267 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007268" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7269 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007270
7271 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007272
Bram Moolenaar446cb832008-06-24 21:56:24 +00007273" call Dret("s:NetrwMarkFileExe")
7274endfun
7275
7276" ---------------------------------------------------------------------
7277" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7278" as the marked file(s) (toggles suffix presence)
7279" Uses the local marked file list.
7280fun! s:NetrwMarkHideSfx(islocal)
7281" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007282 let svpos = winsaveview()
7283" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007284 let curbufnr = bufnr("%")
7285
7286 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7287 if exists("s:netrwmarkfilelist_{curbufnr}")
7288
7289 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007290" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007291 " construct suffix pattern
7292 if fname =~ '\.'
7293 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7294 else
7295 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7296 endif
7297 " determine if its in the hiding list or not
7298 let inhidelist= 0
7299 if g:netrw_list_hide != ""
7300 let itemnum = 0
7301 let hidelist= split(g:netrw_list_hide,',')
7302 for hidepat in hidelist
7303 if sfxpat == hidepat
7304 let inhidelist= 1
7305 break
7306 endif
7307 let itemnum= itemnum + 1
7308 endfor
7309 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007310" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007311 if inhidelist
7312 " remove sfxpat from list
7313 call remove(hidelist,itemnum)
7314 let g:netrw_list_hide= join(hidelist,",")
7315 elseif g:netrw_list_hide != ""
7316 " append sfxpat to non-empty list
7317 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7318 else
7319 " set hiding list to sfxpat
7320 let g:netrw_list_hide= sfxpat
7321 endif
7322 endfor
7323
7324 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007325 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007326" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7327 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007328 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007329 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007330 endif
7331
7332" call Dret("s:NetrwMarkHideSfx")
7333endfun
7334
7335" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007336" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007337" Uses the local marked-file list.
7338fun! s:NetrwMarkFileVimCmd(islocal)
7339" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007340 let svpos = winsaveview()
7341" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007342 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007343 let curbufnr = bufnr("%")
7344
Bram Moolenaarff034192013-04-24 18:51:19 +02007345 " sanity check
7346 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007347 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007348" call Dret("s:NetrwMarkFileVimCmd")
7349 return
7350 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007351" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007352
Bram Moolenaar15146672011-10-20 22:22:38 +02007353 if exists("s:netrwmarkfilelist_{curbufnr}")
7354 " get the command
7355 call inputsave()
7356 let cmd= input("Enter vim command: ","","file")
7357 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007358" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007359 if cmd == ""
7360" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7361 return
7362 endif
7363
7364 " apply command to marked files. Substitute: filename -> %
7365 " If no %, then append a space and the filename to the command
7366 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007367" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007368 if a:islocal
7369 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007370 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007371" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007372 exe cmd
7373 exe "sil! keepalt wq!"
7374 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007375" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007376 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007377 endif
7378 endfor
7379
7380 " unmark marked file list
7381 call s:NetrwUnmarkList(curbufnr,curdir)
7382
7383 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007384 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007385" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7386 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007387 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007388 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007389 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007390
Bram Moolenaar15146672011-10-20 22:22:38 +02007391" call Dret("s:NetrwMarkFileVimCmd")
7392endfun
7393
7394" ---------------------------------------------------------------------
7395" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7396" as the marked file(s) (toggles suffix presence)
7397" Uses the local marked file list.
7398fun! s:NetrwMarkHideSfx(islocal)
7399" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007400 let svpos = winsaveview()
7401" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007402 let curbufnr = bufnr("%")
7403
7404 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7405 if exists("s:netrwmarkfilelist_{curbufnr}")
7406
7407 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007408" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007409 " construct suffix pattern
7410 if fname =~ '\.'
7411 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7412 else
7413 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7414 endif
7415 " determine if its in the hiding list or not
7416 let inhidelist= 0
7417 if g:netrw_list_hide != ""
7418 let itemnum = 0
7419 let hidelist= split(g:netrw_list_hide,',')
7420 for hidepat in hidelist
7421 if sfxpat == hidepat
7422 let inhidelist= 1
7423 break
7424 endif
7425 let itemnum= itemnum + 1
7426 endfor
7427 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007428" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007429 if inhidelist
7430 " remove sfxpat from list
7431 call remove(hidelist,itemnum)
7432 let g:netrw_list_hide= join(hidelist,",")
7433 elseif g:netrw_list_hide != ""
7434 " append sfxpat to non-empty list
7435 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7436 else
7437 " set hiding list to sfxpat
7438 let g:netrw_list_hide= sfxpat
7439 endif
7440 endfor
7441
7442 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007443 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007444" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7445 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007446 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007447 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007448 endif
7449
7450" call Dret("s:NetrwMarkHideSfx")
7451endfun
7452
7453" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007454" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7455" Uses the global markfilelist
7456fun! s:NetrwMarkFileGrep(islocal)
7457" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007458 let svpos = winsaveview()
7459" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007460 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007461 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007462
7463 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007464" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007465 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007466 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007467 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007468" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007469 let netrwmarkfilelist= "*"
7470 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007471
Bram Moolenaarff034192013-04-24 18:51:19 +02007472 " ask user for pattern
7473 call inputsave()
7474 let pat= input("Enter pattern: ","")
7475 call inputrestore()
7476 let patbang = ""
7477 if pat =~ '^!'
7478 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007479 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007480 endif
7481 if pat =~ '^\i'
7482 let pat = escape(pat,'/')
7483 let pat = '/'.pat.'/'
7484 else
7485 let nonisi = pat[0]
7486 endif
7487
7488 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007489" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007490 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007491 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007492 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007493 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007494" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7495 return
7496 endtry
7497 echo "(use :cn, :cp to navigate, :Rex to return)"
7498
7499 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007500" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7501 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007502
7503 if exists("nonisi")
7504 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007505" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007506 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007507 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007508 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007509 endif
7510
7511" call Dret("s:NetrwMarkFileGrep")
7512endfun
7513
7514" ---------------------------------------------------------------------
7515" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7516" uses the global marked file list
7517" s:netrwmfloc= 0: target directory is remote
7518" = 1: target directory is local
7519fun! s:NetrwMarkFileMove(islocal)
7520" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007521 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007522 let curbufnr = bufnr("%")
7523
7524 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007525 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007526 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007527" call Dret("s:NetrwMarkFileMove")
7528 return
7529 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007530" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007531
Bram Moolenaar446cb832008-06-24 21:56:24 +00007532 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007533 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007534" call Dret("s:NetrwMarkFileCopy 0")
7535 return 0
7536 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007537" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007538
7539 if a:islocal && s:netrwmftgt_islocal
7540 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007541" call Decho("move from local to local",'~'.expand("<slnum>"))
7542" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007543 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007544 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7545" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7546 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007547 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007548 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007549" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007550 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007551 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007552" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007553 if g:netrw_localmovecmd =~ '\s'
7554 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7555 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7556 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007557" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007558 else
7559 let movecmd = netrw#WinPath(movecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007560" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007561 endif
7562 else
7563 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007564" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007565 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007566 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaarff034192013-04-24 18:51:19 +02007567 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
7568 let fname= substitute(fname,'/','\\','g')
7569 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007570" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007571 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007572 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007573 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
7574 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-c)",100)
7575 else
7576 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7577 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007578 break
7579 endif
7580 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007581
7582 elseif a:islocal && !s:netrwmftgt_islocal
7583 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007584" call Decho("move from local to remote",'~'.expand("<slnum>"))
7585" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007586 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007587 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007588" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007589 for fname in mflist
7590 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7591 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7592 endfor
7593 unlet mflist
7594
7595 elseif !a:islocal && s:netrwmftgt_islocal
7596 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007597" call Decho("move from remote to local",'~'.expand("<slnum>"))
7598" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007599 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007600 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007601" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602 for fname in mflist
7603 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7604 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7605 endfor
7606 unlet mflist
7607
7608 elseif !a:islocal && !s:netrwmftgt_islocal
7609 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007610" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7611" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007612 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007613 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007614" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007615 for fname in mflist
7616 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7617 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7618 endfor
7619 unlet mflist
7620 endif
7621
7622 " -------
7623 " cleanup
7624 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007625" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007626
7627 " remove markings from local buffer
7628 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7629
7630 " refresh buffers
7631 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007632" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007633 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007634 endif
7635 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007636" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007637 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007638 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007639 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007640" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007641 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007642 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007643
Bram Moolenaar446cb832008-06-24 21:56:24 +00007644" call Dret("s:NetrwMarkFileMove")
7645endfun
7646
7647" ---------------------------------------------------------------------
7648" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7649" using the hardcopy command. Local marked-file list only.
7650fun! s:NetrwMarkFilePrint(islocal)
7651" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7652 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007653
7654 " sanity check
7655 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007656 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007657" call Dret("s:NetrwMarkFilePrint")
7658 return
7659 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007660" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7661 let curdir= s:NetrwGetCurdir(a:islocal)
7662
Bram Moolenaar446cb832008-06-24 21:56:24 +00007663 if exists("s:netrwmarkfilelist_{curbufnr}")
7664 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007665 call s:NetrwUnmarkList(curbufnr,curdir)
7666 for fname in netrwmarkfilelist
7667 if a:islocal
7668 if g:netrw_keepdir
7669 let fname= s:ComposePath(curdir,fname)
7670 endif
7671 else
7672 let fname= curdir.fname
7673 endif
7674 1split
7675 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007676" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007677 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007678" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007679 hardcopy
7680 q
7681 endfor
7682 2match none
7683 endif
7684" call Dret("s:NetrwMarkFilePrint")
7685endfun
7686
7687" ---------------------------------------------------------------------
7688" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7689" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007690" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007691fun! s:NetrwMarkFileRegexp(islocal)
7692" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7693
7694 " get the regular expression
7695 call inputsave()
7696 let regexp= input("Enter regexp: ","","file")
7697 call inputrestore()
7698
7699 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007700 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007701 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007702" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007703 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007704 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007705 let files = glob(s:ComposePath(dirname,regexp),0,0,1)
7706 else
7707 let files = glob(s:ComposePath(dirname,regexp),0,0)
7708 endif
7709" call Decho("files<".files.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01007710 let filelist= split(files,"\n")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007711
7712 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007713 for fname in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007714" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007715 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
Bram Moolenaar5c736222010-01-06 20:54:52 +01007716 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007717
7718 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007719" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007720
7721 " convert displayed listing into a filelist
7722 let eikeep = &ei
7723 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007724 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007725 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007726" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007727 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007728 NetrwKeepj call s:NetrwEnew()
7729 NetrwKeepj call s:NetrwSafeOptions()
7730 sil NetrwKeepj norm! "ap
7731 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007732 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007733 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007734 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007735 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007736 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007737 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007738 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007739 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007740 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007741 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007742 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7743 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007744 call histdel("/",-1)
7745 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007746 endif
7747 " convert regexp into the more usual glob-style format
7748 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007749" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007750 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007751 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007752 let filelist= getline(1,line("$"))
7753 q!
7754 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007755 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007756 endfor
7757 unlet filelist
7758 let @a = areg
7759 let &ei = eikeep
7760 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007761 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762
7763" call Dret("s:NetrwMarkFileRegexp")
7764endfun
7765
7766" ---------------------------------------------------------------------
7767" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7768" Uses the local marked file list.
7769fun! s:NetrwMarkFileSource(islocal)
7770" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7771 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007772
7773 " sanity check
7774 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007775 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007776" call Dret("s:NetrwMarkFileSource")
7777 return
7778 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007779" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7780 let curdir= s:NetrwGetCurdir(a:islocal)
7781
Bram Moolenaar446cb832008-06-24 21:56:24 +00007782 if exists("s:netrwmarkfilelist_{curbufnr}")
7783 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784 call s:NetrwUnmarkList(curbufnr,curdir)
7785 for fname in netrwmarkfilelist
7786 if a:islocal
7787 if g:netrw_keepdir
7788 let fname= s:ComposePath(curdir,fname)
7789 endif
7790 else
7791 let fname= curdir.fname
7792 endif
7793 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007794" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007795 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007796 endfor
7797 2match none
7798 endif
7799" call Dret("s:NetrwMarkFileSource")
7800endfun
7801
7802" ---------------------------------------------------------------------
7803" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7804" Uses the global markfilelist
7805fun! s:NetrwMarkFileTag(islocal)
7806" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007807 let svpos = winsaveview()
7808" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007809 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007810 let curbufnr = bufnr("%")
7811
Bram Moolenaarff034192013-04-24 18:51:19 +02007812 " sanity check
7813 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007814 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007815" call Dret("s:NetrwMarkFileTag")
7816 return
7817 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007818" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007819
Bram Moolenaar446cb832008-06-24 21:56:24 +00007820 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007821" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
7822 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007823 call s:NetrwUnmarkAll()
7824
7825 if a:islocal
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007826
7827" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
7828 call system(g:netrw_ctags." ".netrwmarkfilelist)
7829 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7831 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01007832
Bram Moolenaar446cb832008-06-24 21:56:24 +00007833 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007834 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007835 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007836 let curdir= b:netrw_curdir
7837 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007838 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007839 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007840" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007841 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007842 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007843 wq!
7844 endif
7845 2match none
7846 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007847" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7848 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007849 endif
7850
7851" call Dret("s:NetrwMarkFileTag")
7852endfun
7853
7854" ---------------------------------------------------------------------
7855" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007857" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007858" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007859" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007860fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007861" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
7862 let svpos = winsaveview()
7863" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007864 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007865 let hadtgt = exists("s:netrwmftgt")
7866 if !exists("w:netrw_bannercnt")
7867 let w:netrw_bannercnt= b:netrw_bannercnt
7868 endif
7869
7870 " set up target
7871 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007872" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007873 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7874 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007875" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007876 unlet s:netrwmftgt s:netrwmftgt_islocal
7877 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007878 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007879 endif
7880 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007881" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7882 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007883" call Dret("s:NetrwMarkFileTgt : removed target")
7884 return
7885 else
7886 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007887" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007888 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889
7890 else
7891 " get word under cursor.
7892 " * If directory, use it for the target.
7893 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007894" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 let curword= s:NetrwGetWord()
7896 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007899" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007900 elseif !a:islocal && tgtdir =~ '/$'
7901 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007902" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007903 else
7904 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007905" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007906 endif
7907 endif
7908 if a:islocal
7909 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7910 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007911" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007912 endif
7913 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007914 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007915 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7916 endif
7917 let s:netrwmftgt_islocal= a:islocal
7918
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007919 " need to do refresh so that the banner will be updated
7920 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007921 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007922" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01007923 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007924 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007925" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007926 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007927 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
7928 else
7929 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7930 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007931" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7932 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007933 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007934 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007935 endif
7936
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007937" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
7938" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007939" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
7940endfun
7941
7942" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007943" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7944fun! s:NetrwGetCurdir(islocal)
7945" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7946
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007947 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007948 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7949" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7950 elseif !exists("b:netrw_curdir")
7951 let b:netrw_curdir= getcwd()
7952" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7953 endif
7954
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007955" 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 +01007956 if b:netrw_curdir !~ '\<\a\{3,}://'
7957 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007958" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007959 if g:netrw_keepdir == 0
7960 call s:NetrwLcd(curdir)
7961 endif
7962 endif
7963
7964" call Dret("s:NetrwGetCurdir <".curdir.">")
7965 return b:netrw_curdir
7966endfun
7967
7968" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007969" s:NetrwOpenFile: query user for a filename and open it {{{2
7970fun! s:NetrwOpenFile(islocal)
7971" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007972 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007973 call inputsave()
7974 let fname= input("Enter filename: ")
7975 call inputrestore()
7976 if fname !~ '[/\\]'
7977 if exists("b:netrw_curdir")
7978 if exists("g:netrw_quiet")
7979 let netrw_quiet_keep = g:netrw_quiet
7980 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007981 let g:netrw_quiet = 1
7982 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007983 let s:rexposn_{bufnr("%")}= winsaveview()
7984" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007985 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007986 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007987 else
7988 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7989 endif
7990 if exists("netrw_quiet_keep")
7991 let g:netrw_quiet= netrw_quiet_keep
7992 else
7993 unlet g:netrw_quiet
7994 endif
7995 endif
7996 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007997 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007998 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007999 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008000" call Dret("s:NetrwOpenFile")
8001endfun
8002
8003" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008004" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8005" For the mapping to this function be made via
8006" netrwPlugin, you'll need to have had
8007" g:netrw_usetab set to non-zero.
8008fun! netrw#Shrink()
8009" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8010 let curwin = winnr()
8011 let wiwkeep = &wiw
8012 set wiw=1
8013
8014 if &ft == "netrw"
8015 if winwidth(0) > g:netrw_wiw
8016 let t:netrw_winwidth= winwidth(0)
8017 exe "vert resize ".g:netrw_wiw
8018 wincmd l
8019 if winnr() == curwin
8020 wincmd h
8021 endif
8022" call Decho("vert resize 0",'~'.expand("<slnum>"))
8023 else
8024 exe "vert resize ".t:netrw_winwidth
8025" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8026 endif
8027
8028 elseif exists("t:netrw_lexbufnr")
8029 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8030 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8031 let t:netrw_winwidth= winwidth(0)
8032 exe "vert resize ".g:netrw_wiw
8033 wincmd l
8034 if winnr() == curwin
8035 wincmd h
8036 endif
8037" call Decho("vert resize 0",'~'.expand("<slnum>"))
8038 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8039 exe "vert resize ".t:netrw_winwidth
8040" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8041 else
8042 call netrw#Lexplore(0,0)
8043 endif
8044
8045 else
8046 call netrw#Lexplore(0,0)
8047 endif
8048 let wiw= wiwkeep
8049
8050" call Dret("netrw#Shrink")
8051endfun
8052
8053" ---------------------------------------------------------------------
8054" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8055fun! s:NetSortSequence(islocal)
8056" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8057
8058 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008059 let svpos= winsaveview()
8060" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008061 call inputsave()
8062 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8063 call inputrestore()
8064
8065 " refresh the listing
8066 let g:netrw_sort_sequence= newsortseq
8067 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008068" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8069 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008070 let @@= ykeep
8071
8072" call Dret("NetSortSequence")
8073endfun
8074
8075" ---------------------------------------------------------------------
8076" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8077" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008078" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008079fun! s:NetrwUnmarkList(curbufnr,curdir)
8080" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8081
8082 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008083 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8085 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8086 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8087 call remove(s:netrwmarkfilelist,idx) " remove from global list
8088 endfor
8089 if s:netrwmarkfilelist == []
8090 unlet s:netrwmarkfilelist
8091 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008092
Bram Moolenaar446cb832008-06-24 21:56:24 +00008093 " getting rid of the local marked-file lists is easy
8094 unlet s:netrwmarkfilelist_{a:curbufnr}
8095 endif
8096 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8097 unlet s:netrwmarkfilemtch_{a:curbufnr}
8098 endif
8099 2match none
8100" call Dret("s:NetrwUnmarkList")
8101endfun
8102
8103" ---------------------------------------------------------------------
8104" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8105fun! s:NetrwUnmarkAll()
8106" call Dfunc("s:NetrwUnmarkAll()")
8107 if exists("s:netrwmarkfilelist")
8108 unlet s:netrwmarkfilelist
8109 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008110 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008111 2match none
8112" call Dret("s:NetrwUnmarkAll")
8113endfun
8114
8115" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008116" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008117fun! s:NetrwUnmarkAll2()
8118" call Dfunc("s:NetrwUnmarkAll2()")
8119 redir => netrwmarkfilelist_let
8120 let
8121 redir END
8122 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008123 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008124 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8125 for flist in netrwmarkfilelist_list
8126 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8127 unlet s:netrwmarkfilelist_{curbufnr}
8128 unlet s:netrwmarkfilemtch_{curbufnr}
8129 endfor
8130" call Dret("s:NetrwUnmarkAll2")
8131endfun
8132
8133" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008134" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8135"
8136" Marked files are in two types of lists:
8137" s:netrwmarkfilelist -- holds complete paths to all marked files
8138" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8139"
8140" Marked files suitable for use with 2match are in:
8141" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008142fun! s:NetrwUnMarkFile(islocal)
8143" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008144 let svpos = winsaveview()
8145" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008146 let curbufnr = bufnr("%")
8147
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008148 " unmark marked file list
8149 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8150 if exists("s:netrwmarkfilelist")
8151" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008152 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008153 endif
8154
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008155 let ibuf= 1
8156 while ibuf < bufnr("$")
8157 if exists("s:netrwmarkfilelist_".ibuf)
8158 unlet s:netrwmarkfilelist_{ibuf}
8159 unlet s:netrwmarkfilemtch_{ibuf}
8160 endif
8161 let ibuf = ibuf + 1
8162 endwhile
8163 2match none
8164
Bram Moolenaar446cb832008-06-24 21:56:24 +00008165" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008166"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8167call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008168" call Dret("s:NetrwUnMarkFile")
8169endfun
8170
8171" ---------------------------------------------------------------------
8172" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8173fun! s:NetrwMenu(domenu)
8174
8175 if !exists("g:NetrwMenuPriority")
8176 let g:NetrwMenuPriority= 80
8177 endif
8178
Bram Moolenaaradc21822011-04-01 18:03:16 +02008179 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008180" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8181
8182 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008183" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008184 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008185 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8186 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8187 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8188 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8189 if g:netrw_dirhistmax > 0
8190 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8191 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8192 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8193 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8194 else
8195 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8196 endif
8197 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8198 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8199 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8200 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8201 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8202 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8203 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8204 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8205 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8206 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8207 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8208 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8209 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8210 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8211 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 +01008212 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 +02008213 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8214 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8215 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8216 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8217 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8218 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8219 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8220 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8221 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8222 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8223 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8224 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8225 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8226 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8227 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8228 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8229 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8230 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8231 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8232 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8233 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8234 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8235 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8236 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8237 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8238 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8239 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8240 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8241 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8242 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>'
8243 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>'
8244 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>'
8245 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8246 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>'
8247 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>'
8248 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 +01008249 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 +02008250 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8251 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008252 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008253 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8254 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008255
8256 elseif !a:domenu
8257 let s:netrwcnt = 0
8258 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008259 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008260 exe curwin."wincmd w"
8261
8262 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008263" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008264 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008265" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008266 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008267 endif
8268 endif
8269" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008270 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008271 endif
8272
8273endfun
8274
8275" ---------------------------------------------------------------------
8276" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8277" Used by the O maps (as <SID>NetrwObtain())
8278fun! s:NetrwObtain(islocal)
8279" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8280
Bram Moolenaar97d62492012-11-15 21:28:22 +01008281 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008282 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008283 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008284 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008285 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8286 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008287 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008288 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008289 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008290
8291" call Dret("NetrwObtain")
8292endfun
8293
8294" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008295" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8296" If there's only one window, then the window will first be split.
8297" Returns:
8298" choice = 0 : didn't have to choose
8299" choice = 1 : saved modified file in window first
8300" choice = 2 : didn't save modified file, opened window
8301" choice = 3 : cancel open
8302fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008303" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008304
Bram Moolenaar97d62492012-11-15 21:28:22 +01008305 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008306 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008307 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008308
8309 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008310 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008311 let lastwinnr = winnr("$")
8312 let curword = s:NetrwGetWord()
8313 let choice = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008314 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008315 let curdir = s:treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008316" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008317
Bram Moolenaar8d043172014-01-23 14:24:41 +01008318 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008319 if lastwinnr == 1
8320 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008321" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008322 " g:netrw_preview=0: preview window shown in a horizontally split window
8323 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008324 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008325 " vertically split preview window
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008326 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008327" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008328 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008329 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008330 " horizontally split preview window
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008331 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008332" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008333 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008334 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008335 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008336" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008337
8338 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008339 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008340 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008341 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008342 wincmd p
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008343" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008344
8345 " prevwinnr: the window number of the "prev" window
8346 " prevbufnr: the buffer number of the buffer in the "prev" window
8347 " bnrcnt : the qty of windows open on the "prev" buffer
8348 let prevwinnr = winnr()
8349 let prevbufnr = bufnr("%")
8350 let prevbufname = bufname("%")
8351 let prevmod = &mod
8352 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008353 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008354" 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 +01008355
8356 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008357 " and it doesn't appear in any other extant window, then ask the
8358 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008359 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008360" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008361 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008362" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008363 exe prevwinnr."wincmd w"
8364
8365 if bnrcnt == 1 && &hidden == 0
8366 " only one copy of the modified buffer in a window, and
8367 " hidden not set, so overwriting will lose the modified file. Ask first...
8368 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008369" call Decho("(NetrwPrevWinOpen) prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008370 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008371
8372 if choice == 1
8373 " Yes -- write file & then browse
8374 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008375 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008376 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008377 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008378 exe origwin."wincmd w"
8379 let &ei = eikeep
8380 let @@ = ykeep
8381" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008382 return choice
8383 endif
8384
8385 elseif choice == 2
8386 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008387" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008388 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008389
8390 else
8391 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008392" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008393 exe origwin."wincmd w"
8394 let &ei= eikeep
8395 let @@ = ykeep
8396" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008397 return choice
8398 endif
8399 endif
8400 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008401 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008402 endif
8403
8404 " restore b:netrw_curdir (window split/enew may have lost it)
8405 let b:netrw_curdir= curdir
8406 if a:islocal < 2
8407 if a:islocal
8408 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8409 else
8410 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8411 endif
8412 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008413 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008414" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008415 return choice
8416endfun
8417
8418" ---------------------------------------------------------------------
8419" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8420" Always assumed to be local -> remote
8421" call s:NetrwUpload(filename, target)
8422" call s:NetrwUpload(filename, target, fromdirectory)
8423fun! s:NetrwUpload(fname,tgt,...)
8424" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8425
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008426 if a:tgt =~ '^\a\{3,}://'
8427 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008428 else
8429 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8430 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008431" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008432
8433 if a:0 > 0
8434 let fromdir= a:1
8435 else
8436 let fromdir= getcwd()
8437 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008438" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008439
8440 if type(a:fname) == 1
8441 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008442" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008443 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008444" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8445 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8446" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008447 if a:tgt =~ '/$'
8448 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008449" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008450 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008451 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008452" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008453 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008454" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008455 endif
8456 q!
8457
8458 elseif type(a:fname) == 3
8459 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008460" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008461 let curdir= getcwd()
8462 if a:tgt =~ '^scp:'
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008463 if s:NetrwLcd(fromdir)
8464" call Dret("s:NetrwUpload : lcd failure")
8465 return
8466 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008467 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008468 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008469 if exists("g:netrw_port") && g:netrw_port != ""
8470 let useport= " ".g:netrw_scpport." ".g:netrw_port
8471 else
8472 let useport= ""
8473 endif
8474 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8475 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008476 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008477 if s:NetrwLcd(curdir)
8478" call Dret("s:NetrwUpload : lcd failure")
8479 return
8480 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008481
8482 elseif a:tgt =~ '^ftp:'
8483 call s:NetrwMethod(a:tgt)
8484
8485 if b:netrw_method == 2
8486 " handle uploading a list of files via ftp+.netrc
8487 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008488 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008489" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008490
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008491 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008492" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008493
8494 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008495 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008496" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008497 endif
8498
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008499 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008500" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008501
Bram Moolenaaradc21822011-04-01 18:03:16 +02008502 if tgtdir == ""
8503 let tgtdir= '/'
8504 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008505 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008506" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008507
8508 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008509 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8510" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008511 endfor
8512
8513 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008514 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 +00008515 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008516" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8517 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008518 endif
8519 " 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 +01008520 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008521 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008522 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8523 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8524 else
8525 bw!|q
8526 endif
8527
8528 elseif b:netrw_method == 3
8529 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8530 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008531 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008532 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008533 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008534
8535 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008536 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008537" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008538 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008539 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008540" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008541 endif
8542
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008543 if exists("g:netrw_uid") && g:netrw_uid != ""
8544 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008545 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008546" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008547 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008548 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008549 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008550" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008551 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008552 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008553" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008554 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008555 endif
8556
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008557 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008558" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008559
8560 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008561 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008562" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008563 endif
8564
8565 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008566 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008567" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008568 endif
8569
8570 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008571 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008572" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008573 endfor
8574
8575 " perform ftp:
8576 " -i : turns off interactive prompting from ftp
8577 " -n unix : DON'T use <.netrc>, even though it exists
8578 " -n win32: quit being obnoxious about password
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008579 NetrwKeepj norm! 1Gdd
8580 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008581 " 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 +01008582 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008583 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008584 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8585 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008586 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8588 let &debug = debugkeep
8589 let mod = 1
8590 else
8591 bw!|q
8592 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008593 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008594" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008595 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596 endif
8597 else
8598 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8599 endif
8600 endif
8601
8602" call Dret("s:NetrwUpload")
8603endfun
8604
8605" ---------------------------------------------------------------------
8606" s:NetrwPreview: {{{2
8607fun! s:NetrwPreview(path) range
8608" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008609 let ykeep= @@
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008610 NetrwKeepj call s:NetrwOptionSave("s:")
8611 NetrwKeepj call s:NetrwSafeOptions()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612 if has("quickfix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008613 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008614 if g:netrw_preview && !g:netrw_alto
Bram Moolenaar15146672011-10-20 22:22:38 +02008615 let pvhkeep = &pvh
8616 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8617 let &pvh = winwidth(0) - winsz
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008618 endif
8619 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
8620 if exists("pvhkeep")
8621 let &pvh= pvhkeep
8622 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008624 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008625 endif
8626 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008627 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 +00008628 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008629 NetrwKeepj call s:NetrwOptionRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008630 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631" call Dret("NetrwPreview")
8632endfun
8633
8634" ---------------------------------------------------------------------
8635" s:NetrwRefresh: {{{2
8636fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008637" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") hide=".g:netrw_hide." sortdir=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008639 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008640" call Decho("setl ma noro",'~'.expand("<slnum>"))
8641" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008642 let ykeep = @@
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008643 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8644 if !exists("w:netrw_treetop")
8645 if exists("b:netrw_curdir")
8646 let w:netrw_treetop= b:netrw_curdir
8647 else
8648 let w:netrw_treetop= getcwd()
8649 endif
8650 endif
8651 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8652 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008653
8654 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008655 let screenposn = winsaveview()
8656" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008657
8658" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8659" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8660 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008661 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008662 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008663 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008664 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008666
8667 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008668" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8669 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670
8671 " restore file marks
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01008672 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8673 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8674" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8675 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8676 else
8677" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8678 2match none
8679 endif
8680 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008681
Bram Moolenaar97d62492012-11-15 21:28:22 +01008682" restore
8683 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008684" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008685endfun
8686
8687" ---------------------------------------------------------------------
8688" s:NetrwRefreshDir: refreshes a directory by name {{{2
8689" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008690" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008691fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008692" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008693 if g:netrw_fastbrowse == 0
8694 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008696 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008697" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008698
8699 if tgtwin > 0
8700 " tgtwin is being displayed, so refresh it
8701 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008702" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008703 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008704 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008705 exe curwin."wincmd w"
8706
8707 elseif bufnr(a:dirname) > 0
8708 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008709" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
8710 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008711 endif
8712
8713 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008714" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008715 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008716 endif
8717" call Dret("s:NetrwRefreshDir")
8718endfun
8719
8720" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008721" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8722" window number to do its editing in.
8723" Supports [count]C where the count, if present, is used to specify
8724" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008725fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008726" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008727 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008728" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008729 if a:1 == "" " :NetrwC win#
8730 let g:netrw_chgwin= winnr()
8731 else " :NetrwC
8732 let g:netrw_chgwin= a:1
8733 endif
8734 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008735 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008736 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008737 let g:netrw_chgwin= winnr()
8738 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008739 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008740" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008741endfun
8742
8743" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008744" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8745" What this function does is to compute a priority for the patterns
8746" in the g:netrw_sort_sequence. It applies a substitute to any
8747" "files" that satisfy each pattern, putting the priority / in
8748" front. An "*" pattern handles the default priority.
8749fun! s:NetrwSetSort()
8750" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008751 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008752 if w:netrw_liststyle == s:LONGLIST
8753 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8754 else
8755 let seqlist = g:netrw_sort_sequence
8756 endif
8757 " sanity check -- insure that * appears somewhere
8758 if seqlist == ""
8759 let seqlist= '*'
8760 elseif seqlist !~ '\*'
8761 let seqlist= seqlist.',*'
8762 endif
8763 let priority = 1
8764 while seqlist != ""
8765 if seqlist =~ ','
8766 let seq = substitute(seqlist,',.*$','','e')
8767 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8768 else
8769 let seq = seqlist
8770 let seqlist = ""
8771 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008772 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008773 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008774 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008775 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008776 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008777 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008779" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008780
8781 " sanity check
8782 if w:netrw_bannercnt > line("$")
8783 " apparently no files were left after a Hiding pattern was used
8784" call Dret("SetSort : no files left after hiding")
8785 return
8786 endif
8787 if seq == '*'
8788 let starpriority= spriority
8789 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008790 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008791 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 " sometimes multiple sorting patterns will match the same file or directory.
8793 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008794 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8795 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008796 endif
8797 let priority = priority + 1
8798 endwhile
8799 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008800 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8801 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802 endif
8803
8804 " Following line associated with priority -- items that satisfy a priority
8805 " pattern get prefixed by ###/ which permits easy sorting by priority.
8806 " Sometimes files can satisfy multiple priority patterns -- only the latest
8807 " priority pattern needs to be retained. So, at this point, these excess
8808 " priority prefixes need to be removed, but not directories that happen to
8809 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008810 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8811 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008812 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008813
8814" call Dret("SetSort")
8815endfun
8816
Bram Moolenaarff034192013-04-24 18:51:19 +02008817" ---------------------------------------------------------------------
8818" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8819" Implements [count]Tb (bookhist<b>)
8820" [count]Th (bookhist<h>)
8821" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008822fun! s:NetrwSetTgt(islocal,bookhist,choice)
8823" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008824
8825 if a:bookhist == 'b'
8826 " supports choosing a bookmark as a target using a qb-generated list
8827 let choice= a:choice - 1
8828 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008829 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008830 else
8831 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8832 endif
8833
8834 elseif a:bookhist == 'h'
8835 " supports choosing a history stack entry as a target using a qb-generated list
8836 let choice= (a:choice % g:netrw_dirhistmax) + 1
8837 if exists("g:netrw_dirhist_".choice)
8838 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008839 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008840 else
8841 echomsg "Sorry, history#".a:choice." not available!"
8842 endif
8843 endif
8844
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008845 " refresh the display
8846 if !exists("b:netrw_curdir")
8847 let b:netrw_curdir= getcwd()
8848 endif
8849 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8850
Bram Moolenaarff034192013-04-24 18:51:19 +02008851" call Dret("s:NetrwSetTgt")
8852endfun
8853
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854" =====================================================================
8855" s:NetrwSortStyle: change sorting style (name - time - size) and refresh display {{{2
8856fun! s:NetrwSortStyle(islocal)
8857" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008858 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008859 let svpos= winsaveview()
8860" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008862 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 +01008863 NetrwKeepj norm! 0
8864 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008865" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8866 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008867
8868" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
8869endfun
8870
8871" ---------------------------------------------------------------------
8872" s:NetrwSplit: mode {{{2
8873" =0 : net and o
8874" =1 : net and t
8875" =2 : net and v
8876" =3 : local and o
8877" =4 : local and t
8878" =5 : local and v
8879fun! s:NetrwSplit(mode)
8880" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
8881
Bram Moolenaar97d62492012-11-15 21:28:22 +01008882 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008883 call s:SaveWinVars()
8884
8885 if a:mode == 0
8886 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008887 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008888 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02008890 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008891 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj call s:RestoreWinVars()
8893 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894 unlet s:didsplit
8895
8896 elseif a:mode == 1
8897 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01008898 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008899" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008900 tabnew
8901 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008902 NetrwKeepj call s:RestoreWinVars()
8903 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904 unlet s:didsplit
8905
8906 elseif a:mode == 2
8907 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008908 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008909 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008910" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02008911 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008913 NetrwKeepj call s:RestoreWinVars()
8914 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 unlet s:didsplit
8916
8917 elseif a:mode == 3
8918 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008919 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008920 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008921" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02008922 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008924 NetrwKeepj call s:RestoreWinVars()
8925 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008926 unlet s:didsplit
8927
8928 elseif a:mode == 4
8929 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008931 let eikeep = &ei
8932 let netrw_winnr = winnr()
8933 let netrw_line = line(".")
8934 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008935 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008936 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008937 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008938 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8939 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008940 let &ei = eikeep
8941 let netrw_curdir = s:NetrwTreeDir(0)
8942" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008943 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008944 let b:netrw_curdir = netrw_curdir
8945 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008946 NetrwKeepj call s:RestoreWinVars()
8947 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008948 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008949 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008950 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8951 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008952 let &ei= eikeep
8953 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008954 unlet s:didsplit
8955
8956 elseif a:mode == 5
8957 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008958 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008959 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008960" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02008961 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008962 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008963 NetrwKeepj call s:RestoreWinVars()
8964 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008965 unlet s:didsplit
8966
8967 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008968 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008969 endif
8970
Bram Moolenaar97d62492012-11-15 21:28:22 +01008971 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008972" call Dret("s:NetrwSplit")
8973endfun
8974
8975" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008976" s:NetrwTgtMenu: {{{2
8977fun! s:NetrwTgtMenu()
8978 if !exists("s:netrw_menucnt")
8979 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008980 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008981" call Dfunc("s:NetrwTgtMenu()")
8982
8983 " the following test assures that gvim is running, has menus available, and has menus enabled.
8984 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8985 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008986" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008987 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8988 endif
8989 if !exists("s:netrw_initbookhist")
8990 call s:NetrwBookHistRead()
8991 endif
8992
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008993 " try to cull duplicate entries
8994 let tgtdict={}
8995
Bram Moolenaarff034192013-04-24 18:51:19 +02008996 " target bookmarked places
8997 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008998" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008999 let cnt= 1
9000 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009001 if has_key(tgtdict,bmd)
9002 let cnt= cnt + 1
9003 continue
9004 endif
9005 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009006 let ebmd= escape(bmd,g:netrw_menu_escape)
9007 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009008" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009009 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 +02009010 let cnt= cnt + 1
9011 endfor
9012 endif
9013
9014 " target directory browsing history
9015 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009016" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009017 let histcnt = 1
9018 while histcnt <= g:netrw_dirhistmax
9019 let priority = g:netrw_dirhist_cnt + histcnt
9020 if exists("g:netrw_dirhist_{histcnt}")
9021 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009022 if has_key(tgtdict,histentry)
9023 let histcnt = histcnt + 1
9024 continue
9025 endif
9026 let tgtdict[histentry] = histcnt
9027 let ehistentry = escape(histentry,g:netrw_menu_escape)
9028" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009029 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 +02009030 endif
9031 let histcnt = histcnt + 1
9032 endwhile
9033 endif
9034 endif
9035" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009036endfun
9037
9038" ---------------------------------------------------------------------
9039" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9040" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009041fun! s:NetrwTreeDir(islocal)
9042" 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 +02009043" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9044" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9045" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009046
Bram Moolenaar8d043172014-01-23 14:24:41 +01009047 if exists("s:treedir")
9048 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
9049 let treedir= s:treedir
9050 unlet s:treedir
9051" call Dret("s:NetrwTreeDir ".treedir)
9052 return treedir
9053 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009054
Bram Moolenaar8d043172014-01-23 14:24:41 +01009055 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9056 let b:netrw_curdir= getcwd()
9057 endif
9058 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009059" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009060
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009061 let s:treecurpos= winsaveview()
9062" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9063
9064 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009065" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9066" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009067
9068 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009069 let curline= substitute(getline('.'),"\t -->.*$",'','')
9070 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009071" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009072 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009073" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9074 elseif curline =~ '@$'
9075" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
9076 let treedir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
9077" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009079" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009080 let treedir= ""
9081 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009082
9083 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009084" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9085" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009086" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009088" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009089 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009090" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9091 sil! NetrwKeepj %d _
9092" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009093 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009094" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009095" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009096 endif
9097
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009098" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009099 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9100" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009101
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009102 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9103" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9104" let newdir = w:netrw_treetop.'/'.potentialdir
9105" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9106" let treedir = s:NetrwTreePath(newdir)
9107" let w:netrw_treetop = newdir
9108" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9109" else
9110" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009111 let treedir = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009112" endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009113 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01009114
9115 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009116 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009117" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009118
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009119" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009120 return treedir
9121endfun
9122
9123" ---------------------------------------------------------------------
9124" s:NetrwTreeDisplay: recursive tree display {{{2
9125fun! s:NetrwTreeDisplay(dir,depth)
9126" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9127
9128 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009129 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009130
9131 " install ../ and shortdir
9132 if a:depth == ""
9133 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009134" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009135 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009136 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009137 if a:dir == w:netrw_treetop
9138 let shortdir= a:dir
9139 else
9140 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9141 endif
9142 call setline(line("$")+1,a:depth.shortdir)
9143 else
9144 let shortdir= substitute(a:dir,'^.*/','','e')
9145 call setline(line("$")+1,a:depth.shortdir.'/')
9146 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009147" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009148
9149 " append a / to dir if its missing one
9150 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009151
9152 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009153 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009154" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009155
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009156 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9157 if g:netrw_hide == 1
9158 " hide given patterns
9159 let listhide= split(g:netrw_list_hide,',')
9160" call Decho("listhide=".string(listhide))
9161 for pat in listhide
9162 call filter(w:netrw_treedict[dir],'v:val !~ "'.pat.'"')
9163 endfor
9164
9165 elseif g:netrw_hide == 2
9166 " show given patterns (only)
9167 let listhide= split(g:netrw_list_hide,',')
9168" call Decho("listhide=".string(listhide))
9169 let entries=[]
9170 for entry in w:netrw_treedict[dir]
9171 for pat in listhide
9172 if entry =~ pat
9173 call add(entries,entry)
9174 break
9175 endif
9176 endfor
9177 endfor
9178 let w:netrw_treedict[dir]= entries
9179 endif
9180 if depth != ""
9181 " always remove "." and ".." entries when there's depth
9182 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9183 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9184 endif
9185
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009186" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009187 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009188 if dir =~ '/$'
9189 let direntry= substitute(dir.entry,'[@/]$','','e')
9190 else
9191 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9192 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009193" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009194 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009195" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009196 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009197 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009198" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9199 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9200 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9201" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009202 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009204" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009205 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009206 endif
9207 endfor
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009208" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009209
Bram Moolenaar446cb832008-06-24 21:56:24 +00009210" call Dret("NetrwTreeDisplay")
9211endfun
9212
9213" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009214" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9215fun! s:NetrwRefreshTreeDict(dir)
9216" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009217 if !exists("w:netrw_treedict")
9218" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9219 return
9220 endif
9221
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009222 for entry in w:netrw_treedict[a:dir]
9223 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9224" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9225
9226 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9227" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9228 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009229 let liststar = s:NetrwGlob(direntry,'*',1)
9230 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009231 let w:netrw_treedict[direntry] = liststar + listdotstar
9232" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9233
9234 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9235" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9236 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009237 let liststar = s:NetrwGlob(direntry.'/','*',1)
9238 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009239 let w:netrw_treedict[direntry]= liststar + listdotstar
9240" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9241
9242 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9243" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9244 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009245 let liststar = s:NetrwGlob(direntry.'/','*',1)
9246 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009247" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9248
9249 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009250" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009251 endif
9252 endfor
9253" call Dret("s:NetrwRefreshTreeDict")
9254endfun
9255
9256" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009258" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009259fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009260 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00009261" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9263" 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>"))
9264" 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 +00009265
9266 " update the treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009267" call Decho("update the treetop",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009268 if !exists("w:netrw_treetop")
9269 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009270" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009271 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
9272 let w:netrw_treetop= a:dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009274 endif
9275
Bram Moolenaar446cb832008-06-24 21:56:24 +00009276 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009277 " insure that we have a treedict, albeit empty
9278" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009279 let w:netrw_treedict= {}
9280 endif
9281
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009282 " update the dictionary for the current directory
9283" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009285 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009286 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009287" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009288 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009289
9290 " if past banner, record word
9291 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9292 let fname= expand("<cword>")
9293 else
9294 let fname= ""
9295 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009296" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9297" 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 +00009298
9299 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009300 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009301" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009302
9303 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9304 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009305" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009306 1d
9307 endwhile
9308
Bram Moolenaar13600302014-05-22 18:26:40 +02009309 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009310
9311" call Dret("NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009312 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009313 endif
9314endfun
9315
9316" ---------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009317" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009318" Normally, treetop is w:netrw_treetop, but a
9319" user of the function ( netrw#SetTreetop() )
9320" wipes that out prior to calling this function
9321fun! s:NetrwTreePath(treetop)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009322" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9323 if line(".") < w:netrw_bannercnt + 2
9324 let treedir= a:treetop
9325 if treedir !~ '/$'
9326 let treedir= treedir.'/'
9327 endif
9328" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9329 return treedir
9330 endif
9331
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009332 let svpos = winsaveview()
9333" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009334 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009335" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009336 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009337" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9338 let curline= getline('.')
9339" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9340 if curline =~ '/$'
9341" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9342 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9343" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9344 elseif curline =~ '@\s\+-->'
9345" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9346 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9347 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9348" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009349 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009350" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009351 let treedir= ""
9352 endif
9353 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009354" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9355" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009356 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9357 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9358 let treedir= dirname.treedir
9359 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009360" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009361 endwhile
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009362" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009363 if a:treetop =~ '/$'
9364 let treedir= a:treetop.treedir
9365 else
9366 let treedir= a:treetop.'/'.treedir
9367 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009368" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009369 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009370" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009371" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9372 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009373" call Dret("s:NetrwTreePath <".treedir.">")
9374 return treedir
9375endfun
9376
9377" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009378" s:NetrwWideListing: {{{2
9379fun! s:NetrwWideListing()
9380
9381 if w:netrw_liststyle == s:WIDELIST
9382" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9383 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009384 " cpf: characters per filename
9385 " fpl: filenames per line
9386 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009387 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009388" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009389 let b:netrw_cpf= 0
9390 if line("$") >= w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009391 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9392 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009393 else
9394" call Dret("NetrwWideListing")
9395 return
9396 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009397 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009399
9400 " determine qty files per line (fpl)
9401 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9402 if w:netrw_fpl <= 0
9403 let w:netrw_fpl= 1
9404 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009405" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009406
9407 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009408 " fpc: files per column of wide listing
9409 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009410 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009411 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9412 let newcolstart = w:netrw_bannercnt + fpc
9413 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009414" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009415 if has("clipboard")
9416 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009417 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009418 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009419 while line("$") >= newcolstart
9420 if newcolend > line("$") | let newcolend= line("$") | endif
9421 let newcolqty= newcolend - newcolstart
9422 exe newcolstart
9423 if newcolqty == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009424 exe "sil! NetrwKeepj norm! 0\<c-v>$hx".w:netrw_bannercnt."G$p"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009425 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009426 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$hx'.w:netrw_bannercnt.'G$p'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009427 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009428 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009429 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009430 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009431 if has("clipboard")
9432 sil! let @*= keepregstar
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009433 sil! let @+= keepregplus
Bram Moolenaara6878372014-03-22 21:02:50 +01009434 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009435 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9436 NetrwKeepj call histdel("/",-1)
9437 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9438 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009439" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009440 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009441" call Decho("(NetrwWideListing) 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 +00009442" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009443 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009444 else
9445 if hasmapto("w","n")
9446 sil! nunmap <buffer> w
9447 endif
9448 if hasmapto("b","n")
9449 sil! nunmap <buffer> b
9450 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009451 endif
9452
9453endfun
9454
9455" ---------------------------------------------------------------------
9456" s:PerformListing: {{{2
9457fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9459" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009460" 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>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009461
Bram Moolenaar15146672011-10-20 22:22:38 +02009462 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009463" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009464 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009465
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009466 NetrwKeepj call s:NetrwSafeOptions()
Bram Moolenaara6878372014-03-22 21:02:50 +01009467 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009468" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009469
9470" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009471" call Decho("(netrw) Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009472" endif " Decho
9473
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009474" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009475 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9476 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009477" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9478 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009479 endif
9480
9481 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009482 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009483
9484 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009485 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009486" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009487 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009488 if exists("g:netrw_pchk")
9489 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9490 " failure detections.
9491 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009492 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009493 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9494 endif
9495 if exists("g:netrw_pchk")
9496 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9497 else
9498 let curdir= b:netrw_curdir
9499 endif
9500 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9501 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9502 else
9503 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009504 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009505 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009506 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009507 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009508" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009509 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009510 let w:netrw_bannercnt= 1
9511 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009512" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9513" 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 +00009514
9515 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009516 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009517 let sortby= sortby." reversed"
9518 endif
9519
9520 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009521 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009522" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009523 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009524" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009525 " sorted by name
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009526 NetrwKeepj put ='\" Sorted by '.sortby
9527 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009528 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9529 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009530" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009531 " sorted by size or date
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009532 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009533 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9534 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009535 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009536" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009537" 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 +00009538 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009539
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009540 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009541 if g:netrw_banner
9542 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009543" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009544 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009545 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009546 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009547 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009548 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009549 endif
9550 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009551 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009552" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009553 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009554 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009555 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009556
9557 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009558 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009559" call Decho("--handle hiding/showing (g:netrw_hide=".g:netrw_list_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009560 if g:netrw_list_hide != "" && g:netrw_hide
9561 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009562 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009563 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009564 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009565 endif
9566 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009567 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009568 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009569
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009570" 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 +01009571 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009572" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009573 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009574" 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 +01009575 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009576 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009577" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009578" 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 +00009579 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009580
9581 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009582 if g:netrw_banner
9583 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009584 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009585" 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 +01009586" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009587" 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 +01009588 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009589
Bram Moolenaar446cb832008-06-24 21:56:24 +00009590 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009591" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009592 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009593 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009595 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009596 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009597" 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 +01009598" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9599 return
9600 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009601 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009602
9603 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009604 if !exists("w:netrw_bannercnt")
9605 let w:netrw_bannercnt= 0
9606 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009607" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9608" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9609" 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 +01009610
Bram Moolenaar5c736222010-01-06 20:54:52 +01009611 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009612" call Decho("manipulate directory listing (hide)",'~'.expand("<slnum>"))
9613" 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 +00009614 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009615 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009616 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009617 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009618" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009619
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009620 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009621 " sort by name
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009622 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009623
Bram Moolenaar5c736222010-01-06 20:54:52 +01009624 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009625" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009626 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009627 " normal direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009628 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009629 else
9630 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009631 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009632 endif
9633 endif
9634 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009635" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009636 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9637 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009638
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009639 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009640 " sort by extension
9641 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9642 NetrwKeepj call histdel("/",-1)
9643 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9644 NetrwKeepj call histdel("/",-1)
9645 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9646 NetrwKeepj call histdel("/",-1)
9647 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9648" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009649 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009650 " normal direction sorting
9651 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9652 else
9653 " reverse direction sorting
9654 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9655 endif
9656 endif
9657 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9658 NetrwKeepj call histdel("/",-1)
9659
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009661 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009662" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009663 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009664" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009665 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009668 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009670 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9671 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009672 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009673 endif
9674
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009675 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009676" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009677 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009678 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009679 call histdel("/",-1)
9680 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009681 endif
9682 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009683" 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 +00009684
9685 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009686" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9687" 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 +01009688 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009689" 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 +01009690 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009691" 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 +00009692
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009693 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009694 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009695" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009696 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009697 endif
9698
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009700 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009701" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9702 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009703 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009704" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9705 else
9706" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9707" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9708" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9709" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009710 endif
9711
9712 " record previous current directory
9713 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009714" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009715
9716 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009717" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9718" 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 +01009719 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009720" 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 Moolenaar8feef4f2015-01-07 16:57:10 +01009721 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009722" 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 +00009723
9724 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009725" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009726 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009727" 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 +01009728 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009729" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009730 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9731 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009732
Bram Moolenaar8d043172014-01-23 14:24:41 +01009733 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009734" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9735" 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 +01009736" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9737 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009738 unlet s:treecurpos
9739 endif
9740
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009741" 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>"))
9742" 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 +00009743" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9744endfun
9745
9746" ---------------------------------------------------------------------
9747" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009748fun! s:SetupNetrwStatusLine(statline)
9749" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9750
9751 if !exists("s:netrw_setup_statline")
9752 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009753" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009754
9755 if !exists("s:netrw_users_stl")
9756 let s:netrw_users_stl= &stl
9757 endif
9758 if !exists("s:netrw_users_ls")
9759 let s:netrw_users_ls= &laststatus
9760 endif
9761
9762 " set up User9 highlighting as needed
9763 let keepa= @a
9764 redir @a
9765 try
9766 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009767 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009768 if &bg == "dark"
9769 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9770 else
9771 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9772 endif
9773 endtry
9774 redir END
9775 let @a= keepa
9776 endif
9777
9778 " set up status line (may use User9 highlighting)
9779 " insure that windows have a statusline
9780 " make sure statusline is displayed
9781 let &stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009782 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009783" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009784 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009785
9786" call Dret("SetupNetrwStatusLine : stl=".&stl)
9787endfun
9788
Bram Moolenaarb0d45e72017-11-05 18:19:24 +01009789" =========================================
9790" Remote Directory Browsing Support: {{{1
9791" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009792
9793" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009794" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9795" This function assumes that a long listing will be received. Size, time,
9796" and reverse sorts will be requested of the server but not otherwise
9797" enforced here.
9798fun! s:NetrwRemoteFtpCmd(path,listcmd)
9799" 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 +01009800" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009801 " sanity check: {{{3
9802 if !exists("w:netrw_method")
9803 if exists("b:netrw_method")
9804 let w:netrw_method= b:netrw_method
9805 else
9806 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9807" call Dret("NetrwRemoteFtpCmd")
9808 return
9809 endif
9810 endif
9811
9812 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9813 let ffkeep= &ff
9814 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009815" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009816
9817 " clear off any older non-banner lines " {{{3
9818 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009819" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9820 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009821
9822 ".........................................
9823 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9824 " ftp + <.netrc>: Method #2
9825 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009826 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009827 endif
9828 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009829 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009830" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009831 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009832 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009833" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009834 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009835" 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>"))
9836 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 +01009837 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009838" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9839 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 +01009840 endif
9841
9842 ".........................................
9843 elseif w:netrw_method == 3 " {{{3
9844 " ftp + machine,id,passwd,filename: Method #3
9845 setl ff=unix
9846 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009847 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009848 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009849 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009850 endif
9851
9852 " handle userid and password
9853 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009854" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009855 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9856 call NetUserPass("ftp:".host)
9857 endif
9858 if exists("g:netrw_uid") && g:netrw_uid != ""
9859 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009860 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009861 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009862 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009863 endif
9864 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009865 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009866 endif
9867 endif
9868
9869 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009870 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009871 endif
9872 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009873 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009874" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009875 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009876 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009877
9878 " perform ftp:
9879 " -i : turns off interactive prompting from ftp
9880 " -n unix : DON'T use <.netrc>, even though it exists
9881 " -n win32: quit being obnoxious about password
9882 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009883" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009884 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009885" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009886" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9887" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009888 endif
9889
9890 ".........................................
9891 elseif w:netrw_method == 9 " {{{3
9892 " sftp username@machine: Method #9
9893 " s:netrw_sftp_cmd
9894 setl ff=unix
9895
9896 " restore settings
9897 let &ff= ffkeep
9898" call Dret("NetrwRemoteFtpCmd")
9899 return
9900
9901 ".........................................
9902 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009903 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009904 endif
9905
9906 " cleanup for Windows " {{{3
9907 if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009908 sil! NetrwKeepj %s/\r$//e
9909 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009910 endif
9911 if a:listcmd == "dir"
9912 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009913 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9914 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9915 NetrwKeepj call histdel("/",-1)
9916 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009917 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 +01009918 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9919 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009920 endif
9921 endif
9922
9923 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9924 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009925 exe 'NetrwKeepj '.w:netrw_bannercnt
9926 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009927 endif
9928 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009929 exe 'NetrwKeepj '.w:netrw_bannercnt
9930 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009931 endif
9932
9933 " restore settings " {{{3
9934 let &ff= ffkeep
9935" call Dret("NetrwRemoteFtpCmd")
9936endfun
9937
9938" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939" s:NetrwRemoteListing: {{{2
9940fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009941" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009942
Bram Moolenaara6878372014-03-22 21:02:50 +01009943 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9944 let w:netrw_bannercnt= s:bannercnt
9945 endif
9946 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
9947 let w:netrw_bannercnt= s:bannercnt
9948 endif
9949
Bram Moolenaar446cb832008-06-24 21:56:24 +00009950 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009951
Bram Moolenaar446cb832008-06-24 21:56:24 +00009952 " sanity check:
9953 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009956" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009957 if !exists("g:netrw_quiet")
9958 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9959 endif
9960 call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009961" call Dret("s:NetrwRemoteListing -1")
9962 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009963 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009964
Bram Moolenaar8d043172014-01-23 14:24:41 +01009965 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009966" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009968 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009969 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 +00009970 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009971 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 +00009972 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009973 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009974
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009975 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009976" call Dret("s:NetrwRemoteListing -1")
9977 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009978 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009979" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009980
Bram Moolenaar446cb832008-06-24 21:56:24 +00009981 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009982" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009983 let w:netrw_method= b:netrw_method
9984 endif
9985
Bram Moolenaar13600302014-05-22 18:26:40 +02009986 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009987 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009988" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009989 let s:method = "ftp"
9990 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009991 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009992 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009993 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009994 let listcmd= g:netrw_ftp_sizelist_cmd
9995 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009997 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009999
Bram Moolenaara6878372014-03-22 21:02:50 +010010000 " report on missing file or directory messages
10001 if search('[Nn]o such file or directory\|Failed to change directory')
10002 let mesg= getline(".")
10003 if exists("w:netrw_bannercnt")
10004 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010005 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010006 setl noma
10007 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010008 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010009 call netrw#ErrorMsg(s:WARNING,mesg,96)
10010" call Dret("s:NetrwRemoteListing : -1")
10011 return -1
10012 endif
10013
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010014 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 +000010015 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010016" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010017 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018
10019 " cleanup
10020 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010021 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10022 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010023 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010024 sil! NetrwKeepj %s/\r$//e
10025 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010026
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010027 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010028 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010029 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010030 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010033" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010034 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010036 exe "sil! NetrwKeepj ".line1
10037 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010038
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010039" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010040 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010041" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010042 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10043 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010044 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010045" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010046 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10047 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10048 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10049 NetrwKeepj call histdel("/",-1)
10050 NetrwKeepj call histdel("/",-1)
10051 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010052 endif
10053 endif
10054
Bram Moolenaar13600302014-05-22 18:26:40 +020010055 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010056 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010057" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010058 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010059" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010060 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010061" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10062 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010063 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010064 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10065 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10066 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10067 NetrwKeepj call histdel("/",-1)
10068 NetrwKeepj call histdel("/",-1)
10069 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010070 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010071 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10072 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010073 endif
10074 else
10075 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010076" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010077 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010078 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010079" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10080 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10081" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010082 endif
10083 endif
10084
10085 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010086 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010087" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010088 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10089 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010090 endif
10091 endif
10092
10093 if w:netrw_liststyle == s:LONGLIST
10094 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010095" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010096
10097 if s:method == "ftp"
10098 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010099 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010100 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010101 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010102 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010103 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010104 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010105 sil! NetrwKeepj 1
10106 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010107 let line2= line(".")
10108 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010109 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010110 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010111 endif
10112 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010113 exe "sil! NetrwKeepj ".line1
10114 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010115 endif
10116
10117 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010118" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010119 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 +000010120 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010122 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010123 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010124 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10125 NetrwKeepj call histdel("/",-1)
10126 NetrwKeepj call histdel("/",-1)
10127 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010128 endif
10129 endif
10130
10131" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010132" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010133" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010134
10135" call Dret("s:NetrwRemoteListing 0")
10136 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010137endfun
10138
Bram Moolenaar446cb832008-06-24 21:56:24 +000010139" ---------------------------------------------------------------------
10140" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10141fun! s:NetrwRemoteRm(usrhost,path) range
10142" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010144 let svpos= winsaveview()
10145" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010146
10147 let all= 0
10148 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10149 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010151 for fname in s:netrwmarkfilelist_{bufnr("%")}
10152 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010153 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010154 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010155 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010156 let all= 1
10157 endif
10158 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010159 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010160
10161 else
10162 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010163" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010164
10165 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010166 let keepsol = &l:sol
10167 setl nosol
10168 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010169
10170 " remove multiple files and directories
10171 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010172 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010173 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010174 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010175 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010176 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010177 let all= 1
10178 endif
10179 let ctr= ctr + 1
10180 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010181 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010182 endif
10183
10184 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010185" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010186 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010187" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10188 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010189
10190" call Dret("s:NetrwRemoteRm")
10191endfun
10192
10193" ---------------------------------------------------------------------
10194" s:NetrwRemoteRmFile: {{{2
10195fun! s:NetrwRemoteRmFile(path,rmfile,all)
10196" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10197
10198 let all= a:all
10199 let ok = ""
10200
10201 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10202 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010203" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010204 if !all
10205 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010206" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010207 call inputsave()
10208 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10209 call inputrestore()
10210 echohl NONE
10211 if ok == ""
10212 let ok="no"
10213 endif
10214 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010215 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010216 let all= 1
10217 endif
10218 endif
10219
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010220 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010221" 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 +000010222 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010223" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010224 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010225 if path =~ '^\a\{3,}://'
10226 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010227 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010228 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010229 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10230 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010231" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010232 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010233" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010234 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010235 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010236 let ok="q"
10237 else
10238 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010239" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10240" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10241" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010242 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010243 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010244 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010245 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010246 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010247" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010248 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010249 if v:shell_error != 0
10250 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
10251 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-c)",102)
10252 else
10253 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10254 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010255 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010256 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010257 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010258" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010259 endif
10260 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010261 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010262" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010263 endif
10264
10265 else
10266 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010267" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010268 if !all
10269 call inputsave()
10270 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10271 call inputrestore()
10272 if ok == ""
10273 let ok="no"
10274 endif
10275 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010276 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010277 let all= 1
10278 endif
10279 endif
10280
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010281 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010282 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010283 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010284 else
10285 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010286 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10287" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010288 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010289" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010290
10291 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010292" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10293 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10294" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010295 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010296" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010297
10298 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010299 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010300 endif
10301 endif
10302 endif
10303
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010304 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010305" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010306 endif
10307 endif
10308
10309" call Dret("s:NetrwRemoteRmFile ".ok)
10310 return ok
10311endfun
10312
10313" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010314" s:NetrwRemoteRename: rename a remote file or directory {{{2
10315fun! s:NetrwRemoteRename(usrhost,path) range
10316" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10317
10318 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010319 let svpos = winsaveview()
10320" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010321 let ctr = a:firstline
10322 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10323
10324 " rename files given by the markfilelist
10325 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10326 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010327" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010328 if exists("subfrom")
10329 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010330" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010331 else
10332 call inputsave()
10333 let newname= input("Moving ".oldname." to : ",oldname)
10334 call inputrestore()
10335 if newname =~ '^s/'
10336 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10337 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10338 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010339" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010340 endif
10341 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010342
Bram Moolenaar446cb832008-06-24 21:56:24 +000010343 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010344 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010345 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010346 let oldname= s:ShellEscape(a:path.oldname)
10347 let newname= s:ShellEscape(a:path.newname)
10348" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010349 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010350 endif
10351
10352 endfor
10353 call s:NetrwUnMarkFile(1)
10354
10355 else
10356
10357 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010358 let keepsol= &l:sol
10359 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010360 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010361 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010362
10363 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010364" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010365
10366 call inputsave()
10367 let newname= input("Moving ".oldname." to : ",oldname)
10368 call inputrestore()
10369
10370 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10371 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10372 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010373 let oldname= s:ShellEscape(a:path.oldname)
10374 let newname= s:ShellEscape(a:path.newname)
10375" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010376 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010377 endif
10378
10379 let ctr= ctr + 1
10380 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010381 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382 endif
10383
10384 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010385 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010386" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10387 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388
10389" call Dret("NetrwRemoteRename")
10390endfun
10391
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010392" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010393" Local Directory Browsing Support: {{{1
10394" ==========================================
10395
10396" ---------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010397" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010398" Should accept: file://localhost/etc/fstab
10399" file:///etc/fstab
10400" file:///c:/WINDOWS/clock.avi
10401" file:///c|/WINDOWS/clock.avi
10402" file://localhost/c:/WINDOWS/clock.avi
10403" file://localhost/c|/WINDOWS/clock.avi
10404" file://c:/foo.txt
10405" file:///c:/foo.txt
10406" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010407fun! netrw#FileUrlEdit(fname)
10408" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010409 let fname = a:fname
10410 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010412 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010413" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010414 endif
10415 if (has("win32") || has("win95") || has("win64") || has("win16"))
10416 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010417" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010418 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010419" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010420 endif
10421 endif
10422 let fname2396 = netrw#RFC2396(fname)
10423 let fname2396e= fnameescape(fname2396)
10424 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
10425 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010426" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010427 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010428" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010429 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10430 endif
10431 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010432
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010433" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10434" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010435 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010436 exe 'NetrwKeepj keepalt edit '.plainfname
10437 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10438
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010439" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010440" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010441 exe "sil doau BufReadPost ".fname2396e
10442endfun
10443
10444" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010445" netrw#LocalBrowseCheck: {{{2
10446fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010447 " This function is called by netrwPlugin.vim's s:LocalBrowse(), s:NetrwRexplore(), and by <cr> when atop listed file/directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010448 " unfortunate interaction -- split window debugging can't be
10449 " used here, must use D-echoRemOn or D-echoTabOn -- the BufEnter
10450 " event triggers another call to LocalBrowseCheck() when attempts
10451 " to write to the DBG buffer are made.
10452 " The &ft == "netrw" test was installed because the BufEnter event
10453 " would hit when re-entering netrw windows, creating unexpected
10454 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaara6878372014-03-22 21:02:50 +010010455" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010456" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" 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 Moolenaarb0d45e72017-11-05 18:19:24 +010010458" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010459" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10460" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010461
Bram Moolenaar97d62492012-11-15 21:28:22 +010010462 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010463 if isdirectory(s:NetrwFile(a:dirname))
10464" 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 +010010465
Bram Moolenaar97d62492012-11-15 21:28:22 +010010466 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010467" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10468" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010469 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010470
Bram Moolenaar446cb832008-06-24 21:56:24 +000010471 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010472" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010473 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010474
Bram Moolenaar5c736222010-01-06 20:54:52 +010010475 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010476" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010477 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010478 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010479 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010480" 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 +010010481" call Dret("netrw#LocalBrowseCheck")
10482 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010483 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010484
Bram Moolenaar97d62492012-11-15 21:28:22 +010010485 " following code wipes out currently unused netrw buffers
10486 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10487 " AND IF the listing style is not a tree listing
10488 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010489" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010490 let ibuf = 1
10491 let buflast = bufnr("$")
10492 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010493 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10494 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010495 endif
10496 let ibuf= ibuf + 1
10497 endwhile
10498 endif
10499 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010500" 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>"))
10501" 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 +000010502 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010503" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010504endfun
10505
10506" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010507" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010508" performed any shell command. The idea is to cause all local-browsing
10509" buffers to be refreshed after a user has executed some shell command,
10510" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010511fun! s:LocalBrowseRefresh()
10512" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010513" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10514" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010515
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 " determine which buffers currently reside in a tab
10517 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010518" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010519 return
10520 endif
10521 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010522" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010523 return
10524 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010525 if exists("s:netrw_events") && s:netrw_events == 1
10526 " s:LocalFastBrowser gets called (indirectly) from a
10527 let s:netrw_events= 2
10528" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10529 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010530 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 let itab = 1
10532 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010533 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 while itab <= tabpagenr("$")
10535 let buftablist = buftablist + tabpagebuflist()
10536 let itab = itab + 1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010537 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010538 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010539" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10540" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10542 " | refresh any netrw window
10543 " | wipe out any non-displaying netrw buffer
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010544 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010545 let ibl = 0
10546 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010547" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010548 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10549 " wipe out any non-displaying netrw buffer
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010550 " (ibuf not shown in a current window AND
10551 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010552" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10553 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010554 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010555" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010556 continue
10557 elseif index(tabpagebuflist(),ibuf) != -1
10558 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010559" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010561 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010562 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10563 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10564 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10565 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010566" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010567 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10568 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10569 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010570 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571 endif
10572 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010573" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010574 endfor
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010010575" call Decho("restore window: win_gotoid(".curwinid.")")
10576 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010577 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578
Bram Moolenaara6878372014-03-22 21:02:50 +010010579" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580endfun
10581
10582" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010583" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10584"
10585" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010586" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010587" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10588" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010589" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010590"
10591" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10592" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010593" (re-using a buffer may not be as accurate)
10594"
10595" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
10596" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10597" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10598" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10599" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010600fun! s:LocalFastBrowser()
Bram Moolenaara6878372014-03-22 21:02:50 +010010601" call Dfunc("LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010602" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
10603" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "installed" : "not installed"),'~'.expand("<slnum>"))
10604" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010605
10606 " initialize browselist, a list of buffer numbers that the local browser has used
10607 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010608" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010609 let s:netrw_browselist= []
10610 endif
10611
10612 " append current buffer to fastbrowse list
10613 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010614" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010615 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010616" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010617 endif
10618
10619 " enable autocmd events to handle refreshing/removing local browser buffers
10620 " If local browse buffer is currently showing: refresh it
10621 " If local browse buffer is currently hidden : wipe it
10622 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10623 " =1 : medium speed, re-use directory listing for remote only
10624 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010625 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10626 let s:netrw_events= 1
10627 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010628 au!
10629 if (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010631 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010632 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010633" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010634 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010635 endif
10636 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010637
10638 " user must have changed fastbrowse to its fast setting, so remove
10639 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010640 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010641" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010642 unlet s:netrw_events
10643 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010644 au!
10645 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010646 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010647 endif
10648
10649" call Dret("LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
10650endfun
10651
10652" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010653" s:LocalListing: does the job of "ls" for local directories {{{2
10654fun! s:LocalListing()
10655" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
10657" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
10658" 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 +010010659
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010660" 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
10661" 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
10662" 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 +010010663
10664 " get the list of files contained in the current directory
10665 let dirname = b:netrw_curdir
10666 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010667 let filelist = s:NetrwGlob(dirname,"*",0)
10668 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010669" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010670
10671 if g:netrw_cygwin == 0 && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010672" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010673 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
10674 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010676 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010677" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010678 endif
10679
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010680" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010682" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010683
10684 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
10685 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10686 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010687" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
10688" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010689 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010690" 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 +010010691
10692 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010693" call Decho(" ",'~'.expand("<slnum>"))
10694" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010695
10696 if getftype(filename) == "link"
10697 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010698" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010699 let pfile= filename."@"
10700
10701 elseif getftype(filename) == "socket"
10702 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010703" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010704 let pfile= filename."="
10705
10706 elseif getftype(filename) == "fifo"
10707 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010708" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010709 let pfile= filename."|"
10710
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010711 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010712 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010713" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010714 let pfile= filename."/"
10715
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010716 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010717 if (has("win32") || has("win95") || has("win64") || has("win16"))
10718 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10719 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010720" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010721 let pfile= filename."*"
10722 else
10723 " normal file
10724 let pfile= filename
10725 endif
10726 elseif executable(filename)
10727 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010728" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010729 let pfile= filename."*"
10730 else
10731 " normal file
10732 let pfile= filename
10733 endif
10734
10735 else
10736 " normal file
10737 let pfile= filename
10738 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010739" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010740
10741 if pfile =~ '//$'
10742 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010743" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010744 endif
10745 let pfile= strpart(pfile,dirnamelen)
10746 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010747" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
10748" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010749
10750 if w:netrw_liststyle == s:LONGLIST
10751 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010752 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010753 let sz= s:NetrwHumanReadable(sz)
10754 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010755 let fsz = strpart(" ",1,15-strlen(sz)).sz
10756 let pfile= pfile."\t".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010757" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010758 endif
10759
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010760 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010761 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010762" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010763 let t = getftime(filename)
10764 let ft = strpart("000000000000000000",1,18-strlen(t)).t
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" call Decho("exe NetrwKeepj put ='".ft.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010766 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010767 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010768
10769 elseif g:netrw_sort_by =~ "^s"
10770 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010772 let sz = getfsize(filename)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010773 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010774 let sz= s:NetrwHumanReadable(sz)
10775 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010776 let fsz = strpart("000000000000000000",1,18-strlen(sz)).sz
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010777" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010778 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010779 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010780
10781 else
10782 " sort by name
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010783" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010784 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010010785 endif
10786 endfor
10787
10788 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010789 sil! NetrwKeepj g/^$/d
10790 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010791 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010792" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010793 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10794
10795" call Dret("s:LocalListing")
10796endfun
10797
10798" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010799" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10800fun! s:NetrwLocalExecute(cmd)
10801" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10802 let ykeep= @@
10803 " sanity check
10804 if !executable(a:cmd)
10805 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10806 let @@= ykeep
10807" call Dret("s:NetrwLocalExecute")
10808 return
10809 endif
10810
10811 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010812" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010813 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010814" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010815
10816 " strip any ansi escape sequences off
10817 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10818
10819 " show user the result(s)
10820 echomsg result
10821 let @@= ykeep
10822
10823" call Dret("s:NetrwLocalExecute")
10824endfun
10825
10826" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010827" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010828fun! s:NetrwLocalRename(path) range
10829" call Dfunc("NetrwLocalRename(path<".a:path.">)")
10830
10831 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010832 let ykeep = @@
10833 let ctr = a:firstline
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010834 let svpos = winsaveview()
10835" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010836
10837 " rename files given by the markfilelist
10838 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10839 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010840" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010841 if exists("subfrom")
10842 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010843" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 else
10845 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010846 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010847 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010848 if newname =~ ''
10849 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10850 let newname = substitute(newname,'^.*','','')
10851 elseif newname =~ ''
10852 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10853 let newname = substitute(newname,'[^/]*','','')
10854 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010855 if newname =~ '^s/'
10856 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10857 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010859 let newname = substitute(oldname,subfrom,subto,'')
10860 endif
10861 endif
10862 call rename(oldname,newname)
10863 endfor
10864 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010865
Bram Moolenaar97d62492012-11-15 21:28:22 +010010866 else
10867
10868 " attempt to rename files/directories
10869 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010870 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010871
10872 " sanity checks
10873 if line(".") < w:netrw_bannercnt
10874 let ctr= ctr + 1
10875 continue
10876 endif
10877 let curword= s:NetrwGetWord()
10878 if curword == "./" || curword == "../"
10879 let ctr= ctr + 1
10880 continue
10881 endif
10882
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010883 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010884 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010885" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010886
10887 call inputsave()
10888 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10889 call inputrestore()
10890
10891 call rename(oldname,newname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010893
10894 let ctr= ctr + 1
10895 endwhile
10896 endif
10897
10898 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010900 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010901" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10902 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010903 let @@= ykeep
10904
10905" call Dret("NetrwLocalRename")
10906endfun
10907
10908" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010909" s:NetrwLocalRm: {{{2
10910fun! s:NetrwLocalRm(path) range
10911" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010913
10914 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010915 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010916 let ret = 0
10917 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010918 let svpos = winsaveview()
10919" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010920
10921 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10922 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010923" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010924 for fname in s:netrwmarkfilelist_{bufnr("%")}
10925 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010926 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010927 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010928 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010929 let all= 1
10930 endif
10931 endfor
10932 call s:NetrwUnMarkFile(1)
10933
10934 else
10935 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010937
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010938 let keepsol= &l:sol
10939 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010940 let ctr = a:firstline
10941 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010942 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010943
10944 " sanity checks
10945 if line(".") < w:netrw_bannercnt
10946 let ctr= ctr + 1
10947 continue
10948 endif
10949 let curword= s:NetrwGetWord()
10950 if curword == "./" || curword == "../"
10951 let ctr= ctr + 1
10952 continue
10953 endif
10954 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010955 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010956 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010957 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010958 let all= 1
10959 endif
10960 let ctr= ctr + 1
10961 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010962 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010963 endif
10964
10965 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010967 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010968 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010969" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10970 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010972 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010973
10974" call Dret("s:NetrwLocalRm")
10975endfun
10976
10977" ---------------------------------------------------------------------
10978" s:NetrwLocalRmFile: remove file fname given the path {{{2
10979" Give confirmation prompt unless all==1
10980fun! s:NetrwLocalRmFile(path,fname,all)
10981" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010982
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 let all= a:all
10984 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010985 NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986 let rmfile= s:NetrwFile(s:ComposePath(a:path,a:fname))
10987" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010988
10989 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10990 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010991" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010992 if !all
10993 echohl Statement
10994 call inputsave()
10995 let ok= input("Confirm deletion of file<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10996 call inputrestore()
10997 echohl NONE
10998 if ok == ""
10999 let ok="no"
11000 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011001" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011002 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011003" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011004 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011005 let all= 1
11006 endif
11007 endif
11008
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011009 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011010 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011011" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011012 endif
11013
11014 else
11015 " attempt to remove directory
11016 if !all
11017 echohl Statement
11018 call inputsave()
11019 let ok= input("Confirm deletion of directory<".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
11020 call inputrestore()
11021 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11022 if ok == ""
11023 let ok="no"
11024 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011025 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011026 let all= 1
11027 endif
11028 endif
11029 let rmfile= substitute(rmfile,'[\/]$','','e')
11030
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011031 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011032 if v:version < 704 || (v:version == 704 && !has("patch1107"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011033" " call Decho("1st attempt: system(netrw#WinPath(".g:netrw_localrmdir.') '.s:ShellEscape(rmfile).')','~'.expand("<slnum>"))
11034 call system(netrw#WinPath(g:netrw_localrmdir).' '.s:ShellEscape(rmfile))
11035" " call Decho("v:shell_error=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011036
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011037 if v:shell_error != 0
11038" " call Decho("2nd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11039 let errcode= s:NetrwDelete(rmfile)
11040" " call Decho("errcode=".errcode,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011041
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011042 if errcode != 0
11043 if has("unix")
11044" " call Decho("3rd attempt to remove directory<".rmfile.">",'~'.expand("<slnum>"))
11045 call system("rm ".s:ShellEscape(rmfile))
11046 if v:shell_error != 0 && !exists("g:netrw_quiet")
11047 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",34)
11048 let ok="no"
11049 endif
11050 elseif !exists("g:netrw_quiet")
11051 call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",35)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011052 let ok="no"
11053 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011054 endif
11055 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011056 else
11057 if delete(rmfile,"d")
11058 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
11059 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011060 endif
11061 endif
11062 endif
11063
11064" call Dret("s:NetrwLocalRmFile ".ok)
11065 return ok
11066endfun
11067
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011068" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011069" Support Functions: {{{1
11070
Bram Moolenaar488c6512005-08-11 20:09:58 +000011071" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011072" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11073" 0: marked file list of current buffer
11074" 1: marked file target
11075fun! netrw#Access(ilist)
11076 if a:ilist == 0
11077 if exists("s:netrwmarkfilelist_".bufnr('%'))
11078 return s:netrwmarkfilelist_{bufnr('%')}
11079 else
11080 return "no-list-buf#".bufnr('%')
11081 endif
11082 elseif a:ilist == 1
11083 return s:netrwmftgt
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011084 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011085endfun
11086
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011087" ---------------------------------------------------------------------
11088" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11089fun! netrw#Call(funcname,...)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011090 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011091endfun
11092
Bram Moolenaara6878372014-03-22 21:02:50 +010011093" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011094" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11095" I expect this function to be used in
11096" :PChkAssert netrw#Expose("netrwmarkfilelist")
11097" for example.
11098fun! netrw#Expose(varname)
11099" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011100 if exists("s:".a:varname)
11101 exe "let retval= s:".a:varname
11102 if exists("g:netrw_pchk")
11103 if type(retval) == 3
11104 let retval = copy(retval)
11105 let i = 0
11106 while i < len(retval)
11107 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11108 let i = i + 1
11109 endwhile
11110 endif
11111" call Dret("netrw#Expose ".string(retval))
11112 return string(retval)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011113 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011114 else
11115 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116 endif
11117
11118" call Dret("netrw#Expose ".string(retval))
11119 return retval
11120endfun
11121
11122" ---------------------------------------------------------------------
11123" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11124fun! netrw#Modify(varname,newvalue)
11125" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11126 exe "let s:".a:varname."= ".string(a:newvalue)
11127" call Dret("netrw#Modify")
11128endfun
11129
11130" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011131" netrw#RFC2396: converts %xx into characters {{{2
11132fun! netrw#RFC2396(fname)
11133" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
11134 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=nr2char("0x".submatch(1))','ge')," \t")
11135" call Dret("netrw#RFC2396 ".fname)
11136 return fname
11137endfun
11138
11139" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" netrw#UserMaps: supports user-specified maps {{{2
11141" see :help function()
11142"
11143" g:Netrw_UserMaps is a List with members such as:
11144" [[keymap sequence, function reference],...]
11145"
11146" The referenced function may return a string,
11147" refresh : refresh the display
11148" -other- : this string will be executed
11149" or it may return a List of strings.
11150"
11151" Each keymap-sequence will be set up with a nnoremap
11152" to invoke netrw#UserMaps(islocal).
11153" Related functions:
11154" netrw#Expose(varname) -- see s:varname variables
11155" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11156" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11157fun! netrw#UserMaps(islocal)
11158" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11159" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11160
11161 " set up usermaplist
11162 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11163" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11164 for umap in g:Netrw_UserMaps
11165" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11166" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11167 " if umap[0] is a string and umap[1] is a string holding a function name
11168 if type(umap[0]) == 1 && type(umap[1]) == 1
11169" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11170 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11171 else
11172 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11173 endif
11174 endfor
11175 endif
11176" call Dret("netrw#UserMaps")
11177endfun
11178
11179" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011180" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11181fun! netrw#WinPath(path)
11182" call Dfunc("netrw#WinPath(path<".a:path.">)")
11183 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && (has("win32") || has("win95") || has("win64") || has("win16"))
11184 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011185 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011186 " remove trailing slash (Win95)
11187 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11188 " remove escaped spaces
11189 let path = substitute(path, '\ ', ' ', 'g')
11190 " convert slashes to backslashes
11191 let path = substitute(path, '/', '\', 'g')
11192 else
11193 let path= a:path
11194 endif
11195" call Dret("netrw#WinPath <".path.">")
11196 return path
11197endfun
11198
11199" ---------------------------------------------------------------------
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011200" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11201" cb : bl2mf=0 add marked files to buffer list
11202" cB : bl2mf=1 use bufferlist to mark files
11203" (mnemonic: cb = copy (marked files) to buffer list)
11204fun! s:NetrwBadd(islocal,bl2mf)
11205" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11206 if a:bl2mf
11207 " cB: add buffer list to marked files
11208 redir => bufl
11209 ls
11210 redir END
11211 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11212 for fname in bufl
11213 call s:NetrwMarkFile(a:islocal,fname)
11214 endfor
11215 else
11216 " cb: add marked files to buffer list
11217 for fname in s:netrwmarkfilelist_{bufnr("%")}
11218" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11219 exe "badd ".fnameescape(fname)
11220 endfor
11221 let curbufnr = bufnr("%")
11222 let curdir = s:NetrwGetCurdir(a:islocal)
11223 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11224 endif
11225" call Dret("s:NetrwBadd")
11226endfun
11227
11228" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011229" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11230fun! s:ComposePath(base,subdir)
11231" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11232
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011233 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011234" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011235 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011236 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011237 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011238 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011239 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011240 endif
11241
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011242 " COMBAK: test on windows with changing to root directory: :e C:/
11243 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011244" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011245 let ret= a:subdir
11246
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011247 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && (has("win32") || has("win95") || has("win64") || has("win16"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011248" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011249 if a:base =~ '[/\\]$'
11250 let ret= a:base.a:subdir
11251 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011252 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011253 endif
11254
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011255 elseif a:base =~ '^\a\{3,}://'
11256" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011257 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11258 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11259 if a:subdir == '../'
11260 if curpath =~ '[^/]/[^/]\+/$'
11261 let curpath= substitute(curpath,'[^/]\+/$','','')
11262 else
11263 let curpath=""
11264 endif
11265 let ret= urlbase.curpath
11266 else
11267 let ret= urlbase.curpath.a:subdir
11268 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011269" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11270" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11271" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011272
11273 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011274" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011275 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11276 if a:base =~ '^//'
11277 " keeping initial '//' for the benefit of network share listing support
11278 let ret= '/'.ret
11279 endif
11280 let ret= simplify(ret)
11281 endif
11282
11283" call Dret("s:ComposePath ".ret)
11284 return ret
11285endfun
11286
11287" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011288" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11289" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11290fun! s:DeleteBookmark(fname)
11291" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11292 call s:MergeBookmarks()
11293
11294 if exists("g:netrw_bookmarklist")
11295 let indx= index(g:netrw_bookmarklist,a:fname)
11296 if indx == -1
11297 let indx= 0
11298 while indx < len(g:netrw_bookmarklist)
11299 if g:netrw_bookmarklist[indx] =~ a:fname
11300 call remove(g:netrw_bookmarklist,indx)
11301 let indx= indx - 1
11302 endif
11303 let indx= indx + 1
11304 endwhile
11305 else
11306 " remove exact match
11307 call remove(g:netrw_bookmarklist,indx)
11308 endif
11309 endif
11310
11311" call Dret("s:DeleteBookmark")
11312endfun
11313
11314" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011315" s:FileReadable: o/s independent filereadable {{{2
11316fun! s:FileReadable(fname)
11317" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11318
11319 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011320 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011321 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011322 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011323 endif
11324
11325" call Dret("s:FileReadable ".ret)
11326 return ret
11327endfun
11328
11329" ---------------------------------------------------------------------
11330" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11331" Places correct suffix on end of temporary filename,
11332" using the suffix provided with fname
11333fun! s:GetTempfile(fname)
11334" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11335
11336 if !exists("b:netrw_tmpfile")
11337 " get a brand new temporary filename
11338 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011339" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011340
Bram Moolenaarc236c162008-07-13 17:41:49 +000011341 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011342" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011343
Bram Moolenaar9964e462007-05-05 17:54:07 +000011344 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011345 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11346" 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 +010011347 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011348" call Dret("s:GetTempfile getcwd<".getcwd().">")
11349 return ""
11350 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011351
Bram Moolenaar9964e462007-05-05 17:54:07 +000011352 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011353 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011354" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011355
Bram Moolenaar9964e462007-05-05 17:54:07 +000011356 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011357 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011358 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011359 elseif has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011360 if !exists("+shellslash") || !&ssl
11361 let tmpfile = substitute(tmpfile,'/','\','g')
11362 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011363 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011364 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011365 endif
11366 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011367" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011368 else
11369 " re-use temporary filename
11370 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011371" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011372 endif
11373
11374 " use fname's suffix for the temporary file
11375 if a:fname != ""
11376 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011377" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011378 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011379 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011380 elseif a:fname =~ '.txz$'
11381 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011382 else
11383 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11384 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011385" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011386 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011387" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011388 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011389" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011390 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11391 endif
11392 endif
11393
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011394" 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 +000011395" call Dret("s:GetTempfile <".tmpfile.">")
11396 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011397endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011398
11399" ---------------------------------------------------------------------
11400" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011401" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011402fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011403" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011404 if s:user == ""
11405 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11406 else
11407 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11408 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011409 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011410 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011411 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011412 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011413 else
11414 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11415 endif
11416" call Dret("s:MakeSshCmd <".sshcmd.">")
11417 return sshcmd
11418endfun
11419
11420" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011421" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11422fun! s:MakeBookmark(fname)
11423" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11424
11425 if !exists("g:netrw_bookmarklist")
11426 let g:netrw_bookmarklist= []
11427 endif
11428
11429 if index(g:netrw_bookmarklist,a:fname) == -1
11430 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011431 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011432 call add(g:netrw_bookmarklist,a:fname.'/')
11433 elseif a:fname !~ '/'
11434 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11435 else
11436 call add(g:netrw_bookmarklist,a:fname)
11437 endif
11438 call sort(g:netrw_bookmarklist)
11439 endif
11440
11441" call Dret("s:MakeBookmark")
11442endfun
11443
11444" ---------------------------------------------------------------------
11445" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11446fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011447" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011448 " get bookmarks from .netrwbook file
11449 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011450 if filereadable(s:NetrwFile(savefile))
11451" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011452 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011453" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011454 NetrwKeepj call delete(savefile)
11455 endif
11456" call Dret("s:MergeBookmarks")
11457endfun
11458
11459" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011460" s:NetrwBMShow: {{{2
11461fun! s:NetrwBMShow()
11462" call Dfunc("s:NetrwBMShow()")
11463 redir => bmshowraw
11464 menu
11465 redir END
11466 let bmshowlist = split(bmshowraw,'\n')
11467 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011468 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011469 if bmshowfuncs != []
11470 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011471 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011472 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011473 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011474 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011475 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011476" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11477endfun
11478
11479" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011480" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
11481fun! s:NetrwCursor()
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011482 if !exists("w:netrw_liststyle")
11483 let w:netrw_liststyle= g:netrw_liststyle
11484 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011485" 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 +020011486
11487 if &ft != "netrw"
11488 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11489 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011490" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011491 let &l:cursorline = s:netrw_usercul
11492 let &l:cursorcolumn = s:netrw_usercuc
11493
11494 elseif g:netrw_cursor == 4
11495 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011496" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011497 setl cursorline
11498 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011499
11500 elseif g:netrw_cursor == 3
11501 " thin-long-tree: cursorline, user's cursorcolumn
11502 " wide : cursorline, cursorcolumn
11503 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011504" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011505 setl cursorline
11506 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011507 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011508" 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 +020011509 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011510 let &l:cursorcolumn = s:netrw_usercuc
11511 endif
11512
11513 elseif g:netrw_cursor == 2
11514 " thin-long-tree: cursorline, user's cursorcolumn
11515 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011516" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011517 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar15146672011-10-20 22:22:38 +020011518 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011519
11520 elseif g:netrw_cursor == 1
11521 " thin-long-tree: user's cursorline, user's cursorcolumn
11522 " wide : cursorline, user's cursorcolumn
11523 let &l:cursorcolumn = s:netrw_usercuc
11524 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011525" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011526 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011527 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011528" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011529 let &l:cursorline = s:netrw_usercul
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011530 endif
11531
11532 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011533 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011534" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011535 let &l:cursorline = s:netrw_usercul
11536 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011537 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011538
11539" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011540endfun
11541
11542" ---------------------------------------------------------------------
11543" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11544fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011545" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011546 if exists("s:netrw_usercul")
11547 let &l:cursorline = s:netrw_usercul
11548 endif
11549 if exists("s:netrw_usercuc")
11550 let &l:cursorcolumn = s:netrw_usercuc
11551 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011552" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11553endfun
11554
11555" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011556" s:NetrwDelete: Deletes a file. {{{2
11557" Uses Steve Hall's idea to insure that Windows paths stay
11558" acceptable. No effect on Unix paths.
11559" Examples of use: let result= s:NetrwDelete(path)
11560fun! s:NetrwDelete(path)
11561" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11562
Bram Moolenaar5c736222010-01-06 20:54:52 +010011563 let path = netrw#WinPath(a:path)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011564 if !g:netrw_cygwin && (has("win32") || has("win95") || has("win64") || has("win16"))
11565 if exists("+shellslash")
11566 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011567 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011568 let result = delete(path)
11569 let &shellslash = sskeep
11570 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011571" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011572 let result= delete(path)
11573 endif
11574 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011575" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011576 let result= delete(path)
11577 endif
11578 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011579 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011580 endif
11581
11582" call Dret("s:NetrwDelete ".result)
11583 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011584endfun
11585
11586" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011587" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011588fun! s:NetrwEnew(...)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011589" call Dfunc("s:NetrwEnew() a:0=".a:0." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011590" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011591
Bram Moolenaar446cb832008-06-24 21:56:24 +000011592 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011593" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011594 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11595 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11596 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11597 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11598 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11599 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11600 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11601 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11602 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11603 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11604 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11605 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11606 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11607 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11608 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11609 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11610
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011611 NetrwKeepj call s:NetrwOptionRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011612" call Decho("generate a buffer with NetrwKeepj keepalt enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011613 " when tree listing uses file TreeListing... a new buffer is made.
11614 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011615 " COMBAK: this causes a problem, see P43
11616" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011617 let netrw_keepdiff= &l:diff
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011618 noswapfile NetrwKeepj keepalt enew!
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011619 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011620" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011621 NetrwKeepj call s:NetrwOptionSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011622
Bram Moolenaar446cb832008-06-24 21:56:24 +000011623 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011624" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011625 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11626 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11627 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11628 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11629 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11630 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11631 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11632 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11633 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11634 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11635 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11636 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11637 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11638 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11639 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11640 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11641
Bram Moolenaar5c736222010-01-06 20:54:52 +010011642 if a:0 > 0
11643 let b:netrw_curdir= a:1
11644 if b:netrw_curdir =~ '/$'
11645 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011646 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011647 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011648 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011649 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11650 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011651 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011652 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011653 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011654 endif
11655 endif
11656
Bram Moolenaar8d043172014-01-23 14:24:41 +010011657" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011658endfun
11659
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011660" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011661" s:NetrwExe: executes a string using "!" {{{2
11662fun! s:NetrwExe(cmd)
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011663" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011664 if has("win32") && &shell !~? 'cmd' && !g:netrw_cygwin
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011665" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011666 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11667 set shell& shellcmdflag& shellxquote& shellxescape&
11668 set shellquote& shellpipe& shellredir& shellslash&
11669 exe a:cmd
11670 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11671 else
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011672" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011673 exe a:cmd
11674 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011675" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011676endfun
11677
11678" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011679" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11680fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011681 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011682" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011683 let curbuf = bufnr("%")
11684 let curwin = winnr()
11685 let iwin = 1
11686 while iwin <= winnr("$")
11687 exe iwin."wincmd w"
11688 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11689 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11690 let winvars= w:
11691 break
11692 endif
11693 let iwin= iwin + 1
11694 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011695 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011696 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011697" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011698 for k in keys(winvars)
11699 let w:{k}= winvars[k]
11700 endfor
11701 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011702" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011703 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011704endfun
11705
Bram Moolenaara6878372014-03-22 21:02:50 +010011706" ---------------------------------------------------------------------
11707" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011708" Returns: 0=success
11709" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011710fun! s:NetrwLcd(newdir)
11711" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
11712
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011713 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011714 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011715 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011716 catch /^Vim\%((\a\+)\)\=:E344/
11717 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11718 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011720 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11721 " forward slashes by earlier code; so check for both.
11722 if (has("win32") || has("win95") || has("win64") || has("win16")) && !g:netrw_cygwin
11723 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11724 let dirname = '\'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011725 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011726 endif
11727 endif
11728 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011729 let err472= 1
11730 endtry
11731
11732 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011733 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11734 if exists("w:netrw_prvdir")
11735 let a:newdir= w:netrw_prvdir
11736 else
11737 call s:NetrwOptionRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011738" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011739 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011740" 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 +010011741 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011742 endif
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011743" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11744 return -1
11745 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011746
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011747" call Dret("s:NetrwLcd 0")
11748 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011749endfun
11750
Bram Moolenaar9964e462007-05-05 17:54:07 +000011751" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011752" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11753" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11754fun! s:NetrwSaveWordPosn()
11755" call Dfunc("NetrwSaveWordPosn()")
11756 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11757" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11758endfun
11759
11760" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011761" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11762" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11763fun! s:NetrwHumanReadable(sz)
11764" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11765
11766 if g:netrw_sizestyle == 'h'
11767 if a:sz >= 1000000000
11768 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11769 elseif a:sz >= 10000000
11770 let sz = printf("%d",a:sz/1000000)."m"
11771 elseif a:sz >= 1000000
11772 let sz = printf("%.1f",a:sz/1000000.0)."m"
11773 elseif a:sz >= 10000
11774 let sz = printf("%d",a:sz/1000)."k"
11775 elseif a:sz >= 1000
11776 let sz = printf("%.1f",a:sz/1000.0)."k"
11777 else
11778 let sz= a:sz
11779 endif
11780
11781 elseif g:netrw_sizestyle == 'H'
11782 if a:sz >= 1073741824
11783 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11784 elseif a:sz >= 10485760
11785 let sz = printf("%d",a:sz/1048576)."M"
11786 elseif a:sz >= 1048576
11787 let sz = printf("%.1f",a:sz/1048576.0)."M"
11788 elseif a:sz >= 10240
11789 let sz = printf("%d",a:sz/1024)."K"
11790 elseif a:sz >= 1024
11791 let sz = printf("%.1f",a:sz/1024.0)."K"
11792 else
11793 let sz= a:sz
11794 endif
11795
11796 else
11797 let sz= a:sz
11798 endif
11799
11800" call Dret("s:NetrwHumanReadable ".sz)
11801 return sz
11802endfun
11803
11804" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011805" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11806" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11807fun! s:NetrwRestoreWordPosn()
11808" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011809 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011810" call Dret("NetrwRestoreWordPosn")
11811endfun
11812
11813" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011814" s:RestoreBufVars: {{{2
11815fun! s:RestoreBufVars()
11816" call Dfunc("s:RestoreBufVars()")
11817
11818 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11819 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11820 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11821 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11822 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11823 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11824
11825" call Dret("s:RestoreBufVars")
11826endfun
11827
11828" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011829" s:RemotePathAnalysis: {{{2
11830fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011831" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011832
Bram Moolenaara6878372014-03-22 21:02:50 +010011833 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011834 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011835 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011836 let s:user = substitute(a:dirname,dirpat,'\3','')
11837 let s:machine = substitute(a:dirname,dirpat,'\4','')
11838 let s:port = substitute(a:dirname,dirpat,'\5','')
11839 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011840 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011841 if s:machine =~ '@'
11842 let dirpat = '^\(.*\)@\(.\{-}\)$'
11843 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11844 let s:machine = substitute(s:machine,dirpat,'\2','')
11845 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011846
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011847" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11848" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11849" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11850" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11851" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11852" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011853
11854" call Dret("s:RemotePathAnalysis")
11855endfun
11856
11857" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011858" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11859" Returns status
11860" Runs system() on
11861" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011862" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011863fun! s:RemoteSystem(cmd)
11864" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11865 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011866 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 +000011867 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011868 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011869 else
11870 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11871 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11872 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011873 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011874 else
11875 let cmd= cmd.' '
11876 endif
11877 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011878" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011879 let ret= system(cmd)
11880 endif
11881" call Dret("s:RemoteSystem ".ret)
11882 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011883endfun
11884
11885" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011886" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011887fun! s:RestoreWinVars()
11888" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011889 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011890 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11891 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11892 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11893 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11894 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11895 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11896 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11897 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11898 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11899 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11900 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11901 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011902 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11903 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011904 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11905 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11906 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11907" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011908endfun
11909
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011910" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011911" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11912"
11913" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11914" is true) and a command, :Rexplore, which call this function.
11915"
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011916" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011917"
11918" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011919fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011920 if exists("s:netrwdrag")
11921 return
11922 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011923" 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 +010011924" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11925" 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 +010011926
11927 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011928 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011929" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011930 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011931 unlet w:netrw_rexfile
11932" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011933 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011934" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011935" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11936" 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 +020011937 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011938
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011939 " ---------------------------
11940 " :Rex issued while in a file
11941 " ---------------------------
11942
Bram Moolenaara6878372014-03-22 21:02:50 +010011943 " record current file so :Rex can return to it from netrw
11944 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011945" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011946
11947 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011948" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011949 return
11950 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011951" 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 +020011952 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011953 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011954 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011955 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011956 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011957 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011958 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011959 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011960 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011961" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11962 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011963" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11964 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011965 if exists("s:rexposn_".bufnr('%'))
11966 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011967 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011968 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011970 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011971
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010011972 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11973 if exists("s:explore_match")
11974 exe "2match netrwMarkFile /".s:explore_match."/"
11975 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011976 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011977
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011978" 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 +010011979" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011980endfun
11981
11982" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011983" s:SaveBufVars: save selected b: variables to s: variables {{{2
11984" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011985fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011986" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011987
11988 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11989 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11990 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11991 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11992 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11993 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11994
11995" call Dret("s:SaveBufVars")
11996endfun
11997
11998" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011999" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12000fun! s:SavePosn(posndict)
12001" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12002
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010012003 if !exists("a:posndict[bufnr('%')]")
12004 let a:posndict[bufnr("%")]= []
12005 endif
12006" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12007 call add(a:posndict[bufnr("%")],winsaveview())
12008" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012009
12010" call Dret("s:SavePosn posndict")
12011 return a:posndict
12012endfun
12013
12014" ---------------------------------------------------------------------
12015" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12016fun! s:RestorePosn(posndict)
12017" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010012018 if exists("a:posndict")
12019 if has_key(a:posndict,bufnr("%"))
12020" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12021 let posnlen= len(a:posndict[bufnr("%")])
12022 if posnlen > 0
12023 let posnlen= posnlen - 1
12024" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12025 call winrestview(a:posndict[bufnr("%")][posnlen])
12026 call remove(a:posndict[bufnr("%")],posnlen)
12027" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12028 endif
12029 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012030 endif
12031" call Dret("s:RestorePosn")
12032endfun
12033
12034" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012035" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012036fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012037" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012038 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12039 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12040 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12041 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12042 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12043 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12044 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12045 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12046 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12047 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12048 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12049 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12050 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12051 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12052 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12053 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12054 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12055 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12056" call Dret("s:SaveWinVars")
12057endfun
12058
12059" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012060" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012061" To allow separate windows to have their own activities, such as
12062" Explore **/pattern, several variables have been made window-oriented.
12063" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012064" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012065" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012066fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012067" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012068 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12069 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12070 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12071 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12072 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12073 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12074 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12075 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12076 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12077 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12078" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012079endfun
12080
12081" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012082" s:SetRexDir: set directory for :Rexplore {{{2
12083fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012084" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012085 let w:netrw_rexdir = a:dirname
12086 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012087 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012088" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12089" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012090" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012091" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012092" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012093endfun
12094
12095" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012096" s:ShowLink: used to modify thin and tree listings to show links {{{2
12097fun! s:ShowLink()
12098" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012099" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12100" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012101 if exists("b:netrw_curdir")
12102 norm! $?\a
12103 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12104 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012105" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12106" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12107" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12108 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012109 let dirlen = strlen(b:netrw_curdir)
12110 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012111" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012112 endif
12113 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012114" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12115" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012116 setl noro ma
12117 call setline(".",modline)
12118 setl ro noma nomod
12119 endif
12120" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12121endfun
12122
12123" ---------------------------------------------------------------------
12124" s:ShowStyle: {{{2
12125fun! s:ShowStyle()
12126 if !exists("w:netrw_liststyle")
12127 let liststyle= g:netrw_liststyle
12128 else
12129 let liststyle= w:netrw_liststyle
12130 endif
12131 if liststyle == s:THINLIST
12132 return s:THINLIST.":thin"
12133 elseif liststyle == s:LONGLIST
12134 return s:LONGLIST.":long"
12135 elseif liststyle == s:WIDELIST
12136 return s:WIDELIST.":wide"
12137 elseif liststyle == s:TREELIST
12138 return s:TREELIST.":tree"
12139 else
12140 return 'n/a'
12141 endif
12142endfun
12143
12144" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012145" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12146" Solution from Nicolai Weibull, vim docs (:help strlen()),
12147" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012148fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012149" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12150
12151 if v:version >= 703 && exists("*strdisplaywidth")
12152 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012153
Bram Moolenaar8d043172014-01-23 14:24:41 +010012154 elseif type(g:Align_xstrlen) == 1
12155 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12156 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012157
Bram Moolenaar8d043172014-01-23 14:24:41 +010012158 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012159 " number of codepoints (Latin a + combining circumflex is two codepoints)
12160 " (comment from TM, solution from NW)
12161 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012162
Bram Moolenaar8d043172014-01-23 14:24:41 +010012163 elseif g:Align_xstrlen == 2
12164 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012165 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12166 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012167 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012168
Bram Moolenaar8d043172014-01-23 14:24:41 +010012169 elseif g:Align_xstrlen == 3
12170 " virtual length (counting, for instance, tabs as anything between 1 and
12171 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012172 " preceded by lam, one otherwise, etc.)
12173 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012174 let modkeep= &l:mod
12175 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012176 call setline(line("."),a:x)
12177 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012178 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012179 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012180 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012181
Bram Moolenaar446cb832008-06-24 21:56:24 +000012182 else
12183 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012184 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012185 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012186" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012187 return ret
12188endfun
12189
12190" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012191" s:ShellEscape: shellescape(), or special windows handling {{{2
12192fun! s:ShellEscape(s, ...)
12193 if (has('win32') || has('win64')) && $SHELL == '' && &shellslash
12194 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12195 endif
12196 let f = a:0 > 0 ? a:1 : 0
12197 return shellescape(a:s, f)
12198endfun
12199
12200" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012201" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012202fun! s:TreeListMove(dir)
12203" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012204 let curline = getline('.')
12205 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12206 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12207 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12208 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12209 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12210 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12211" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12212" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12213" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12214" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12215" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12216 " COMBAK : need to handle when on a directory
12217 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012218 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012219 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012220 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012221 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012222" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012223 elseif a:dir == '[]' && nxtline != ''
12224 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012225" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012226 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12227 if nl != 0
12228 NetrwKeepj norm! k
12229 else
12230 NetrwKeepj norm! G
12231 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012232" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012233 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012234 endif
12235
12236" call Dret("s:TreeListMove")
12237endfun
12238
12239" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012240" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12241" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12242" can't be called except via emenu. But due to locale, that menu line may not be called
12243" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12244fun! s:UpdateBuffersMenu()
12245" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012246 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012247 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012248 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012249 catch /^Vim\%((\a\+)\)\=:E/
12250 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012251 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012252 endtry
12253 endif
12254" call Dret("s:UpdateBuffersMenu")
12255endfun
12256
12257" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012258" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012259" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012260fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012261" call Dfunc("s:UseBufWinVars()")
12262 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012263 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12264 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12265 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12266 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12267 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12268 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12269 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12270 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12271 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 +000012272" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012273endfun
12274
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012275" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012276" s:UserMaps: supports user-defined UserMaps {{{2
12277" * calls a user-supplied funcref(islocal,curdir)
12278" * interprets result
12279" See netrw#UserMaps()
12280fun! s:UserMaps(islocal,funcname)
12281" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12282
12283 if !exists("b:netrw_curdir")
12284 let b:netrw_curdir= getcwd()
12285 endif
12286 let Funcref = function(a:funcname)
12287 let result = Funcref(a:islocal)
12288
12289 if type(result) == 1
12290 " if result from user's funcref is a string...
12291" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12292 if result == "refresh"
12293" call Decho("refreshing display",'~'.expand("<slnum>"))
12294 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12295 elseif result != ""
12296" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12297 exe result
12298 endif
12299
12300 elseif type(result) == 3
12301 " if result from user's funcref is a List...
12302" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12303 for action in result
12304 if action == "refresh"
12305" call Decho("refreshing display",'~'.expand("<slnum>"))
12306 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12307 elseif action != ""
12308" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12309 exe action
12310 endif
12311 endfor
12312 endif
12313
12314" call Dret("s:UserMaps")
12315endfun
12316
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010012317" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012318" Settings Restoration: {{{1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010012319" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012320let &cpo= s:keepcpo
12321unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012322
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010012323" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012324" Modelines: {{{1
Bram Moolenaarb0d45e72017-11-05 18:19:24 +010012325" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012326" vim:ts=8 fdm=marker