blob: fef151a641aa41975cce85b352b9d8c9703df993 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" netrw.vim: Handles file transfer and remote directory listing across
2" AUTOLOAD SECTION
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Date: May 03, 2023
Christian Brabandtcb0c1132023-11-21 18:48:16 +00005" Version: 173a
Travis Sheltone34d0e32024-07-30 21:08:56 +02006" Last Change: {{{1
Christian Brabandtcb0c1132023-11-21 18:48:16 +00007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
K.Takata8750e3c2023-11-22 18:20:01 +09008" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
Travis Sheltone34d0e32024-07-30 21:08:56 +020027" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010028" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000029" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010030" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000031" Permission is hereby granted to use and distribute this code,
32" with or without modifications, provided that this copyright
33" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000034" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000035" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000036" expressed or implied. By using this plugin, you agree that
37" in no event will the copyright holder be liable for any damages
38" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010039"
40" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
41" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
42"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020043"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000044"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000045" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000046" (James 1:22 RSV)
47" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000048" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000049if &cp || exists("g:loaded_netrw")
50 finish
51endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020052
53" Check that vim has patches that netrw requires.
54" Patches needed for v7.4: 1557, and 213.
55" (netrw will benefit from vim's having patch#656, too)
56let s:needspatches=[1557,213]
57if exists("s:needspatches")
58 for ptch in s:needspatches
59 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
60 if !exists("s:needpatch{ptch}")
61 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
62 endif
63 let s:needpatch{ptch}= 1
64 finish
65 endif
66 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020067endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020068
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010069let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000070
Bram Moolenaar1afcace2005-11-25 19:54:28 +000071let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010072setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020073"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010074"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010075"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000077" ======================
78" Netrw Variables: {{{1
79" ======================
80
Bram Moolenaar071d4272004-06-13 20:20:40 +000081" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020082" netrw#ErrorMsg: {{{2
83" 0=note = s:NOTE
84" 1=warning = s:WARNING
85" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010086" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
87" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
88" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010089" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +020090fun! netrw#ErrorMsg(level,msg,errnum)
91" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
92
93 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +020094" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +020095 return
96 endif
97
98 if a:level == 1
99 let level= "**warning** (netrw) "
100 elseif a:level == 2
101 let level= "**error** (netrw) "
102 else
103 let level= "**note** (netrw) "
104 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100105" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200106
Damienb4d11642024-08-15 22:00:45 +0200107 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200108 " use popup window
109 if type(a:msg) == 3
110 let msg = [level]+a:msg
111 else
112 let msg= level.a:msg
113 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200114 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200115 let s:popuperr_text= ""
116 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200117 " (default) netrw creates a one-line window to show error/warning
118 " messages (reliably displayed)
119
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100120 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200121 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100122" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200123
124 " getting messages out reliably is just plain difficult!
125 " This attempt splits the current window, creating a one line window.
126 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100127" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200128 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100129" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200130 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100131 if type(a:msg) == 3
132 for msg in a:msg
133 NetrwKeepj call setline(line("$")+1,level.msg)
134 endfor
135 else
136 NetrwKeepj call setline(line("$")+1,level.a:msg)
137 endif
138 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200139 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100140" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200141 bo 1split
142 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200143 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200144 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100145 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100146" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200147 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100148 if type(a:msg) == 3
149 for msg in a:msg
150 NetrwKeepj call setline(line("$")+1,level.msg)
151 endfor
152 else
153 NetrwKeepj call setline(line("$"),level.a:msg)
154 endif
155 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200156 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100157" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200158 if &fo !~ '[ta]'
159 syn clear
160 syn match netrwMesgNote "^\*\*note\*\*"
161 syn match netrwMesgWarning "^\*\*warning\*\*"
162 syn match netrwMesgError "^\*\*error\*\*"
163 hi link netrwMesgWarning WarningMsg
164 hi link netrwMesgError Error
165 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100166" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200167 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200168
169 else
170 " (optional) netrw will show messages using echomsg. Even if the
171 " message doesn't appear, at least it'll be recallable via :messages
172" redraw!
173 if a:level == s:WARNING
174 echohl WarningMsg
175 elseif a:level == s:ERROR
176 echohl Error
177 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100178
179 if type(a:msg) == 3
180 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100181 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100182 endfor
183 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100184 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100185 endif
186
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100187" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200188 echohl None
189 endif
190
191" call Dret("netrw#ErrorMsg")
192endfun
193
194" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100195" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100196" Loosely, varname = value.
197fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100198" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100199 if !exists(a:varname)
200 if type(a:value) == 0
201 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200202 elseif type(a:value) == 1 && a:value =~ '^[{[]'
203 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100204 elseif type(a:value) == 1
205 exe "let ".a:varname."="."'".a:value."'"
206 else
207 exe "let ".a:varname."=".a:value
208 endif
209 endif
210endfun
211
212" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000213" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200214call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000215if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100216 call s:NetrwInit("s:THINLIST",0)
217 call s:NetrwInit("s:LONGLIST",1)
218 call s:NetrwInit("s:WIDELIST",2)
219 call s:NetrwInit("s:TREELIST",3)
220 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000221endif
222
Damien7c754112024-08-15 21:58:57 +0200223let s:NOTE = 0
224let s:WARNING = 1
225let s:ERROR = 2
226call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
227
Bram Moolenaar9964e462007-05-05 17:54:07 +0000228" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200229" Default option values: {{{2
230let g:netrw_localcopycmdopt = ""
231let g:netrw_localcopydircmdopt = ""
232let g:netrw_localmkdiropt = ""
233let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200234
235" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000236" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200237if exists("*popup_atcursor")
238\ && has("syntax")
239\ && exists("g:syntax_on")
240\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200241 call s:NetrwInit("g:netrw_use_errorwindow",2)
242else
243 call s:NetrwInit("g:netrw_use_errorwindow",1)
244endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200245
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000246if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100247 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000248 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100249 elseif executable("curl")
250 let g:netrw_dav_cmd = "curl"
251 else
252 let g:netrw_dav_cmd = ""
253 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000254endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000255if !exists("g:netrw_fetch_cmd")
256 if executable("fetch")
257 let g:netrw_fetch_cmd = "fetch -o"
258 else
259 let g:netrw_fetch_cmd = ""
260 endif
261endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100262if !exists("g:netrw_file_cmd")
263 if executable("elinks")
264 call s:NetrwInit("g:netrw_file_cmd","elinks")
265 elseif executable("links")
266 call s:NetrwInit("g:netrw_file_cmd","links")
267 endif
268endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000269if !exists("g:netrw_ftp_cmd")
270 let g:netrw_ftp_cmd = "ftp"
271endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200272let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200273if !exists("g:netrw_ftp_options")
274 let g:netrw_ftp_options= "-i -n"
275endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000276if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100277 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100278 let g:netrw_http_cmd = "wget"
279 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100280 elseif executable("curl")
281 let g:netrw_http_cmd = "curl"
282 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200283 elseif executable("elinks")
284 let g:netrw_http_cmd = "elinks"
285 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000286 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100287 let g:netrw_http_cmd = "fetch"
288 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200289 elseif executable("links")
290 let g:netrw_http_cmd = "links"
291 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000292 else
293 let g:netrw_http_cmd = ""
294 endif
295endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100296call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100297call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100298call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
299call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200300call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200301if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200302 if executable("scp")
303 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
304 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200305 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200306 else
307 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
308 endif
309endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100310call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
311call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000312
Nir Lichtman1e34b952024-05-08 19:19:34 +0200313if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000314 \ && exists("g:netrw_use_nt_rcp")
315 \ && g:netrw_use_nt_rcp
316 \ && executable( $SystemRoot .'/system32/rcp.exe')
317 let s:netrw_has_nt_rcp = 1
318 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000319else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000320 let s:netrw_has_nt_rcp = 0
321 let s:netrw_rcpmode = ''
322endif
323
324" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000325" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000326" Cygwin Detection ------- {{{3
327if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200328 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
329 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000330 else
331 let g:netrw_cygwin= 0
332 endif
333endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000334" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100335call s:NetrwInit("g:netrw_alto" , &sb)
336call s:NetrwInit("g:netrw_altv" , &spr)
337call s:NetrwInit("g:netrw_banner" , 1)
338call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200339call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100340call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200341call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100342call s:NetrwInit("g:netrw_compress" , "gzip")
343call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200344if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
345 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
346 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000347endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200348call s:NetrwInit("g:netrw_cursor" , 2)
349let s:netrw_usercul = &cursorline
350let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200351"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100352call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000353" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200354call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200355call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200356call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100357call s:NetrwInit("g:netrw_dirhistmax" , 10)
358call s:NetrwInit("g:netrw_fastbrowse" , 1)
359call 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 +0000360if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000361 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
362 let g:netrw_ftp_list_cmd = "ls -lF"
363 let g:netrw_ftp_timelist_cmd = "ls -tlF"
364 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000365 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000366 let g:netrw_ftp_list_cmd = "dir"
367 let g:netrw_ftp_timelist_cmd = "dir"
368 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000369 endif
370endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100371call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000372" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100373call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000374if !exists("g:netrw_ignorenetrc")
375 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
376 let g:netrw_ignorenetrc= 1
377 else
378 let g:netrw_ignorenetrc= 0
379 endif
380endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100381call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000382if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000383 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100384 if exists("g:netrw_list_cmd_options")
385 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
386 else
387 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
388 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000389 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200390 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100391 if exists("g:netrw_list_cmd_options")
392 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
393 else
394 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
395 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000396 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100397" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000398 let g:netrw_list_cmd= ""
399 endif
400endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100401call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000402" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200403if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200404 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200405 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
406endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100407if !exists("g:netrw_localcmdshell")
408 let g:netrw_localcmdshell= ""
409endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000410if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200411 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000412 if g:netrw_cygwin
413 let g:netrw_localcopycmd= "cp"
414 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000415 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200416 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000417 endif
418 elseif has("unix") || has("macunix")
419 let g:netrw_localcopycmd= "cp"
420 else
421 let g:netrw_localcopycmd= ""
422 endif
423endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100424if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200425 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100426 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200427 let g:netrw_localcopydircmd = "cp"
428 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100429 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000430 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200431 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200433 elseif has("unix")
434 let g:netrw_localcopydircmd = "cp"
435 let g:netrw_localcopydircmdopt= " -R"
436 elseif has("macunix")
437 let g:netrw_localcopydircmd = "cp"
438 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100439 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200440 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100441 endif
442endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200443if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100444 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200445 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
446endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200447if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200448 if g:netrw_cygwin
449 call s:NetrwInit("g:netrw_localmkdir","mkdir")
450 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000451 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200452 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200453 endif
454else
455 call s:NetrwInit("g:netrw_localmkdir","mkdir")
456endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200457call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200458if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200459 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200460 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
461endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000462if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200463 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000464 if g:netrw_cygwin
465 let g:netrw_localmovecmd= "mv"
466 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000467 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200468 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000469 endif
470 elseif has("unix") || has("macunix")
471 let g:netrw_localmovecmd= "mv"
472 else
473 let g:netrw_localmovecmd= ""
474 endif
475endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100476" following serves as an example for how to insert a version&patch specific test
477"if v:version < 704 || (v:version == 704 && !has("patch1107"))
478"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100479call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
480" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000481if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000482 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000483endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000484if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000485 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
486endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000487" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100488call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
489call s:NetrwInit("g:netrw_maxfilenamelen", 32)
490call s:NetrwInit("g:netrw_menu" , 1)
491call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200492call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100493call s:NetrwInit("g:netrw_retmap" , 0)
494if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
495 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200496elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100497 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
498else
499 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000500endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100501call s:NetrwInit("g:netrw_preview" , 0)
502call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100503call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100504call s:NetrwInit("g:netrw_sshport" , "-p")
505call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
506call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
507call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100508call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
509" Default values - q-s ---------- {{{3
510call s:NetrwInit("g:netrw_quickhelp",0)
511let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100512 \ "(create new) %:file d:directory",
513 \ "(windows split&open) o:horz v:vert p:preview",
514 \ "i:style qf:file info O:obtain r:reverse",
515 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
516 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
517 \ "(history) qb:list u:go up U:go down",
518 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100519" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
520call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100521if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
522 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
523else
524 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
525endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100526call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
527call s:NetrwInit("g:netrw_sort_options" , "")
528call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000529if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200531 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100532 else
533 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000534 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000535endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100536call s:NetrwInit("g:netrw_special_syntax" , 0)
537call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200538call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100539call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100540call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000541" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200543if !exists("g:netrw_xstrlen")
544 if exists("g:Align_xstrlen")
545 let g:netrw_xstrlen= g:Align_xstrlen
546 elseif exists("g:drawit_xstrlen")
547 let g:netrw_xstrlen= g:drawit_xstrlen
548 elseif &enc == "latin1" || !has("multi_byte")
549 let g:netrw_xstrlen= 0
550 else
551 let g:netrw_xstrlen= 1
552 endif
553endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100554call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200555call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100556call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200557if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000558" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000559" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100560call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200561if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200562 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200563else
Bram Moolenaarff034192013-04-24 18:51:19 +0200564 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200565endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200566call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100567call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
568call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100569if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100570 let s:treedepthstring= "│ "
571else
572 let s:treedepthstring= "| "
573endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200574call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000575
576" BufEnter event ignored by decho when following variable is true
577" Has a side effect that doau BufReadPost doesn't work, so
578" files read by network transfer aren't appropriately highlighted.
579"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580
Bram Moolenaaradc21822011-04-01 18:03:16 +0200581" ======================
582" Netrw Initialization: {{{1
583" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200584if 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 +0100585" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100586 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200587" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100588 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100589 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
590 au VimEnter * let s:initbeval= &beval
591"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100592" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
593" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
594" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
595" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
596" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
597" 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 +0200598endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200599au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200600
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200601if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100602 com! -nargs=* NetrwKeepj keepj <args>
603else
604 let g:netrw_keepj= ""
605 com! -nargs=* NetrwKeepj <args>
606endif
607
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000608" ==============================
609" Netrw Utility Functions: {{{1
610" ==============================
611
Bram Moolenaaradc21822011-04-01 18:03:16 +0200612" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100613" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100614if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100615" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100616 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100617 if &ft != "netrw"
618 return ""
619 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200620 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
621 " popup error window is still showing
622 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
623 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
624 " text under mouse hasn't changed; only close window when it changes
625 call popup_close(s:popuperr_id)
626 unlet s:popuperr_text
627 else
628 let s:popuperr_text= v:beval_text
629 endif
630 let mesg= ""
631 elseif !exists("w:netrw_bannercnt") || v:beval_lnum >= w:netrw_bannercnt || (exists("g:netrw_nobeval") && g:netrw_nobeval)
Bram Moolenaar8d043172014-01-23 14:24:41 +0100632 let mesg= ""
633 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
634 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
635 elseif getline(v:beval_lnum) =~ '^"\s*/'
636 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
637 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100638 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100639 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
640 let mesg = "S: edit sorting sequence"
641 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
642 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
643 elseif v:beval_text == "Quick" || v:beval_text == "Help"
644 let mesg = "Help: press <F1>"
645 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
646 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
647 else
648 let mesg= ""
649 endif
650 return mesg
651 endfun
652"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100653" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
654" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
655" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
656" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
657" 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 +0200658endif
659
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200661" netrw#Explore: launch the local browser in the directory of the current file {{{2
662" indx: == -1: Nexplore
663" == -2: Pexplore
664" == +: this is overloaded:
665" * If Nexplore/Pexplore is in use, then this refers to the
666" indx'th item in the w:netrw_explore_list[] of items which
667" matched the */pattern **/pattern *//pattern **//pattern
668" * If Hexplore or Vexplore, then this will override
669" g:netrw_winsize to specify the qty of rows or columns the
670" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100671" 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 +0200672" dosplit==1: the window will be split before running the local browser
673" style == 0: Explore style == 1: Explore!
674" == 2: Hexplore style == 3: Hexplore!
675" == 4: Vexplore style == 5: Vexplore!
676" == 6: Texplore
677fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100678" 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 +0100679" 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 +0200680 if !exists("b:netrw_curdir")
681 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100682" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200683 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100684
685 " record current file for Rexplore's benefit
686 if &ft != "netrw"
687 let w:netrw_rexfile= expand("%:p")
688 endif
689
690 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200691 let curdir = simplify(b:netrw_curdir)
692 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200693 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200694 let curdir= substitute(curdir,'\','/','g')
695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100696" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100697
698 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
699 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
700 " try Explore again.
701 if a:0 > 0
702" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100703 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
704 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
705 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
706 \ '~'.expand("<slnum>"))
707 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200708 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
709 if a1 != a:1
710 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
711 return
712 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100713 endif
714 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200715
716 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200717 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100718" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100719 sil! let keepregstar = @*
720 sil! let keepregplus = @+
721 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 sil! let keepregslash= @/
723
Bram Moolenaar8d043172014-01-23 14:24:41 +0100724 " if dosplit
725 " -or- file has been modified AND file not hidden when abandoned
726 " -or- Texplore used
727 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200728 call s:SaveWinVars()
729 let winsz= g:netrw_winsize
730 if a:indx > 0
731 let winsz= a:indx
732 endif
733
734 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200735 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200736 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200737 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200738
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200739 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200740 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200741 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200742 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200743
744 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200745 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200746 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200747 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200748
749 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200750 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200751 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200752 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200753
754 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200756 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200757 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200758
759 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200761 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200762 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200763
764 elseif a:style == 6 " Texplore
765 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200766 exe "keepalt tabnew ".fnameescape(curdir)
767 call s:RestoreBufVars()
768 endif
769 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100771 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200772
773 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100776" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100778" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200779 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100780" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
782 if dirname !~ '/$'
783 let dirname= dirname."/"
784 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100785" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100787" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200788 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100789" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200790 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100791" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200792 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100793" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 let dirname= a:1
797 endif
798 else
799 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100800" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200801 call s:NetrwClearExplore()
802" call Dret("netrw#Explore : cleared list")
803 return
804 endif
805
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100806" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200807 if dirname =~ '\.\./\=$'
808 let dirname= simplify(fnamemodify(dirname,':p:h'))
809 elseif dirname =~ '\.\.' || dirname == '.'
810 let dirname= simplify(fnamemodify(dirname,':p'))
811 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100812" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200813
814 if dirname =~ '^\*//'
815 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100816" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200817 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
818 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100819" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
821
822 elseif dirname =~ '^\*\*//'
823 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100824" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200825 let pattern= substitute(dirname,'^\*\*//','','')
826 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100827" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200828
829 elseif dirname =~ '/\*\*/'
830 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100831" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200833 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200834 let b:netrw_curdir = prefixdir
835 else
836 let b:netrw_curdir= getcwd().'/'.prefixdir
837 endif
838 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
839 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100840" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
841" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842
843 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200844 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200845 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100846" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200847
848 elseif dirname=~ '^\*\*/'
849 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
850 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100851" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200852
853 else
854 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100855" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200856 endif
857
858 if starpat == 0 && a:indx >= 0
859 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100860" 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 +0200861 if dirname == ""
862 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100863" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200864 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200865 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200866 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200867 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200868 if dirname == ""
869 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200870 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100871 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100872 " depending on whether backslashes have been converted to forward slashes by earlier code).
873 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200874 let dirname= b:netrw_curdir."/".dirname
875 endif
876 elseif dirname !~ '^/'
877 let dirname= b:netrw_curdir."/".dirname
878 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100879" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200880 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100881" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
882" 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 +0200883 endif
884 if exists("w:netrw_bannercnt")
885 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
886 " If one wants to return the same place in the netrw window, use :Rex instead.
887 exe w:netrw_bannercnt
888 endif
889
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100890" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200891 " ---------------------------------------------------------------------
892 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
893" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100894" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200895" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100896" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200897" endif
898 " ---------------------------------------------------------------------
899
900 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
901 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
902 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
903 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
904 elseif a:indx <= 0
905 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100906" 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 +0200907 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100908" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200909 let s:didstarstar= 1
910 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
911 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
912 endif
913
914 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100915" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200916 if !exists("w:netrw_explore_indx")
917 let w:netrw_explore_indx= 0
918 endif
919
920 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100921" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200922
923 if indx == -1
924 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100925" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200926 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100927 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Nexplore or <s-down> improperly; see help for netrw-starstar",40)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200928 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100929" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100930 if @* != keepregstar | sil! let @* = keepregstar | endif
931 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100932 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 sil! let @/ = keepregslash
934" call Dret("netrw#Explore")
935 return
936 endif
937 let indx= w:netrw_explore_indx
938 if indx < 0 | let indx= 0 | endif
939 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
940 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100941" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200942 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
943 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100944" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200945 endwhile
946 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100947" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200948
949 elseif indx == -2
950 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100953 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"using Pexplore or <s-up> improperly; see help for netrw-starstar",41)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200954 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100955" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100956 if @* != keepregstar | sil! let @* = keepregstar | endif
957 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100958 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200959 sil! let @/ = keepregslash
960" call Dret("netrw#Explore")
961 return
962 endif
963 let indx= w:netrw_explore_indx
964 if indx < 0 | let indx= 0 | endif
965 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
966 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100967" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200968 while indx >= 0 && curfile == w:netrw_explore_list[indx]
969 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100970" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200971 endwhile
972 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100973" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200974
975 else
976 " Explore -- initialize
977 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100978" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100979 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200980 let w:netrw_explore_indx= 0
981 if !exists("b:netrw_curdir")
982 let b:netrw_curdir= getcwd()
983 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100984" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200985
986 " switch on starpat to build the w:netrw_explore_list of files
987 if starpat == 1
988 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100989" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
990" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200991 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100992 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200993 catch /^Vim\%((\a\+)\)\=:E480/
994 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
995" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
996 return
997 endtry
998 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
999 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1000
1001 elseif starpat == 2
1002 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001003" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1004" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001005 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001006 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001007 catch /^Vim\%((\a\+)\)\=:E480/
1008 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1009 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001010 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001011" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001012 if @* != keepregstar | sil! let @* = keepregstar | endif
1013 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001014 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 sil! let @/ = keepregslash
1016" call Dret("netrw#Explore : no files matched pattern")
1017 return
1018 endtry
1019 let s:netrw_curdir = b:netrw_curdir
1020 let w:netrw_explore_list = getqflist()
1021 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1022 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1023
1024 elseif starpat == 3
1025 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001026" 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 +02001027 let filepat= substitute(dirname,'^\*/','','')
1028 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001029" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1030" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001031 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1032 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1033
1034 elseif starpat == 4
1035 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" 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 +02001037 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1038 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1039 endif " switch on starpat to build w:netrw_explore_list
1040
1041 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001042" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1043" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001044
1045 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001046 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001047 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001048" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001049 if @* != keepregstar | sil! let @* = keepregstar | endif
1050 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001051 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001052 sil! let @/ = keepregslash
1053" call Dret("netrw#Explore : no files matched")
1054 return
1055 endif
1056 endif " if indx ... endif
1057
1058 " NetrwStatusLine support - for exploring support
1059 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001060" 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 +02001061
1062 " wrap the indx around, but issue a note
1063 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001064" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001065 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1066 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001067 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001068 endif
1069
1070 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001071" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001073" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001074
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001075" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 call netrw#LocalBrowseCheck(newdir)
1077 if !exists("w:netrw_liststyle")
1078 let w:netrw_liststyle= g:netrw_liststyle
1079 endif
1080 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001081 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001083 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001084 endif
1085 let w:netrw_explore_mtchcnt = indx + 1
1086 let w:netrw_explore_bufnr = bufnr("%")
1087 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001088 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001089" 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 +02001090
1091 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001092" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001093 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001094 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 +02001095 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001096 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001097" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001098 if @* != keepregstar | sil! let @* = keepregstar | endif
1099 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001100 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001101 sil! let @/ = keepregslash
1102" call Dret("netrw#Explore : missing +path_extra")
1103 return
1104 endif
1105
1106 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001107" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001108 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1109 sil! unlet w:netrw_treedict
1110 sil! unlet w:netrw_treetop
1111 endif
1112 let newdir= dirname
1113 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001114 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001115 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001116 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001117 endif
1118 endif
1119
1120 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001121" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1122" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001123 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001124" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001126 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001127" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001128 let s:explore_prvdir = b:netrw_curdir
1129 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001130 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001131 if b:netrw_curdir !~ '/$'
1132 let dirlen= dirlen + 1
1133 endif
1134 let prvfname= ""
1135 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001136" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001137 if fname =~ '^'.b:netrw_curdir
1138 if s:explore_match == ""
1139 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1140 else
1141 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1142 endif
1143 elseif fname !~ '^/' && fname != prvfname
1144 if s:explore_match == ""
1145 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1146 else
1147 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1148 endif
1149 endif
1150 let prvfname= fname
1151 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001152" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001153 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1154 exe "2match netrwMarkFile /".s:explore_match."/"
1155 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001156 endif
1157 echo "<s-up>==Pexplore <s-down>==Nexplore"
1158 else
1159 2match none
1160 if exists("s:explore_match") | unlet s:explore_match | endif
1161 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001162" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001163 endif
1164
Bram Moolenaara6878372014-03-22 21:02:50 +01001165 " since Explore may be used to initialize netrw's browser,
1166 " there's no danger of a late FocusGained event on initialization.
1167 " Consequently, set s:netrw_events to 2.
1168 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001169 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001170" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001171 if @* != keepregstar | sil! let @* = keepregstar | endif
1172 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001173 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001174 sil! let @/ = keepregslash
1175" call Dret("netrw#Explore : @/<".@/.">")
1176endfun
1177
1178" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001179" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001180" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1181" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1182" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1183" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1184" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001185fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001186" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001187 let curwin= winnr()
1188
Bram Moolenaara6878372014-03-22 21:02:50 +01001189 if a:0 > 0 && a:1 != ""
1190 " if a netrw window is already on the left-side of the tab
1191 " and a directory has been specified, explore with that
1192 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001193" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001194 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001195" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001196 exe "1wincmd w"
1197 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001198" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001199 exe "Explore ".fnameescape(a1)
1200 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001201 let s:lexplore_win= curwin
1202 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001203 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001204" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001205 unlet t:netrw_lexposn
1206 endif
1207" call Dret("netrw#Lexplore")
1208 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001209 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001210 exe curwin."wincmd w"
1211 else
1212 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001213" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001214 endif
1215
Bram Moolenaar8d043172014-01-23 14:24:41 +01001216 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001217 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001218 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001219" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220 else
1221 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001222" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001223 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001224" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001225
1226 if lexwinnr > 0
1227 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001228" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001229 exe lexwinnr."wincmd w"
1230 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001231 let t:netrw_lexposn = winsaveview()
1232" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001233" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001234 close
1235 if lexwinnr < curwin
1236 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001237 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001238 if lexwinnr != curwin
1239 exe curwin."wincmd w"
1240 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001241 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001242" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001243
1244 else
1245 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001246" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247 exe "1wincmd w"
1248 let keep_altv = g:netrw_altv
1249 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001250 if a:count != 0
1251 let netrw_winsize = g:netrw_winsize
1252 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001253 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001254 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001255" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001256 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001257" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001258 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001259" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001260 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001261 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001262 elseif curfile =~ '^\a\{3,}://'
1263" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001264 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001265 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001266" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001267 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 endif
1269 if a:count != 0
1270 let g:netrw_winsize = netrw_winsize
1271 endif
1272 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001273 let g:netrw_altv = keep_altv
1274 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001275 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1276 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001277 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001278 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001279" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1280" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001281 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001282" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001283" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1284 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001285 unlet t:netrw_lexposn
1286 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001287 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001288
1289 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001290 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001291 if a:rightside
1292 let g:netrw_chgwin= 1
1293 else
1294 let g:netrw_chgwin= 2
1295 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001296" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001297 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001298
Bram Moolenaar8d043172014-01-23 14:24:41 +01001299" call Dret("netrw#Lexplore")
1300endfun
1301
1302" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001303" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001304" supports :NetrwClean -- remove netrw from first directory on runtimepath
1305" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001306fun! netrw#Clean(sys)
1307" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001308
1309 if a:sys
1310 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1311 else
1312 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1313 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001314" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001315 let diddel= 0
1316 let diddir= ""
1317
1318 if choice == 1
1319 for dir in split(&rtp,',')
1320 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001321" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001322 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1323 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1324 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1325 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1326 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1327 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 +00001328 let diddir= dir
1329 let diddel= diddel + 1
1330 if !a:sys|break|endif
1331 endif
1332 endfor
1333 endif
1334
1335 echohl WarningMsg
1336 if diddel == 0
1337 echomsg "netrw is either not installed or not removable"
1338 elseif diddel == 1
1339 echomsg "removed one copy of netrw from <".diddir.">"
1340 else
1341 echomsg "removed ".diddel." copies of netrw"
1342 endif
1343 echohl None
1344
Bram Moolenaara6878372014-03-22 21:02:50 +01001345" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001346endfun
1347
Bram Moolenaar5c736222010-01-06 20:54:52 +01001348" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001349" netrw#MakeTgt: make a target out of the directory name provided {{{2
1350fun! netrw#MakeTgt(dname)
1351" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1352 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001353 let svpos = winsaveview()
1354" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001355 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1356" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001357 if s:netrwmftgt_islocal
1358 let netrwmftgt= simplify(a:dname)
1359 else
1360 let netrwmftgt= a:dname
1361 endif
1362 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1363 " re-selected target, so just clear it
1364 unlet s:netrwmftgt s:netrwmftgt_islocal
1365 else
1366 let s:netrwmftgt= netrwmftgt
1367 endif
1368 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001369 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001370 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001371" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1372 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001373" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001374endfun
1375
Bram Moolenaara6878372014-03-22 21:02:50 +01001376" ---------------------------------------------------------------------
1377" netrw#Obtain: {{{2
1378" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001379" islocal=0 obtain from remote source
1380" =1 obtain from local source
1381" fname : a filename or a list of filenames
1382" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001383fun! netrw#Obtain(islocal,fname,...)
1384" 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 +02001385 " NetrwStatusLine support - for obtaining support
1386
1387 if type(a:fname) == 1
1388 let fnamelist= [ a:fname ]
1389 elseif type(a:fname) == 3
1390 let fnamelist= a:fname
1391 else
1392 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 +01001393" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001394 return
1395 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001396" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001397 if a:0 > 0
1398 let tgtdir= a:1
1399 else
1400 let tgtdir= getcwd()
1401 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001402" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001403
1404 if exists("b:netrw_islocal") && b:netrw_islocal
1405 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001406" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1408 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001409 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001410 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001411" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001413" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001414 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001415 if v:shell_error != 0
1416 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 +01001417" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001418 return
1419 endif
1420 endfor
1421 else
1422 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1424 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1425" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001426 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001427 if v:shell_error != 0
1428 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 +01001429" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001430 return
1431 endif
1432 endif
1433 elseif !exists("b:netrw_curdir")
1434 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1435 else
1436 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1437 endif
1438
1439 else
1440 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001441" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001442 if type(a:fname) == 1
1443 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1444 endif
1445 call s:NetrwMethod(b:netrw_curdir)
1446
1447 if b:netrw_method == 4
1448 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001449" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001450 if exists("g:netrw_port") && g:netrw_port != ""
1451 let useport= " ".g:netrw_scpport." ".g:netrw_port
1452 else
1453 let useport= ""
1454 endif
1455 if b:netrw_fname =~ '/'
1456 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1457 else
1458 let path= ""
1459 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001460 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001461 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 +02001462
1463 elseif b:netrw_method == 2
1464 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001465" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001466 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001467 let tmpbufnr= bufnr("%")
1468 setl ff=unix
1469 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001470 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001472 endif
1473
1474 if exists("b:netrw_fname") && b:netrw_fname != ""
1475 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001476" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001477 endif
1478
1479 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001480 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001481" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001482 endif
1483 for fname in fnamelist
1484 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001485" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001486 endfor
1487 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001488 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 +02001489 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001490 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001491 endif
1492 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1493 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1494 let debugkeep= &debug
1495 setl debug=msg
1496 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1497 let &debug= debugkeep
1498 endif
1499
1500 elseif b:netrw_method == 3
1501 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001502" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001503 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001504 let tmpbufnr= bufnr("%")
1505 setl ff=unix
1506
1507 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001508 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001509" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001510 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001511 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001513 endif
1514
1515 if exists("g:netrw_uid") && g:netrw_uid != ""
1516 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001517 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001518" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001519 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001520 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001521 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001524 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001525" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001526 endif
1527 endif
1528
1529 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001531" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001532 endif
1533
1534 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001535 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001536" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001537 endif
1538
1539 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001540 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001541" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001542 endif
1543
1544 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001545 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001546" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001547 endif
1548 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001549 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001550 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001551" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001552
1553 " perform ftp:
1554 " -i : turns off interactive prompting from ftp
1555 " -n unix : DON'T use <.netrc>, even though it exists
1556 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001557 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1558 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001559 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001560 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1561 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001562" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001563 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001564 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001565 endif
1566 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001567
1568 elseif b:netrw_method == 9
1569 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001570" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001571 if a:fname =~ '/'
1572 let localfile= substitute(a:fname,'^.*/','','')
1573 else
1574 let localfile= a:fname
1575 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001576 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 +02001577
Bram Moolenaarff034192013-04-24 18:51:19 +02001578 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001579 " probably a badly formed url; protocol not recognized
1580" call Dret("netrw#Obtain : unsupported method")
1581 return
1582
1583 else
1584 " protocol recognized but not supported for Obtain (yet?)
1585 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001586 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001587 endif
1588" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001589 return
1590 endif
1591
1592 " restore status line
1593 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001594 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001595 endif
1596
1597 endif
1598
1599 " cleanup
1600 if exists("tmpbufnr")
1601 if bufnr("%") != tmpbufnr
1602 exe tmpbufnr."bw!"
1603 else
1604 q!
1605 endif
1606 endif
1607
Bram Moolenaara6878372014-03-22 21:02:50 +01001608" call Dret("netrw#Obtain")
1609endfun
1610
1611" ---------------------------------------------------------------------
1612" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1613fun! netrw#Nread(mode,fname)
1614" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001615 let svpos= winsaveview()
1616" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001617 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001618" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1619 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001620
1621 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1622 if exists("w:netrw_bannercnt")
1623 " start with cursor just after the banner
1624 exe w:netrw_bannercnt
1625 endif
1626 endif
1627" call Dret("netrw#Nread")
1628endfun
1629
1630" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001631" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1632" Options get restored by s:NetrwOptionsRestore()
1633"
1634" Option handling:
1635" * save user's options (s:NetrwOptionsSave)
1636" * set netrw-safe options (s:NetrwOptionsSafe)
1637" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1638" * restore user's options (s:netrwOPtionsRestore)
1639" - restore a user option when != safe option (s:NetrwRestoreSetting)
1640" vt: (variable type) normally its either "w:" or "s:"
1641fun! s:NetrwOptionsSave(vt)
1642" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1643" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001644" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt." hid=".&hid,'~'.expand("<slnum>"))
1645" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001646
1647 if !exists("{a:vt}netrw_optionsave")
1648 let {a:vt}netrw_optionsave= 1
1649 else
1650" call Dret("s:NetrwOptionsSave : options already saved")
1651 return
1652 endif
1653" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1654
1655 " Save current settings and current directory
1656" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1657 let s:yykeep = @@
1658 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1659 let {a:vt}netrw_aikeep = &l:ai
1660 let {a:vt}netrw_awkeep = &l:aw
1661 let {a:vt}netrw_bhkeep = &l:bh
1662 let {a:vt}netrw_blkeep = &l:bl
1663 let {a:vt}netrw_btkeep = &l:bt
1664 let {a:vt}netrw_bombkeep = &l:bomb
1665 let {a:vt}netrw_cedit = &cedit
1666 let {a:vt}netrw_cikeep = &l:ci
1667 let {a:vt}netrw_cinkeep = &l:cin
1668 let {a:vt}netrw_cinokeep = &l:cino
1669 let {a:vt}netrw_comkeep = &l:com
1670 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001671 let {a:vt}netrw_cuckeep = &l:cuc
1672 let {a:vt}netrw_culkeep = &l:cul
1673" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001674 let {a:vt}netrw_diffkeep = &l:diff
1675 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001676 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1677 let {a:vt}netrw_ffkeep = &l:ff
1678 endif
1679 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1680 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001681 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001682 let {a:vt}netrw_hidkeep = &l:hidden
1683 let {a:vt}netrw_imkeep = &l:im
1684 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001685 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001686 let {a:vt}netrw_lskeep = &l:ls
1687 let {a:vt}netrw_makeep = &l:ma
1688 let {a:vt}netrw_magickeep = &l:magic
1689 let {a:vt}netrw_modkeep = &l:mod
1690 let {a:vt}netrw_nukeep = &l:nu
1691 let {a:vt}netrw_rnukeep = &l:rnu
1692 let {a:vt}netrw_repkeep = &l:report
1693 let {a:vt}netrw_rokeep = &l:ro
1694 let {a:vt}netrw_selkeep = &l:sel
1695 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001696 if !g:netrw_use_noswf
1697 let {a:vt}netrw_swfkeep = &l:swf
1698 endif
1699 let {a:vt}netrw_tskeep = &l:ts
1700 let {a:vt}netrw_twkeep = &l:tw " textwidth
1701 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1702 let {a:vt}netrw_wrapkeep = &l:wrap
1703 let {a:vt}netrw_writekeep = &l:write
1704
1705 " save a few selected netrw-related variables
1706" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1707 if g:netrw_keepdir
1708 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001709" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001710 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001711 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001712 sil! let {a:vt}netrw_starkeep = @*
1713 sil! let {a:vt}netrw_pluskeep = @+
1714 endif
1715 sil! let {a:vt}netrw_slashkeep= @/
1716
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001717" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001718" 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>"))
1719" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1720endfun
1721
1722" ---------------------------------------------------------------------
1723" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1724" Use s:NetrwSaveOptions() to save user settings
1725" Use s:NetrwOptionsRestore() to restore user settings
1726fun! s:NetrwOptionsSafe(islocal)
1727" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1728" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1729" 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>"))
1730 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1731 call s:NetrwSetSafeSetting("&l:ai",0)
1732 call s:NetrwSetSafeSetting("&l:aw",0)
1733 call s:NetrwSetSafeSetting("&l:bl",0)
1734 call s:NetrwSetSafeSetting("&l:bomb",0)
1735 if a:islocal
1736 call s:NetrwSetSafeSetting("&l:bt","nofile")
1737 else
1738 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1739 endif
1740 call s:NetrwSetSafeSetting("&l:ci",0)
1741 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001742 if g:netrw_fastbrowse > a:islocal
1743 call s:NetrwSetSafeSetting("&l:bh","hide")
1744 else
1745 call s:NetrwSetSafeSetting("&l:bh","delete")
1746 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001747 call s:NetrwSetSafeSetting("&l:cino","")
1748 call s:NetrwSetSafeSetting("&l:com","")
1749 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1750 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1751 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001752 if &go =~ 'a' | set go-=a | endif
1753 if &go =~ 'A' | set go-=A | endif
1754 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001755 call s:NetrwSetSafeSetting("&l:hid",0)
1756 call s:NetrwSetSafeSetting("&l:im",0)
1757 setl isk+=@ isk+=* isk+=/
1758 call s:NetrwSetSafeSetting("&l:magic",1)
1759 if g:netrw_use_noswf
1760 call s:NetrwSetSafeSetting("swf",0)
1761 endif
1762 call s:NetrwSetSafeSetting("&l:report",10000)
1763 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1764 call s:NetrwSetSafeSetting("&l:spell",0)
1765 call s:NetrwSetSafeSetting("&l:tw",0)
1766 call s:NetrwSetSafeSetting("&l:wig","")
1767 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001768
1769 " set up cuc and cul based on g:netrw_cursor and listing style
1770 " COMBAK -- cuc cul related
1771 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001772
1773 " allow the user to override safe options
1774" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1775 if &ft == "netrw"
1776" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1777 keepalt NetrwKeepj doau FileType netrw
1778 endif
1779
1780" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1781" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1782" call Dret("s:NetrwOptionsSafe")
1783endfun
1784
1785" ---------------------------------------------------------------------
1786" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1787fun! s:NetrwOptionsRestore(vt)
1788" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001789" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001790" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001791 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001792" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001793
1794 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1795 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001796" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001797 filetype detect
1798" call Decho("..settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
1799 else
1800 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001801 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001802" call Decho("..ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001803" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001804 return
1805 endif
1806 unlet {a:vt}netrw_optionsave
1807
1808 if exists("+acd")
1809 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001810" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001811 let curdir = getcwd()
1812 let &l:acd = {a:vt}netrw_acdkeep
1813 unlet {a:vt}netrw_acdkeep
1814 if &l:acd
1815 call s:NetrwLcd(curdir)
1816 endif
1817 endif
1818 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001819" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001820 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1821 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1822 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1823 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1824 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001825" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001826 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1827 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1828 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1829 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1830 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001831" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001832 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1833 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1834 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1835 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1836 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001837 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001838" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1839 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1840 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001841 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001842 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1843" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1844 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1845 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1846" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1847 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1848" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1850 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001851 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001852 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1853 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1854" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1855 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1856 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1857 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1858 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1859" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001860 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1862 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1863 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001864 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001865" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001866 call s:NetrwRestoreSetting("s:yykeep","@@")
1867 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1868 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1869 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1870 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1871
Bram Moolenaara6878372014-03-22 21:02:50 +01001872 if exists("{a:vt}netrw_swfkeep")
1873 if &directory == ""
1874 " user hasn't specified a swapfile directory;
1875 " netrw will temporarily set the swapfile directory
1876 " to the current directory as returned by getcwd().
1877 let &l:directory= getcwd()
1878 sil! let &l:swf = {a:vt}netrw_swfkeep
1879 setl directory=
1880 unlet {a:vt}netrw_swfkeep
1881 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001882 if !g:netrw_use_noswf
1883 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1884 sil! let &l:swf= {a:vt}netrw_swfkeep
1885 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001886 unlet {a:vt}netrw_swfkeep
1887 endif
1888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001889 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001890 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1891 if exists("{a:vt}netrw_dirkeep")
1892 call s:NetrwLcd(dirkeep)
1893 unlet {a:vt}netrw_dirkeep
1894 endif
1895 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001896 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001897" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001898 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1899 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001900 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001901 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001902
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001903" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1904" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1905" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1906" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1907" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001908 " Moved the filetype detect here from NetrwGetFile() because remote files
1909 " were having their filetype detect-generated settings overwritten by
1910 " NetrwOptionRestore.
1911 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001912" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1913 filetype detect
1914" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001915 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001916" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001917" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001918" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001919endfun
1920
1921" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001922" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1923" but only when the options' value and the safe setting differ
1924" Doing this means that netrw will not come up as having changed a
1925" setting last when it really didn't actually change it.
1926"
1927" Called from s:NetrwOptionsSafe
1928" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1929fun! s:NetrwSetSafeSetting(setting,safesetting)
1930" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001931
Bram Moolenaar85850f32019-07-19 22:05:51 +02001932 if a:setting =~ '^&'
1933" call Decho("fyi: a:setting starts with &")
1934 exe "let settingval= ".a:setting
1935" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001936
Bram Moolenaar85850f32019-07-19 22:05:51 +02001937 if settingval != a:safesetting
1938" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1939 if type(a:safesetting) == 0
1940 exe "let ".a:setting."=".a:safesetting
1941 elseif type(a:safesetting) == 1
1942 exe "let ".a:setting."= '".a:safesetting."'"
1943 else
1944 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1945 endif
1946 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001947 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001948
Bram Moolenaar85850f32019-07-19 22:05:51 +02001949" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001950endfun
1951
1952" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001953" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1954" but only if the setting value differs from the associated keepvar.
1955" Doing this means that netrw will not come up as having changed a
1956" setting last when it really didn't actually change it.
1957"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001958" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001959" keepvars are set up by s:NetrwOptionsSave
1960fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001961""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001962
Bram Moolenaar85850f32019-07-19 22:05:51 +02001963 " typically called from s:NetrwOptionsRestore
1964 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1965 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001966 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001967 if exists(a:keepvar)
1968 exe "let keepvarval= ".a:keepvar
1969 exe "let setting= ".a:setting
1970
1971"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1972"" call Decho("fyi: keepvarval=".keepvarval)
1973"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1974
1975 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001976"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001977 if type(a:setting) == 0
1978 exe "let ".a:setting."= ".keepvarval
1979 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001980 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001981 else
1982 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1983 endif
1984 endif
1985
1986 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001987 endif
1988
Bram Moolenaar85850f32019-07-19 22:05:51 +02001989"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001990endfun
1991
1992" ---------------------------------------------------------------------
1993" NetrwStatusLine: {{{2
1994fun! NetrwStatusLine()
1995
1996" vvv NetrwStatusLine() debugging vvv
1997" let g:stlmsg=""
1998" if !exists("w:netrw_explore_bufnr")
1999" let g:stlmsg="!X<explore_bufnr>"
2000" elseif w:netrw_explore_bufnr != bufnr("%")
2001" let g:stlmsg="explore_bufnr!=".bufnr("%")
2002" endif
2003" if !exists("w:netrw_explore_line")
2004" let g:stlmsg=" !X<explore_line>"
2005" elseif w:netrw_explore_line != line(".")
2006" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2007" endif
2008" if !exists("w:netrw_explore_list")
2009" let g:stlmsg=" !X<explore_list>"
2010" endif
2011" ^^^ NetrwStatusLine() debugging ^^^
2012
2013 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")
2014 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002015 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002016 let &laststatus = s:netrw_users_ls
2017 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2018 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2019 return ""
2020 else
2021 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2022 endif
2023endfun
2024
Bram Moolenaar85850f32019-07-19 22:05:51 +02002025" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002026" Netrw Transfer Functions: {{{1
2027" ===============================
2028
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002030" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002031" mode: =0 read remote file and insert before current line
2032" =1 read remote file and insert after current line
2033" =2 replace with remote file
2034" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002035fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002036" 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 +00002037
Bram Moolenaar5c736222010-01-06 20:54:52 +01002038 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002039 call s:NetrwOptionsSave("w:")
2040 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002041 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002042 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2043 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2044 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002045" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002046
Bram Moolenaar5c736222010-01-06 20:54:52 +01002047 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002048 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002049 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002050 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002051 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002052 elseif a:mode == 2 " replace with remote file
2053 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002054 elseif a:mode == 3 " skip read of file (leave as temporary)
2055 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056 else
2057 exe a:mode
2058 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002059 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002061" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062
Bram Moolenaar5c736222010-01-06 20:54:52 +01002063 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002064 let tmpfile= s:GetTempfile("")
2065 if tmpfile == ""
2066" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002067 return
2068 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002069
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002070 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002071
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002072 " attempt to repeat with previous host-file-etc
2073 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002074" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 let choice = b:netrw_lastfile
2076 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002077
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002078 else
2079 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002080" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002081
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002083 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002084 echomsg 'NetRead Usage:'
2085 echomsg ':Nread machine:path uses rcp'
2086 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2087 echomsg ':Nread "machine id password path" uses ftp'
2088 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2089 echomsg ':Nread fetch://machine/path uses fetch'
2090 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2091 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002092 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002093 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002094 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2095 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2096 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2097 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002098 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002099 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002100
Bram Moolenaar9964e462007-05-05 17:54:07 +00002101 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002102 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002103" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002104 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002105 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002106 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002107 else
2108 " case "... ... ..."
2109 let choice = strpart(choice,1,strlen(choice)-1)
2110 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002111
Bram Moolenaar9964e462007-05-05 17:54:07 +00002112 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 let wholechoice = wholechoice . " " . choice
2114 let ichoice = ichoice + 1
2115 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002116 if !exists("g:netrw_quiet")
2117 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2118 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002119" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002120 return
2121 endif
2122 let choice= a:{ichoice}
2123 endwhile
2124 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2125 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 endif
2127 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002128
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002129" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002130 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002131
Bram Moolenaar5c736222010-01-06 20:54:52 +01002132 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002133 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002134 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002135" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002136 return
2137 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002138 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002139
Bram Moolenaar8d043172014-01-23 14:24:41 +01002140 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002141" 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 +02002142 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002143" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002144 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002145" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002146 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002148
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002149 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002150 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002151 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002152 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2153 echo "(netrw) Processing your read request..."
2154 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002155
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002157 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002159" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002160 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002161 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002162 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002163 " ER: the tmpfile is full path: rcp sees C:\... as host C
2164 if s:netrw_has_nt_rcp == 1
2165 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2166 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2167 else
2168 " Any way needed it machine contains a '.'
2169 let uid_machine = g:netrw_machine .'.'. $USERNAME
2170 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002172 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2173 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2174 else
2175 let uid_machine = g:netrw_machine
2176 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002178 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 +00002179 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002180 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002181
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002183 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002184 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002186 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002187 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002188 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002189 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002190 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002191" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002192 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002193 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002194" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002195 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002196 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002197" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002198 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002199 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 +00002200 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002202 endif
2203 " 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 +00002204 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002205 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002206 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002207 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002208 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002209 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002210 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002211 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002212 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2213 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002214 q!
2215 endif
2216 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002217 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002218 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002219
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002220 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002221 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002222 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2223 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002224" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002225 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002226 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002227 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002228 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002229 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002230 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002231" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002233 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002235 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002236
Bram Moolenaar97d62492012-11-15 21:28:22 +01002237 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002238 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002239 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002240" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002241 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002242 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002243 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002244" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002245 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002246 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002247" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002250
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002251 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002252 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002253" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002254 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002255 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002256 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002258 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002259 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002260" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002261
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262 " perform ftp:
2263 " -i : turns off interactive prompting from ftp
2264 " -n unix : DON'T use <.netrc>, even though it exists
2265 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002266 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002267 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002268 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2269 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002271 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002272 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002273 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002275 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002276 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002278
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002279 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002280 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002281 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002282" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002284 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 else
2286 let useport= ""
2287 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002288 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2289 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002290 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002291 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2292 else
2293 let tmpfile_get = tmpfile
2294 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002295 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 +00002296 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002297 let b:netrw_lastfile = choice
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: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002301 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002302" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002303 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002304 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002305 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002306 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002307" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002308 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002309 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002310
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002311 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2312 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002313" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002314 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002315 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 +00002316 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002317 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 +00002318 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002319 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002320
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002321 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002322 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002324 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2325 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002326" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2327" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2328 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 +00002329 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002330" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002331 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002332 endif
2333 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002334" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002335 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002336
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002337 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002338 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002339 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002341
Bram Moolenaar5c736222010-01-06 20:54:52 +01002342 if !executable(g:netrw_dav_cmd)
2343 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2344" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2345 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002346 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002347 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002348 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 +01002349 else
2350 " Construct execution string (four lines) which will be passed through filter
2351 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2352 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002353 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002354 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002355 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002356 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002357 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002358 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002359 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002360 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002361 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002362 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2363 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002364
Bram Moolenaar5c736222010-01-06 20:54:52 +01002365 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002366 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002368 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002369 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002370 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002371 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002372
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002373 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002374 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002375 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002376" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002377 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 +00002378 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002379 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002380
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002382 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002384 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002385" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002386 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002387 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002388 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002389 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002390" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002391 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002392 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002393 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002394 let netrw_option= "http"
2395 else
2396 let netrw_option= "ftp"
2397 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002398" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002399
Bram Moolenaar446cb832008-06-24 21:56:24 +00002400 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002401 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 +00002402 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002403 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 +00002404 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002405
Bram Moolenaar446cb832008-06-24 21:56:24 +00002406 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002407 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002409 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002410
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002411 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002412 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002413 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002414" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2415 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 +00002416 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002418
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002419 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002420 " NetRead: (file) NetRead Method #10 {{{3
2421 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002422" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2423 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002424 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2425 let b:netrw_lastfile = choice
2426
2427 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002428 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002429 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002430 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002431 endif
2432 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002433
Bram Moolenaar5c736222010-01-06 20:54:52 +01002434 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002435 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002436" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002437 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002438 unlet b:netrw_fname
2439 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002440 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 +01002441" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002442 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002443 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002444 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002445
Bram Moolenaar9964e462007-05-05 17:54:07 +00002446" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002447endfun
2448
2449" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002450" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002451fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002452" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002453
Bram Moolenaar5c736222010-01-06 20:54:52 +01002454 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002455 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002456 call s:NetrwOptionsSave("w:")
2457 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002458
Bram Moolenaar5c736222010-01-06 20:54:52 +01002459 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002460 let tmpfile= s:GetTempfile("")
2461 if tmpfile == ""
2462" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002463 return
2464 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002465
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002466 if a:0 == 0
2467 let ichoice = 0
2468 else
2469 let ichoice = 1
2470 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002471
Bram Moolenaar9964e462007-05-05 17:54:07 +00002472 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002473" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002474 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002475 " For binary writes, always write entire file.
2476 " (line numbers don't really make sense for that).
2477 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002478" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002479 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002480 elseif g:netrw_cygwin
2481 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002482 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002483" 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 +01002484 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002485 else
2486 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002487" 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 +01002488 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002489 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002490
Bram Moolenaar9964e462007-05-05 17:54:07 +00002491 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002492 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002493 " on the temporary file's name. Deletion of the temporary file during
2494 " cleanup then causes an error message.
2495 0file!
2496 endif
2497
Bram Moolenaar5c736222010-01-06 20:54:52 +01002498 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002499 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002500
Bram Moolenaar9964e462007-05-05 17:54:07 +00002501 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002502 " attempt to repeat with previous host-file-etc
2503 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002504" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 let choice = b:netrw_lastfile
2506 let ichoice= ichoice + 1
2507 else
2508 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002509
Bram Moolenaar8d043172014-01-23 14:24:41 +01002510 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002511 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002512 echomsg 'NetWrite Usage:"'
2513 echomsg ':Nwrite machine:path uses rcp'
2514 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2515 echomsg ':Nwrite "machine id password path" uses ftp'
2516 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2517 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2518 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2519 echomsg ':Nwrite rcp://machine/path uses rcp'
2520 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2521 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2522 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002523 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002524 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002525
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002526 elseif match(choice,"^\"") != -1
2527 if match(choice,"\"$") != -1
2528 " case "..."
2529 let choice=strpart(choice,1,strlen(choice)-2)
2530 else
2531 " case "... ... ..."
2532 let choice = strpart(choice,1,strlen(choice)-1)
2533 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002534
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002535 while match(choice,"\"$") == -1
2536 let wholechoice= wholechoice . " " . choice
2537 let ichoice = ichoice + 1
2538 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002539 if !exists("g:netrw_quiet")
2540 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2541 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002542" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002543 return
2544 endif
2545 let choice= a:{ichoice}
2546 endwhile
2547 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2548 endif
2549 endif
2550 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002551 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002552" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002553
Bram Moolenaar9964e462007-05-05 17:54:07 +00002554 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002555 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002556 if !exists("b:netrw_method") || b:netrw_method < 0
2557" call Dfunc("netrw#NetWrite : unsupported method")
2558 return
2559 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002560
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002561 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002562 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002563 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002564 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2565 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002566" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002567 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002568
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002569 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002570 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002571 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002572" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002573 if s:netrw_has_nt_rcp == 1
2574 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2575 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2576 else
2577 let uid_machine = g:netrw_machine .'.'. $USERNAME
2578 endif
2579 else
2580 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2581 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2582 else
2583 let uid_machine = g:netrw_machine
2584 endif
2585 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002586 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 +00002587 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002588
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002589 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002590 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002591 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002592" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002593 let netrw_fname = b:netrw_fname
2594
2595 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2596 let bhkeep = &l:bh
2597 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002598 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002599 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002600
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002601" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002602 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002603 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002605 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002606 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002607" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002608 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002609 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002610" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002612 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 +00002613 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2615 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 endif
2617 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2618 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002619 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002620 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002621 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002622 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002624
2625 " remove enew buffer (quietly)
2626 let filtbuf= bufnr("%")
2627 exe curbuf."b!"
2628 let &l:bh = bhkeep
2629 exe filtbuf."bw!"
2630
Bram Moolenaar071d4272004-06-13 20:20:40 +00002631 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002632
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002633 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002634 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002635 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002636 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002637" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002638 let netrw_fname = b:netrw_fname
2639 let bhkeep = &l:bh
2640
2641 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2642 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002643 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002644 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002645 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002646
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002647 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002648 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002649" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002651 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002652" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002653 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002654 if exists("g:netrw_uid") && g:netrw_uid != ""
2655 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002656 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002657" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002658 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002659 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002660 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002661" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002662 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002663 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002664" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002665 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002666 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002667 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002669 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002670 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002672 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002675 " save choice/id/password for future use
2676 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002677
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002678 " perform ftp:
2679 " -i : turns off interactive prompting from ftp
2680 " -n unix : DON'T use <.netrc>, even though it exists
2681 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002682 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002683 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002684 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2685 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002686 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002687 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002688 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002689 let mod=1
2690 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002691
2692 " remove enew buffer (quietly)
2693 let filtbuf= bufnr("%")
2694 exe curbuf."b!"
2695 let &l:bh= bhkeep
2696 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002697
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002698 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002699 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002700 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002701" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002702 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002703 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002704 else
2705 let useport= ""
2706 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707 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 +00002708 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002709
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002710 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002711 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002713" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002714 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2715 if executable(curl)
2716 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002717 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 +01002718 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002719 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002720 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002721
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002722 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002723 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002724 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002725" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002726
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002727 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002728 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2729 let bhkeep = &l:bh
2730
2731 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2732 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002733 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002734 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002735
Bram Moolenaarff034192013-04-24 18:51:19 +02002736 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002737 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002738 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002739 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002740 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002741 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002742 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002743 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002744 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002745 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002746
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002748 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002749 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002750
2751 " remove enew buffer (quietly)
2752 let filtbuf= bufnr("%")
2753 exe curbuf."b!"
2754 let &l:bh = bhkeep
2755 exe filtbuf."bw!"
2756
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002757 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002758
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002759 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002760 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002761 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002762" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002763 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 +00002764 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002765
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002766 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002767 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002768 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002769" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002770 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2772 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2773 else
2774 let uid_machine = g:netrw_machine
2775 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002776
2777 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2778 let bhkeep = &l:bh
2779 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002780 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002781 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002782
Bram Moolenaarff034192013-04-24 18:51:19 +02002783 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002784 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002785" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002786 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002787 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002788 let filtbuf= bufnr("%")
2789 exe curbuf."b!"
2790 let &l:bh = bhkeep
2791 exe filtbuf."bw!"
2792 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002793
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002794 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002795 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002796 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002797 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002798 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002800 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002801
Bram Moolenaar5c736222010-01-06 20:54:52 +01002802 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002803" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002804 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002805" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002806 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002808 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002809
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002810 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002812 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" 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 +02002814 elseif !exists("leavemod")
2815 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002816" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002817 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002818" 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 +00002819 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002820
Bram Moolenaar9964e462007-05-05 17:54:07 +00002821" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002822endfun
2823
2824" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002825" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002826" uses NetRead to get a copy of the file into a temporarily file,
2827" then sources that file,
2828" then removes that file.
2829fun! netrw#NetSource(...)
2830" call Dfunc("netrw#NetSource() a:0=".a:0)
2831 if a:0 > 0 && a:1 == '?'
2832 " give help
2833 echomsg 'NetSource Usage:'
2834 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2835 echomsg ':Nsource fetch://machine/path uses fetch'
2836 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002837 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002838 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2839 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2840 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2841 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2842 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002843 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002844 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002845 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002847" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002849" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002850 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002851" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002852 if delete(s:netrw_tmpfile)
2853 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2854 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 unlet s:netrw_tmpfile
2856 else
2857 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2858 endif
2859 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002860 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002861 endif
2862" call Dret("netrw#NetSource")
2863endfun
2864
Bram Moolenaar8d043172014-01-23 14:24:41 +01002865" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002866" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2867" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002868fun! netrw#SetTreetop(iscmd,...)
2869" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2870" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002871
Bram Moolenaar85850f32019-07-19 22:05:51 +02002872 " iscmd==0: netrw#SetTreetop called using gn mapping
2873 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2874" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002875 " clear out the current tree
2876 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002877" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002878 let inittreetop= w:netrw_treetop
2879 unlet w:netrw_treetop
2880 endif
2881 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002882" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002883 unlet w:netrw_treedict
2884 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002885" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002886
Bram Moolenaar85850f32019-07-19 22:05:51 +02002887 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002888 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002889" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002890 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002891 if isdirectory(s:NetrwFile(a:1))
2892" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002893 let treedir = a:1
2894 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002895 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002896 let treedir = b:netrw_curdir."/".a:1
2897 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002898" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002899 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002900 " normally the cursor is left in the message window.
2901 " However, here this results in the directory being listed in the message window, which is not wanted.
2902 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002903 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002904 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002905 let treedir = "."
2906 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002907 endif
2908 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002909" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002910
2911 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002912 let islocal= expand("%") !~ '^\a\{3,}://'
2913" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002914
2915 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002916 if islocal
2917 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2918 else
2919 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2920 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002921
Bram Moolenaara6878372014-03-22 21:02:50 +01002922" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002923endfun
2924
Bram Moolenaar9964e462007-05-05 17:54:07 +00002925" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002926" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002927" readcmd == %r : replace buffer with newly read file
2928" == 0r : read file at top of buffer
2929" == r : read file after current line
2930" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002931fun! s:NetrwGetFile(readcmd, tfile, method)
2932" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002933
2934 " readcmd=='t': simply do nothing
2935 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002936" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01002937" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002938 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002939 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002940
Bram Moolenaar9964e462007-05-05 17:54:07 +00002941 " get name of remote filename (ie. url and all)
2942 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002943" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002944
Bram Moolenaar9964e462007-05-05 17:54:07 +00002945 if exists("*NetReadFixup")
2946 " for the use of NetReadFixup (not otherwise used internally)
2947 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002948 endif
2949
Bram Moolenaar9964e462007-05-05 17:54:07 +00002950 if a:readcmd[0] == '%'
2951 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002952" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002953
2954 " rename the current buffer to the temp file (ie. tfile)
2955 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002956 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002957 else
2958 let tfile= a:tfile
2959 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002960 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002961
2962 " edit temporary file (ie. read the temporary file in)
2963 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002964" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002965 call zip#Browse(tfile)
2966 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002967" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002968 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002969 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002970" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002972 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002973" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002974 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002975 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002976" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002977 call tar#Browse(tfile)
2978 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002979" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002980 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002982" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002983 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002984 endif
2985
2986 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002987 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002988
Bram Moolenaar71badf92023-04-22 22:40:14 +01002989 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002990 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002991 " Note that isk must not include a "/" for scripts.vim
2992 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002993" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2994" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002995" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002996" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2997 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002998 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002999 filetype detect
3000" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003001 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003002" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003003 let line1 = 1
3004 let line2 = line("$")
3005
Bram Moolenaar8d043172014-01-23 14:24:41 +01003006 elseif !&ma
3007 " 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 +01003008 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003009" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003010 return
3011
Bram Moolenaar9964e462007-05-05 17:54:07 +00003012 elseif s:FileReadable(a:tfile)
3013 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003014" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003015 let curline = line(".")
3016 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003018 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003019 let line1= curline + 1
3020 let line2= line("$") - lastline + 1
3021
3022 else
3023 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3025" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003026 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003027" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003028 return
3029 endif
3030
3031 " User-provided (ie. optional) fix-it-up command
3032 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003033" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003034 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003035" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003036" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003037 endif
3038
Bram Moolenaaradc21822011-04-01 18:03:16 +02003039 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003040 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003041 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003042 endif
3043
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003044" 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 +00003045
3046 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003047" redraw!
3048
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003049" 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 +00003050" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003051endfun
3052
Bram Moolenaar9964e462007-05-05 17:54:07 +00003053" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003054" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003055" Input:
3056" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3057" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003058" b:netrw_method= 1: rcp
3059" 2: ftp + <.netrc>
3060" 3: ftp + machine, id, password, and [path]filename
3061" 4: scp
3062" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003063" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003064" 7: rsync
3065" 8: fetch
3066" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003067" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003068" g:netrw_machine= hostname
3069" b:netrw_fname = filename
3070" g:netrw_port = optional port number (for ftp)
3071" g:netrw_choice = copy of input url (choice)
3072fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003073" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003074
Bram Moolenaar251e1912011-06-19 05:09:16 +02003075 " sanity check: choice should have at least three slashes in it
3076 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3077 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3078 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003079" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003080 return
3081 endif
3082
Bram Moolenaar5c736222010-01-06 20:54:52 +01003083 " record current g:netrw_machine, if any
3084 " curmachine used if protocol == ftp and no .netrc
3085 if exists("g:netrw_machine")
3086 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003087" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003088 else
3089 let curmachine= "N O T A HOST"
3090 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003091 if exists("g:netrw_port")
3092 let netrw_port= g:netrw_port
3093 endif
3094
3095 " insure that netrw_ftp_cmd starts off every method determination
3096 " with the current g:netrw_ftp_cmd
3097 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003098
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003099 " initialization
3100 let b:netrw_method = 0
3101 let g:netrw_machine = ""
3102 let b:netrw_fname = ""
3103 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003104 let g:netrw_choice = a:choice
3105
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003107 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003108 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3109 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003110 " rcpurm : rcp://[user@]host/filename Use rcp
3111 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003113 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003114 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003115 " rsyncurm : rsync://host[:port]/path Use rsync
3116 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3117 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003118 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003119 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3120 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003121 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3122 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003123 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003124 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003125 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003126 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003128 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003130 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003131
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003132" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003134 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003135 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003136" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003137 let b:netrw_method = 1
3138 let userid = substitute(a:choice,rcpurm,'\1',"")
3139 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3140 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003141 if userid != ""
3142 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003144
Bram Moolenaaradc21822011-04-01 18:03:16 +02003145 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003146 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003147" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003148 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003149 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3150 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3151 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003152
Bram Moolenaar15146672011-10-20 22:22:38 +02003153 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003154 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003155" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 let b:netrw_method = 5
3157 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3158 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003159 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003160
Bram Moolenaaradc21822011-04-01 18:03:16 +02003161 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003163" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003165 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003166 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3167 else
3168 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3169 endif
3170 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003171
Bram Moolenaaradc21822011-04-01 18:03:16 +02003172 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003173 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003174" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003175 let b:netrw_method = 7
3176 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3177 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003178
Bram Moolenaaradc21822011-04-01 18:03:16 +02003179 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003180 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003181" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003182 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3184 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3185 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003186" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003187 if userid != ""
3188 let g:netrw_uid= userid
3189 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003190
Bram Moolenaaradc21822011-04-01 18:03:16 +02003191 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003192 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003193 call NetUserPass("ftp:".g:netrw_machine)
3194 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003195 " if there's a change in hostname, require password re-entry
3196 unlet s:netrw_passwd
3197 endif
3198 if exists("netrw_port")
3199 unlet netrw_port
3200 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003201 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003202
Bram Moolenaar446cb832008-06-24 21:56:24 +00003203 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003204 let b:netrw_method = 3
3205 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003206 let host= substitute(g:netrw_machine,'\..*$','','')
3207 if exists("s:netrw_hup[host]")
3208 call NetUserPass("ftp:".host)
3209
Nir Lichtman1e34b952024-05-08 19:19:34 +02003210 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003211" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3212" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003213 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003214 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003215" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003216 endif
3217 let b:netrw_method= 2
3218 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003219" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003220 let b:netrw_method= 2
3221 else
3222 if !exists("g:netrw_uid") || g:netrw_uid == ""
3223 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003224 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003225 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003226 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003227 endif
3228 let b:netrw_method= 3
3229 endif
3230 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003231
Bram Moolenaaradc21822011-04-01 18:03:16 +02003232 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003233 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003234" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 let b:netrw_method = 8
3236 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3237 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3238 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3239 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003240
Bram Moolenaaradc21822011-04-01 18:03:16 +02003241 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003242 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003243" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003245 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3246 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003247 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003248 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003249 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003250
Bram Moolenaaradc21822011-04-01 18:03:16 +02003251 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003253" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003254 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 let b:netrw_method = 3
3256 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3257 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003258
Bram Moolenaar9964e462007-05-05 17:54:07 +00003259 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003260 let b:netrw_method = 2
3261 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3262 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3263 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003264
Bram Moolenaaradc21822011-04-01 18:03:16 +02003265 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003266 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003267" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003268 let b:netrw_method = 9
3269 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3270 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003271
Bram Moolenaaradc21822011-04-01 18:03:16 +02003272 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003273 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003274" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003275 let b:netrw_method = 1
3276 let userid = substitute(a:choice,rcphf,'\2',"")
3277 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3278 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003279" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3280" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3281" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3282" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003283 if userid != ""
3284 let g:netrw_uid= userid
3285 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003286
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003287 " Method#10: file://user@hostname/...path-to-file {{{3
3288 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003289" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003290 let b:netrw_method = 10
3291 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003292" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003293
Bram Moolenaaradc21822011-04-01 18:03:16 +02003294 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003295 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003296 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003297 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003298 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003299 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003301 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003302
Bram Moolenaar81695252004-12-29 20:58:21 +00003303 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003304 " remove any leading [:#] from port number
3305 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3306 elseif exists("netrw_port")
3307 " retain port number as implicit for subsequent ftp operations
3308 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003309 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003310
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003311" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3312" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3313" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3314" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003315" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003316" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003317" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003318" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003319" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003320" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003322" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003323endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324
Bram Moolenaar9964e462007-05-05 17:54:07 +00003325" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003326" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003327" Usage: :call NetUserPass() -- will prompt for userid and password
3328" :call NetUserPass("uid") -- will prompt for password
3329" :call NetUserPass("uid","password") -- sets global userid and password
3330" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3331" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332fun! NetUserPass(...)
3333
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003334" call Dfunc("NetUserPass() a:0=".a:0)
3335
3336 if !exists('s:netrw_hup')
3337 let s:netrw_hup= {}
3338 endif
3339
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003341 " case: no input arguments
3342
3343 " change host and username if not previously entered; get new password
3344 if !exists("g:netrw_machine")
3345 let g:netrw_machine= input('Enter hostname: ')
3346 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003348 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349 let g:netrw_uid= input('Enter username: ')
3350 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003351 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003352 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003353
3354 " set up hup database
3355 let host = substitute(g:netrw_machine,'\..*$','','')
3356 if !exists('s:netrw_hup[host]')
3357 let s:netrw_hup[host]= {}
3358 endif
3359 let s:netrw_hup[host].uid = g:netrw_uid
3360 let s:netrw_hup[host].passwd = s:netrw_passwd
3361
3362 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003363 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003364
3365 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003366 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003367 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003368" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003369 let host = substitute(a:1,'^ftp:','','')
3370 let host = substitute(host,'\..*','','')
3371 if exists("s:netrw_hup[host]")
3372 let g:netrw_uid = s:netrw_hup[host].uid
3373 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003374" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3375" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003376 else
3377 let g:netrw_uid = input("Enter UserId: ")
3378 let s:netrw_passwd = inputsecret("Enter Password: ")
3379 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003380
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003381 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003382 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003383" 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 +02003384 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003385 if g:netrw_machine =~ '[0-9.]\+'
3386 let host= g:netrw_machine
3387 else
3388 let host= substitute(g:netrw_machine,'\..*$','','')
3389 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003390 else
3391 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003392 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003393 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003394" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003395 if exists("g:netrw_passwd")
3396 " ask for password if one not previously entered
3397 let s:netrw_passwd= g:netrw_passwd
3398 else
3399 let s:netrw_passwd = inputsecret("Enter Password: ")
3400 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003401 endif
3402
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003403" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003404 if exists("host")
3405 if !exists('s:netrw_hup[host]')
3406 let s:netrw_hup[host]= {}
3407 endif
3408 let s:netrw_hup[host].uid = g:netrw_uid
3409 let s:netrw_hup[host].passwd = s:netrw_passwd
3410 endif
3411
3412 elseif a:0 == 2
3413 let g:netrw_uid = a:1
3414 let s:netrw_passwd = a:2
3415
3416 elseif a:0 == 3
3417 " enter hostname, user-id, and password into the hup dictionary
3418 let host = substitute(a:1,'^\a\+:','','')
3419 let host = substitute(host,'\..*$','','')
3420 if !exists('s:netrw_hup[host]')
3421 let s:netrw_hup[host]= {}
3422 endif
3423 let s:netrw_hup[host].uid = a:2
3424 let s:netrw_hup[host].passwd = a:3
3425 let g:netrw_uid = s:netrw_hup[host].uid
3426 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003427" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3428" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003430
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003431" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433
Bram Moolenaar85850f32019-07-19 22:05:51 +02003434" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003435" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003436" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003438" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003439" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3440fun! s:ExplorePatHls(pattern)
3441" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3442 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003443" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003444 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003445" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003446 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3447" call Dret("s:ExplorePatHls repat<".repat.">")
3448 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003449endfun
3450
3451" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003452" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003453" 0: (user: <mb>) bookmark current directory
3454" 1: (user: <gb>) change to the bookmarked directory
3455" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003456" 3: (browsing) records current directory history
3457" 4: (user: <u>) go up (previous) directory, using history
3458" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003459" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003460fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003461" call Dfunc("s:NetrwBookHistHandler(chg=".a:chg." curdir<".a:curdir.">) cnt=".v:count." histcnt=".g:netrw_dirhistcnt." histmax=".g:netrw_dirhistmax)
Bram Moolenaarff034192013-04-24 18:51:19 +02003462 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3463" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3464 return
3465 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003466
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003467 let ykeep = @@
3468 let curbufnr = bufnr("%")
3469
Bram Moolenaar9964e462007-05-05 17:54:07 +00003470 if a:chg == 0
3471 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003472" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003473 if exists("s:netrwmarkfilelist_{curbufnr}")
3474 call s:NetrwBookmark(0)
3475 echo "bookmarked marked files"
3476 else
3477 call s:MakeBookmark(a:curdir)
3478 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003479 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003480
KSR-Yasudaf4498252023-10-06 03:34:17 +09003481 try
3482 call s:NetrwBookHistSave()
3483 catch
3484 endtry
3485
Bram Moolenaar9964e462007-05-05 17:54:07 +00003486 elseif a:chg == 1
3487 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003488" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003489 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003490" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003491 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003492 else
3493 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3494 endif
3495
3496 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003497" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003498 let didwork= 0
3499 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003500" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003501 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003502" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003503 let cnt= 1
3504 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003505" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003506 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003507 let didwork = 1
3508 let cnt = cnt + 1
3509 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003510 endif
3511
3512 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003513 " Note: history is saved only when PerformListing is done;
3514 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3515 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003516 let first = 1
3517 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003518 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003519 while ( first || cnt != g:netrw_dirhistcnt )
3520" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003521 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003522" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003523 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003524 let didwork= 1
3525 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003526 let histcnt = histcnt + 1
3527 let first = 0
3528 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003529 if cnt < 0
3530 let cnt= cnt + g:netrw_dirhistmax
3531 endif
3532 endwhile
3533 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003534 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003535 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003536 if didwork
3537 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3538 endif
3539
3540 elseif a:chg == 3
3541 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003542" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003543 if !exists("g:netrw_dirhistcnt") || !exists("g:netrw_dirhist_{g:netrw_dirhistcnt}") || g:netrw_dirhist_{g:netrw_dirhistcnt} != a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003544 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003545 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3546 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003547 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003548" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003549 endif
3550
3551 elseif a:chg == 4
3552 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003553" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003554 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3556 if g:netrw_dirhistcnt < 0
3557 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003558 endif
3559 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003560 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003561 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3563" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003564 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003565 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003566" call Decho("setl ma noro",'~'.expand("<slnum>"))
3567 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003568 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003569" call Decho("setl nomod",'~'.expand("<slnum>"))
3570" 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 +00003571 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003572" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3573 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003574 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003575 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003576 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003577 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003578 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003579 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003580 echo "Sorry, no predecessor directory exists yet"
3581 endif
3582
3583 elseif a:chg == 5
3584 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003585" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003586 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003587 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3588 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3589" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003590 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003591" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003592 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003593 sil! NetrwKeepj %d _
3594" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3595" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003596 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003597" 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 +02003598 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003599" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3600 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003601 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003602 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3603 if g:netrw_dirhistcnt < 0
3604 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003605 endif
3606 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003607 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003608 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003609 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003610 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003611 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003612
3613 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003614" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003615 if exists("s:netrwmarkfilelist_{curbufnr}")
3616 call s:NetrwBookmark(1)
3617 echo "removed marked files from bookmarks"
3618 else
3619 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003620 let iremove = v:count
3621 let dremove = g:netrw_bookmarklist[iremove - 1]
3622" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003623 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003624" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3625 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3626 echo "removed ".dremove." from g:netrw_bookmarklist"
3627" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003628 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003629" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003630
3631 try
3632 call s:NetrwBookHistSave()
3633 catch
3634 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003635 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003636 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003637 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003638 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003639" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003640endfun
3641
3642" ---------------------------------------------------------------------
3643" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003644" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003645" Sister function: s:NetrwBookHistSave()
3646fun! s:NetrwBookHistRead()
3647" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003648 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003649" call Dret("s:NetrwBookHistRead - nothing read (suppressed due to dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a").")")
Bram Moolenaarff034192013-04-24 18:51:19 +02003650 return
3651 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003652 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003653
3654 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003655 if !exists("s:netrw_initbookhist")
3656 let home = s:NetrwHome()
3657 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003658 if filereadable(s:NetrwFile(savefile))
3659" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003660 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003661 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003662
3663 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003664 if g:netrw_dirhistmax > 0
3665 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003666 if filereadable(s:NetrwFile(savefile))
3667" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003668 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003669 endif
3670 let s:netrw_initbookhist= 1
3671 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003672 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003673 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003674
Bram Moolenaar97d62492012-11-15 21:28:22 +01003675 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003676" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3677" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003678" call Dret("s:NetrwBookHistRead")
3679endfun
3680
3681" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003682" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683" Sister function: s:NetrwBookHistRead()
3684" I used to do this via viminfo but that appears to
3685" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003686" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3687" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003688" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003689fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003690" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003691 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003693 return
3694 endif
3695
Bram Moolenaar5c736222010-01-06 20:54:52 +01003696 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003697" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003698 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003699
3700 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003701 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003703 if g:netrw_use_noswf
3704 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3705 else
3706 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3707 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003708 setl nocin noai noci magic nospell nohid wig= noaw
3709 setl ma noro write
3710 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003711 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003712
Bram Moolenaar85850f32019-07-19 22:05:51 +02003713 " rename enew'd file: .netrwhist -- no attempt to merge
3714 " record dirhistmax and current dirhistcnt
3715 " save history
3716" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003717 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003718 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003719 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3720 if g:netrw_dirhistmax > 0
3721 let lastline = line("$")
3722 let cnt = g:netrw_dirhistcnt
3723 let first = 1
3724 while ( first || cnt != g:netrw_dirhistcnt )
3725 let lastline= lastline + 1
3726 if exists("g:netrw_dirhist_{cnt}")
3727 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3728" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3729 endif
3730 let first = 0
3731 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3732 if cnt < 0
3733 let cnt= cnt + g:netrw_dirhistmax
3734 endif
3735 endwhile
3736 exe "sil! w! ".savefile
3737" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3738 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003739
Bram Moolenaar85850f32019-07-19 22:05:51 +02003740 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003741 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003742 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003743" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003744 " merge and write .netrwbook
3745 let savefile= s:NetrwHome()."/.netrwbook"
3746
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003747 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003748 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003749 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003750 for bdm in booklist
3751 if index(g:netrw_bookmarklist,bdm) == -1
3752 call add(g:netrw_bookmarklist,bdm)
3753 endif
3754 endfor
3755 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003756 endif
3757
3758 " construct and save .netrwbook
3759 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003760 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003761" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003762 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003763
3764 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003765 let bgone= bufnr("%")
3766 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003767 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003768
3769" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003770endfun
3771
3772" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003773" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3774" list of the contents of a local or remote directory. It is assumed that the
3775" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3776" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003777" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003778fun! s:NetrwBrowse(islocal,dirname)
3779 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003780" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar85850f32019-07-19 22:05:51 +02003781" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3782" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3783" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003784
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003785 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3786 " This is useful when one edits a local file, then :e ., then :Rex
3787 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3788 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003789" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003790 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003791
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003792 " s:NetrwBrowse : initialize history {{{3
3793 if !exists("s:netrw_initbookhist")
3794 NetrwKeepj call s:NetrwBookHistRead()
3795 endif
3796
3797 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003798 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003799 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003800" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801 else
3802 let dirname= a:dirname
3803 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003804
Bram Moolenaar85850f32019-07-19 22:05:51 +02003805 " repoint t:netrw_lexbufnr if appropriate
3806 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3807" call Decho("set repointlexbufnr to true!")
3808 let repointlexbufnr= 1
3809 endif
3810
3811 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003812 if exists("s:netrw_skipbrowse")
3813 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003814" 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 +01003815" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003816 return
3817 endif
3818 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003819 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003820" call Dret("s:NetrwBrowse : missing shellescape()")
3821 return
3822 endif
3823 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003824 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003825" call Dret("s:NetrwBrowse : missing fnameescape()")
3826 return
3827 endif
3828
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003830 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003831
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003832 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003833 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3834 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3835" call Decho("clearing marked files",'~'.expand("<slnum>"))
3836 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3837 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003838 endif
3839
3840 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003841 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003842" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3843" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003844 if s:NetrwLcd(dirname)
3845" call Dret("s:NetrwBrowse : lcd failure")
3846 return
3847 endif
3848 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003849" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003850
Bram Moolenaar5c736222010-01-06 20:54:52 +01003851 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003852 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003853" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003854 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003855" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003856 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003857 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003858 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003859" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003860
3861 " remove any filetype indicator from end of dirname, except for the
3862 " "this is a directory" indicator (/).
3863 " There shouldn't be one of those here, anyway.
3864 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003865" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866 call s:RemotePathAnalysis(dirname)
3867
3868 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3869 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003870 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003871 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003872" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003873 let b:netrw_curdir = dirname
3874 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003875 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003876 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3877 sil call netrw#NetRead(2,url)
3878 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003879" call Decho("url<".url.">",'~'.expand("<slnum>"))
3880" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3881" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003882 if s:path =~ '.bz2'
3883 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3884 elseif s:path =~ '.gz'
3885 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3886 elseif s:path =~ '.gz'
3887 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3888 else
3889 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3890 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003891 endif
3892
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003893 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003894 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003895 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003896" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003897 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003898" 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 +00003899
Bram Moolenaar446cb832008-06-24 21:56:24 +00003900" call Dret("s:NetrwBrowse : file<".s:fname.">")
3901 return
3902 endif
3903
Bram Moolenaaradc21822011-04-01 18:03:16 +02003904 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003905 call s:UseBufWinVars()
3906
3907 " set up some variables {{{3
3908 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003909 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003910 let s:last_sort_by = g:netrw_sort_by
3911
3912 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003913 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003914
Bram Moolenaar97d62492012-11-15 21:28:22 +01003915 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003916" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003917 let svpos = winsaveview()
3918" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003919 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003920
Bram Moolenaar446cb832008-06-24 21:56:24 +00003921 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003922 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3923 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3924" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3925" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3926 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3927 else
3928" " call Decho("2match none",'~'.expand("<slnum>"))
3929 2match none
3930 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003931 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003932 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003933 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003934" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003935 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003936" 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 +01003937" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003938 return
3939 endif
3940
3941 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003942" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003943 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003944 if b:netrw_curdir =~ '[/\\]$'
3945 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3946 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003947 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003948 let b:netrw_curdir= b:netrw_curdir."/"
3949 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003950 if b:netrw_curdir == ''
3951 if has("amiga")
3952 " On the Amiga, the empty string connotes the current directory
3953 let b:netrw_curdir= getcwd()
3954 else
3955 " under unix, when the root directory is encountered, the result
3956 " from the preceding substitute is an empty string.
3957 let b:netrw_curdir= '/'
3958 endif
3959 endif
3960 if !a:islocal && b:netrw_curdir !~ '/$'
3961 let b:netrw_curdir= b:netrw_curdir.'/'
3962 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003963" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003964
3965 " ------------
3966 " (local only) {{{3
3967 " ------------
3968 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003969" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003970
3971 " Set up ShellCmdPost handling. Append current buffer to browselist
3972 call s:LocalFastBrowser()
3973
3974 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3975 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003976" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3977" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003978 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003979 if s:NetrwLcd(b:netrw_curdir)
3980" call Dret("s:NetrwBrowse : lcd failure")
3981 return
3982 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003983 endif
3984 endif
3985
3986 " --------------------------------
3987 " remote handling: {{{3
3988 " --------------------------------
3989 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003990" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003991
Bram Moolenaar97d62492012-11-15 21:28:22 +01003992 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003993" 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 +02003994 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003995 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003996" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003997 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3998 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3999 if dirname !~ '/$'
4000 let dirname= dirname.'/'
4001 endif
4002 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004004 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004005 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007 endif
4008
4009 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4010 if dirname !~ dirpat
4011 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004012 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004013 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004014 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004015" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004016 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004017" 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 +00004018" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4019 return
4020 endif
4021 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004022" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004023 endif " (additional remote handling)
4024
Bram Moolenaar85850f32019-07-19 22:05:51 +02004025 " -------------------------------
4026 " Perform Directory Listing: {{{3
4027 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004028 NetrwKeepj call s:NetrwMaps(a:islocal)
4029 NetrwKeepj call s:NetrwCommands(a:islocal)
4030 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004031
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004032 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004033 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004034" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4035
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004036 " If there is a rexposn: restore position with rexposn
4037 " Otherwise : set rexposn
4038 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004039" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4040 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4041 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4042 NetrwKeepj exe w:netrw_bannercnt
4043 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004044 else
4045 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4046 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004047 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004048 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004049" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004050 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004051 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004052
Bram Moolenaar85850f32019-07-19 22:05:51 +02004053 " repoint t:netrw_lexbufnr if appropriate
4054 if exists("repointlexbufnr")
4055 let t:netrw_lexbufnr= bufnr("%")
4056" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4057 endif
4058
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059 " restore position
4060 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004061" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4062 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004063 endif
4064
Bram Moolenaara6878372014-03-22 21:02:50 +01004065 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004066 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4067 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004068" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4069" 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 +02004070" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004071 return
4072endfun
4073
4074" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004075" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4076" may not apply correctly; ie. netrw's idea of the current directory may
4077" differ from vim's. This function insures that netrw's idea of the current
4078" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004079" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004080fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004081" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4082" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4083" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4084" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4085" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004086
4087 " clean up any leading treedepthstring
4088 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4089 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004090" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004091 else
4092 let fname= a:fname
4093 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004094
4095 if g:netrw_keepdir
4096 " vim's idea of the current directory possibly may differ from netrw's
4097 if !exists("b:netrw_curdir")
4098 let b:netrw_curdir= getcwd()
4099 endif
4100
Nir Lichtman1e34b952024-05-08 19:19:34 +02004101 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004102 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004103 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004104 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004105" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004106 else
4107 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004108 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004109" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110 endif
4111
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004115" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116 else
4117 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004119" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120 endif
4121 else
4122 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004123 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004124" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4125" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4126" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004127 endif
4128
Bram Moolenaar85850f32019-07-19 22:05:51 +02004129" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004130 return ret
4131endfun
4132
4133" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004134" s:NetrwFileInfo: supports qf (query for file information) {{{2
4135fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004136" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004137 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004138 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004139 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004140 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004141 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004142 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004143 let lsopt= "-lsadh --si"
4144 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004145" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004146 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004147
4148 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004149 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004150" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004151
Bram Moolenaara6878372014-03-22 21:02:50 +01004152 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004153 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004154" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004155
4156 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004157 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004158" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004159
Bram Moolenaar446cb832008-06-24 21:56:24 +00004160 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004161" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004162 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004163" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004164 endif
4165 else
4166 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004167" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4168 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004169 let fname= substitute(a:fname,".$","","")
4170 else
4171 let fname= a:fname
4172 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173 let t = getftime(s:NetrwFile(fname))
4174 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004175 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004176 let sz= s:NetrwHumanReadable(sz)
4177 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004178 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4179" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004180 endif
4181 else
4182 echo "sorry, \"qf\" not supported yet for remote files"
4183 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004184 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004185" call Dret("s:NetrwFileInfo")
4186endfun
4187
4188" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004189" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4190fun! s:NetrwFullPath(filename)
4191" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4192 let filename= a:filename
4193 if filename !~ '^/'
4194 let filename= resolve(getcwd().'/'.filename)
4195 endif
4196 if filename != "/" && filename =~ '/$'
4197 let filename= substitute(filename,'/$','','')
4198 endif
4199" " call Dret("s:NetrwFullPath <".filename.">")
4200 return filename
4201endfun
4202
4203" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004204" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004205" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004206" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004207" Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004208fun! s:NetrwGetBuffer(islocal,dirname)
4209" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004210" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." hid=".&hid,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004211" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4212" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004213 let dirname= a:dirname
4214
4215 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004216" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004217 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004218" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004219 let s:netrwbuf= {}
4220 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004221" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4222" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4223
4224 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4225 let bufnum = -1
4226
4227 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4228 if has_key(s:netrwbuf,"NetrwTreeListing")
4229 let bufnum= s:netrwbuf["NetrwTreeListing"]
4230 else
4231 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4232 endif
4233" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4234 if !bufexists(bufnum)
4235 call remove(s:netrwbuf,"NetrwTreeListing"])
4236 let bufnum= -1
4237 endif
4238 elseif bufnr("NetrwTreeListing") != -1
4239 let bufnum= bufnr("NetrwTreeListing")
4240" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4241 else
4242" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4243 let bufnum= -1
4244 endif
4245
4246 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004247 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004248" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004249 if !bufexists(bufnum)
4250 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4251 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004252 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004253
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004255" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004256 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004257 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4259
Bram Moolenaar71badf92023-04-22 22:40:14 +01004260 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004261 " IF the buffer already has the desired name
4262 " AND it is empty
4263 let curbuf = bufname("%")
4264 if curbuf == '.'
4265 let curbuf = getcwd()
4266 endif
4267" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004268" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004269" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4270" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4271" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4272" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4273 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004274" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4275 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004276 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004277" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004278 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004279 " Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems
Bram Moolenaar446cb832008-06-24 21:56:24 +00004280
4281 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004282 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004283" 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 +00004284 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004285" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004286 " name the buffer
4287 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4288 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004289" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004290 let w:netrw_treebufnr = bufnr("%")
4291 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004292 if g:netrw_use_noswf
4293 setl nobl bt=nofile noswf
4294 else
4295 setl nobl bt=nofile
4296 endif
4297 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4298 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4299 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4300 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004301" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004302 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004303 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004304 " enter the new buffer into the s:netrwbuf dictionary
4305 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4306" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4307" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004308 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004309" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004310
4311 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004312" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004313 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004315 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004316
4317 if &ft == "netrw"
4318" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4319 exe "sil! NetrwKeepj noswapfile b ".bufnum
4320" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004321 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004322" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4323 call s:NetrwEditBuf(bufnum)
4324" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004325 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004326" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004327 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004328 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004329 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004330
4331 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004332 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004333
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004334 if line("$") <= 1 && getline(1) == ""
4335 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004336 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004337" 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>"))
4338" 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 +01004339" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4340 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004341
Bram Moolenaar97d62492012-11-15 21:28:22 +01004342 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004343" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004344 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004345 sil NetrwKeepj %d _
4346" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4347" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004348" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but refreshing due to g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004349 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004350
Bram Moolenaar446cb832008-06-24 21:56:24 +00004351 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004352" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4353" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004354 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004356 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004357" 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>"))
4358" 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 +01004359" 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 +00004360 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004361
Bram Moolenaar446cb832008-06-24 21:56:24 +00004362 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004363" 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>"))
4364" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4365" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004366 return 1
4367 endif
4368 endif
4369
4370 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4371 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4372 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4373 " med 1 D H
4374 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004375" 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 +00004376 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004377 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004378 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004379
4380 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004381" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4382" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4383 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004384
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385" 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>"))
4386" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4387" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004388 return 0
4389endfun
4390
4391" ---------------------------------------------------------------------
4392" s:NetrwGetcwd: get the current directory. {{{2
4393" Change backslashes to forward slashes, if any.
4394" If doesc is true, escape certain troublesome characters
4395fun! s:NetrwGetcwd(doesc)
4396" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4397 let curdir= substitute(getcwd(),'\\','/','ge')
4398 if curdir !~ '[\/]$'
4399 let curdir= curdir.'/'
4400 endif
4401 if a:doesc
4402 let curdir= fnameescape(curdir)
4403 endif
4404" call Dret("NetrwGetcwd <".curdir.">")
4405 return curdir
4406endfun
4407
4408" ---------------------------------------------------------------------
4409" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4410fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004411" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4412" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4413 let keepsol= &l:sol
4414 setl nosol
4415
Bram Moolenaar446cb832008-06-24 21:56:24 +00004416 call s:UseBufWinVars()
4417
4418 " insure that w:netrw_liststyle is set up
4419 if !exists("w:netrw_liststyle")
4420 if exists("g:netrw_liststyle")
4421 let w:netrw_liststyle= g:netrw_liststyle
4422 else
4423 let w:netrw_liststyle= s:THINLIST
4424 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004425" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 endif
4427
4428 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4429 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004430" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004431 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004432 let dirname= "./"
4433 let curline= getline('.')
4434
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004435 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004436 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004437 let s:netrw_skipbrowse= 1
4438 echo 'Pressing "s" also works'
4439
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004440 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441 let s:netrw_skipbrowse= 1
4442 echo 'Press "S" to edit sorting sequence'
4443
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004444 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004445 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004446 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004448 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004449 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004450 let s:netrw_skipbrowse= 1
4451 echo 'Pressing "a" also works'
4452
4453 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004454 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004455 endif
4456
4457 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004458" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004459 NetrwKeepj norm! 0
4460 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004461
4462 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004463" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004464 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4466
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004467 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004468" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004469 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004470 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004471
4472 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004473" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004474 let dirname= getline('.')
4475
4476 if !exists("b:netrw_cpf")
4477 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004478 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 +01004479 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004480" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481 endif
4482
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004485" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4486" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004487 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004488 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004489 else
4490 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004491 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004492 endif
Enno3146d632024-07-04 19:44:42 +02004493
4494 let dict={}
4495 " save the unnamed register and register 0-9 and a
4496 let dict.a=[getreg('a'), getregtype('a')]
4497 for i in range(0, 9)
4498 let dict[i] = [getreg(i), getregtype(i)]
4499 endfor
4500 let dict.unnamed = [getreg(''), getregtype('')]
4501
Bram Moolenaarc236c162008-07-13 17:41:49 +00004502 let eofname= filestart + b:netrw_cpf + 1
4503 if eofname <= col("$")
4504 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004505 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004506 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004507 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004508 endif
Enno3146d632024-07-04 19:44:42 +02004509
Bram Moolenaar446cb832008-06-24 21:56:24 +00004510 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004511 call s:RestoreRegister(dict)
4512
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004513" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004514 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004515" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004516 endif
4517
4518 " symlinks are indicated by a trailing "@". Remove it before further processing.
4519 let dirname= substitute(dirname,"@$","","")
4520
4521 " executables are indicated by a trailing "*". Remove it before further processing.
4522 let dirname= substitute(dirname,"\*$","","")
4523
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004524 let &l:sol= keepsol
4525
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526" call Dret("s:NetrwGetWord <".dirname.">")
4527 return dirname
4528endfun
4529
4530" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004531" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4532" g:netrw_bufsettings will be used after the listing is produced.
4533" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004534fun! s:NetrwListSettings(islocal)
4535" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004536" 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 +00004537 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004538" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4539 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4540 setl bt=nofile nobl ma nonu nowrap noro nornu
4541 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004542 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004543 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004545" call Dredir("ls!","s:NetrwListSettings")
4546" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004547 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004548 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004549 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004550 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004551 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004552 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004553 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004554" 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 +00004555" call Dret("s:NetrwListSettings")
4556endfun
4557
4558" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004559" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004560" islocal=0: remote browsing
4561" =1: local browsing
4562fun! s:NetrwListStyle(islocal)
4563" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004564
Bram Moolenaar97d62492012-11-15 21:28:22 +01004565 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004566 let fname = s:NetrwGetWord()
4567 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004568 let svpos = winsaveview()
4569" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004570 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004571" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4572" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4573" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004574
Bram Moolenaar85850f32019-07-19 22:05:51 +02004575 " repoint t:netrw_lexbufnr if appropriate
4576 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4577" call Decho("set repointlexbufnr to true!")
4578 let repointlexbufnr= 1
4579 endif
4580
Bram Moolenaar446cb832008-06-24 21:56:24 +00004581 if w:netrw_liststyle == s:THINLIST
4582 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004583" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4585
4586 elseif w:netrw_liststyle == s:LONGLIST
4587 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004588" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004589 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4590
4591 elseif w:netrw_liststyle == s:WIDELIST
4592 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004593" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004594 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4595
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004596 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004597" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004598 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4599
4600 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004601 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004602 let g:netrw_liststyle = s:THINLIST
4603 let w:netrw_liststyle = g:netrw_liststyle
4604 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4605 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004606 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004608
4609 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004610" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4611 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004612 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004613" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004614 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004615" 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 +00004616
4617 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004618" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004619 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004620 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004621
Bram Moolenaar85850f32019-07-19 22:05:51 +02004622 " repoint t:netrw_lexbufnr if appropriate
4623 if exists("repointlexbufnr")
4624 let t:netrw_lexbufnr= bufnr("%")
4625" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4626 endif
4627
Bram Moolenaar13600302014-05-22 18:26:40 +02004628 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004629" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4630 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004631 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004632
4633" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4634endfun
4635
4636" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004637" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4638fun! s:NetrwBannerCtrl(islocal)
4639" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4640
Bram Moolenaar97d62492012-11-15 21:28:22 +01004641 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004642 " toggle the banner (enable/suppress)
4643 let g:netrw_banner= !g:netrw_banner
4644
4645 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004646 let svpos= winsaveview()
4647" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004648 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4649
4650 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004651 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4652 let fname= s:NetrwGetWord()
4653 sil NetrwKeepj $
4654 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4655" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4656 if result <= 0 && exists("w:netrw_bannercnt")
4657 exe "NetrwKeepj ".w:netrw_bannercnt
4658 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004659 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004660 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004661" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4662endfun
4663
4664" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004665" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4666"
4667" No bang: enters files/directories into Netrw's bookmark system
4668" No argument and in netrw buffer:
4669" if there are marked files: bookmark marked files
4670" otherwise : bookmark file/directory under cursor
4671" No argument and not in netrw buffer: bookmarks current open file
4672" Has arguments: globs them individually and bookmarks them
4673"
4674" With bang: deletes files/directories from Netrw's bookmark system
4675fun! s:NetrwBookmark(del,...)
4676" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4677 if a:0 == 0
4678 if &ft == "netrw"
4679 let curbufnr = bufnr("%")
4680
4681 if exists("s:netrwmarkfilelist_{curbufnr}")
4682 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004683" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004684 let svpos = winsaveview()
4685" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004686 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004687 for fname in s:netrwmarkfilelist_{curbufnr}
4688 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4689 endfor
4690 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4691 call s:NetrwUnmarkList(curbufnr,curdir)
4692 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004693" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4694 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004695 else
4696 let fname= s:NetrwGetWord()
4697 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4698 endif
4699
4700 else
4701 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004702" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004703 let fname= expand("%")
4704 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4705 endif
4706
4707 else
4708 " bookmark specified files
4709 " attempts to infer if working remote or local
4710 " by deciding if the current file begins with an url
4711 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004712 let islocal= expand("%") !~ '^\a\{3,}://'
4713" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004714 let i = 1
4715 while i <= a:0
4716 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004717 if v:version > 704 || (v:version == 704 && has("patch656"))
4718 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004719 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004720 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004721 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004722 else
4723 let mbfiles= [a:{i}]
4724 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004725" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004726 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004727" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004728 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4729 endfor
4730 let i= i + 1
4731 endwhile
4732 endif
4733
4734 " update the menu
4735 call s:NetrwBookmarkMenu()
4736
4737" call Dret("s:NetrwBookmark")
4738endfun
4739
4740" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004741" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4742" .2.[cnt] for bookmarks, and
4743" .3.[cnt] for history
4744" (see s:NetrwMenu())
4745fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004746 if !exists("s:netrw_menucnt")
4747 return
4748 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004749" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004750
4751 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004752 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004753 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004754" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004755 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4756 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004757 endif
4758 if !exists("s:netrw_initbookhist")
4759 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004760 endif
4761
4762 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004763 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004764 let cnt= 1
4765 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004766" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004767 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004768
4769 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004770 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004771
4772 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004773 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 +01004774 let cnt= cnt + 1
4775 endfor
4776
4777 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004778
4779 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004780 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004781 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004782 let first = 1
4783 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004784 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004785 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004786 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004787 if exists("g:netrw_dirhist_{cnt}")
4788 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004789" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004790 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4791 endif
4792 let first = 0
4793 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4794 if cnt < 0
4795 let cnt= cnt + g:netrw_dirhistmax
4796 endif
4797 endwhile
4798 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004799
Bram Moolenaar9964e462007-05-05 17:54:07 +00004800 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004801" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004802endfun
4803
4804" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004805" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4806" directory and a new directory name. Also, if the
4807" "new directory name" is actually a file,
4808" NetrwBrowseChgDir() edits the file.
4809fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004810" call Dfunc("s:NetrwBrowseChgDir(islocal=".a:islocal."> newdir<".a:newdir.">) a:0=".a:0." win#".winnr()." curpos<".string(getpos("."))."> b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004811" 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 +00004812
Bram Moolenaar97d62492012-11-15 21:28:22 +01004813 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004814 if !exists("b:netrw_curdir")
4815 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4816 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004817 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004818" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4819" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004820" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004821" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004822 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004823 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004824" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004825
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004826 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004827" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004828 call s:SavePosn(s:netrw_posn)
4829 NetrwKeepj call s:NetrwOptionsSave("s:")
4830 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004831 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004832 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004833 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004834 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004835 endif
4836 let newdir = a:newdir
4837 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004838 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004839" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004840" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004841" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004842
4843 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004844" call Decho('(s:NetrwBrowseChgDir) ignore [return]s when done in banner (g:netrw_banner='.g:netrw_banner.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004845 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004846" call Decho("win#".winnr()." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a')." line(.)#".line('.')." line($)#".line("#"),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004847 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004848 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004849" 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 +01004850 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004851" 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 +02004852 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004853 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004854 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004855 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004856" 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 +01004857 endif
4858 endif
4859" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004860" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004861 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004862
Bram Moolenaar446cb832008-06-24 21:56:24 +00004863 " set up o/s-dependent directory recognition pattern
4864 if has("amiga")
4865 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004866 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867 let dirpat= '[\/]$'
4868 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004869" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004870
4871 if dirname !~ dirpat
4872 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004873 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004875" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004876 endif
4877
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004878" 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 +01004879 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004880 " ------------------------------
4881 " NetrwBrowseChgDir: edit a file {{{3
4882 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004883" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004884
Bram Moolenaar97d62492012-11-15 21:28:22 +01004885 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004886 let s:rexposn_{bufnr("%")}= winsaveview()
4887" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004888" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4889" 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 +01004890
Bram Moolenaar446cb832008-06-24 21:56:24 +00004891 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004892" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4893" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004894" let newdir = s:NetrwTreePath(s:netrw_treetop)
4895" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004896 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004897 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4898" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4899 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 if dirname =~ '/$'
4901 let dirname= dirname.newdir
4902 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004903 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004904 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004905" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4906" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004907 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004908" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004909 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004910 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004911 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004912 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004913" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004914 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004915 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004916" call Decho("edit-a-file: (a:0=".a:0."<1) set up windows for editing<".fnameescape(dirname)."> didsplit=".(exists("s:didsplit")? s:didsplit : "doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004917 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004918 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004919 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004920" " call Decho("edit-a-file: s:didsplit does not exist; g:netrw_browse_split=".string(g:netrw_browse_split)." win#".winnr()." g:netrw_chgwin=".g:netrw_chgwin",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004921 if type(g:netrw_browse_split) == 3
4922 " open file in server
4923 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004924" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004925 call s:NetrwServerEdit(a:islocal,dirname)
4926" call Dret("s:NetrwBrowseChgDir")
4927 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004928
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004929 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004930 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004931" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004932 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4933 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004934 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004935 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004936 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004937 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004938
Bram Moolenaar446cb832008-06-24 21:56:24 +00004939 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004940 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004941" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004942 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4943 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004944 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004945 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004946 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004947 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004948
Bram Moolenaar446cb832008-06-24 21:56:24 +00004949 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004950 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004951" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004952 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004953 if !exists("b:netrw_curdir")
4954 let b:netrw_curdir= getcwd()
4955 endif
4956 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004957
Bram Moolenaar446cb832008-06-24 21:56:24 +00004958 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004959 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004960" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004961 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004962 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004963" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004964 return
4965 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004966 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004967
Bram Moolenaar9964e462007-05-05 17:54:07 +00004968 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004969 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004970" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004971 call s:NetrwMenu(0)
4972 " optional change to window
4973 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004974" call Decho("edit-a-file: changing window to #".g:netrw_chgwin.": (due to g:netrw_chgwin)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02004975 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004976 " if g:netrw_chgwin is set to one more than the last window, then
4977 " vertically split the last window to make that window available.
4978 let curwin= winnr()
4979 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4980 vs
4981 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004982 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004983 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004984 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004985 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004986 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004987
Bram Moolenaar9964e462007-05-05 17:54:07 +00004988 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004989
Bram Moolenaar446cb832008-06-24 21:56:24 +00004990 " the point where netrw actually edits the (local) file
4991 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004992 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004993 if !&mod
4994 " if e the new file would fail due to &mod, then don't change any of the flags
4995 let dolockout= 1
4996 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004997 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004998" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004999 " some like c-^ to return to the last edited file
5000 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005001 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5002 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005003 call s:NetrwEditFile("e","",dirname)
5004" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005005 " COMBAK -- cuc cul related
5006 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005007 if &hidden || &bufhidden == "hide"
5008 " file came from vim's hidden storage. Don't "restore" options with it.
5009 let dorestore= 0
5010 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005011 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005012" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005013 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005014
5015 " handle g:Netrw_funcref -- call external-to-netrw functions
5016 " This code will handle g:Netrw_funcref as an individual function reference
5017 " or as a list of function references. It will ignore anything that's not
5018 " a function reference. See :help Funcref for information about function references.
5019 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005020" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005021 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005022" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005023 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005025" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005026 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005027 if type(Fncref) == 2
5028 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005029 endif
5030 endfor
5031 endif
5032 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005033 endif
5034
5035 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005036 " ----------------------------------------------------
5037 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5038 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005039" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005040 let dirname = newdir
5041 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005042 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005043 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005044
5045 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005046 " ---------------------------------------------
5047 " NetrwBrowseChgDir: refresh the directory list {{{3
5048 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005049" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005050 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005051 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005052
5053 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005054 " --------------------------------------
5055 " NetrwBrowseChgDir: go up one directory {{{3
5056 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005057" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005058
5059 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5060 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5062" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005063 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005064 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005065 endif
5066
5067 if has("amiga")
5068 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005069" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005070 if a:islocal
5071 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5072 let dirname= substitute(dirname,'/$','','')
5073 else
5074 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5075 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005076" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005077
Nir Lichtman1e34b952024-05-08 19:19:34 +02005078 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005079 " windows
5080 if a:islocal
5081 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5082 if dirname == ""
5083 let dirname= '/'
5084 endif
5085 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005086 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005087 endif
5088 if dirname =~ '^\a:$'
5089 let dirname= dirname.'/'
5090 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005091" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005092
Bram Moolenaar446cb832008-06-24 21:56:24 +00005093 else
5094 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005095" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../" and unix or cygwin','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005096 if a:islocal
5097 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5098 if dirname == ""
5099 let dirname= '/'
5100 endif
5101 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005102 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005104" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005105 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005106 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005107 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005108
5109 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005110 " --------------------------------------
5111 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5112 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005113" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005114 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5115" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005116 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005117 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005118" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5119 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005120 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005121 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005122" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005123 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005124 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005125" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005126
5127 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005128" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005129 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005130" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005131 let haskey= 1
5132 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005133" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005134 endif
5135
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005136 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005137" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005138 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 if has_key(w:netrw_treedict,treedir."/")
5140 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005141" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005142 let haskey = 1
5143 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005144" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005145 endif
5146 endif
5147
5148 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005149" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005150 if !haskey && treedir =~ '/$'
5151 let treedir= substitute(treedir,'/$','','')
5152 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005153" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005154 let haskey = 1
5155 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005156" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005157 endif
5158 endif
5159
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005160" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005161 if haskey
5162 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005163" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005165" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5166" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005167 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005168 else
5169 " go down one directory
5170 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005171" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5172" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005173 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005174 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005175" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005176 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005177
5178 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005179 " ----------------------------------------
5180 " NetrwBrowseChgDir: Go down one directory {{{3
5181 " ----------------------------------------
5182 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005183" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005184 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005185 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005186 endif
5187
Bram Moolenaar97d62492012-11-15 21:28:22 +01005188 " --------------------------------------
5189 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5190 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005191 if dorestore
5192 " dorestore is zero'd when a local file was hidden or bufhidden;
5193 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005194" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005195 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005196" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005197" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005198 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005199 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005200" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005201 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005202" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5203" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005204 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005205" 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 +02005206 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5208" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005209 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005210" 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 +02005211 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005212 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005213 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005214 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005215
Bram Moolenaar446cb832008-06-24 21:56:24 +00005216" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5217 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005218endfun
5219
5220" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005221" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5222" for thin, long, and wide: cursor placed just after banner
5223" for tree, keeps cursor on current filename
5224fun! s:NetrwBrowseUpDir(islocal)
5225" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005226 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5227 " this test needed because occasionally this function seems to be incorrectly called
5228 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005229 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005230 " directories.
5231" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5232 return
5233 endif
5234
Bram Moolenaara6878372014-03-22 21:02:50 +01005235 norm! 0
5236 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005237" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005238 let curline= getline(".")
5239 let swwline= winline() - 1
5240 if exists("w:netrw_treetop")
5241 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005242 elseif exists("b:netrw_curdir")
5243 let w:netrw_treetop= b:netrw_curdir
5244 else
5245 let w:netrw_treetop= getcwd()
5246 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005248 let curfile = getline(".")
5249 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005250 if a:islocal
5251 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5252 else
5253 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5254 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005255" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5256" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5257 if w:netrw_treetop == '/'
5258 keepj call search('^\M'.curfile,"w")
5259 elseif curfile == '../'
5260 keepj call search('^\M'.curfile,"wb")
5261 else
5262" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5263 while 1
5264 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5265 let treepath= s:NetrwTreePath(w:netrw_treetop)
5266" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5267 if treepath == curpath
5268 break
5269 endif
5270 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005271 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005272
Bram Moolenaara6878372014-03-22 21:02:50 +01005273 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005274" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005275 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005276 if exists("b:netrw_curdir")
5277 let curdir= b:netrw_curdir
5278 else
5279 let curdir= expand(getcwd())
5280 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005281 if a:islocal
5282 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5283 else
5284 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5285 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005286 call s:RestorePosn(s:netrw_posn)
5287 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005288 let curdir= '\<'. escape(curdir, '~'). '/'
5289 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005290 endif
5291" call Dret("s:NetrwBrowseUpDir")
5292endfun
5293
5294" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005295" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005296" given filename; typically this means given their extension.
5297" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005298fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005299 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005300" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005301
Bram Moolenaar91359012019-11-30 17:57:03 +01005302 if a:remote == 0 && isdirectory(a:fname)
5303 " if its really just a local directory, then do a "gf" instead
5304" call Decho("remote≡0 and a:fname<".a:fname."> ".(isdirectory(a:fname)? "is a directory" : "is not a directory"),'~'.expand("<slnum>"))
Bram Moolenaar29634562020-01-09 21:46:04 +01005305" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5306 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005307" call Dret("netrw#BrowseX")
5308 return
5309 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5310 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5311" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5312" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5313" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5314" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5315 norm! gf
5316" call Dret("netrw#BrowseX")
5317 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005318 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005319" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005320
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005321 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5322 let remote = a:remote
5323 else
5324 let remote = 0
5325 endif
5326
Bram Moolenaar97d62492012-11-15 21:28:22 +01005327 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005328 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005329" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005330
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005331 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5332 let awkeep = &aw
5333 set noaw
5334
Bram Moolenaar5c736222010-01-06 20:54:52 +01005335 " special core dump handler
5336 if a:fname =~ '/core\(\.\d\+\)\=$'
5337 if exists("g:Netrw_corehandler")
5338 if type(g:Netrw_corehandler) == 2
5339 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005340" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005341 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005342 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005344" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005346 if type(Fncref) == 2
5347 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005348 endif
5349 endfor
5350 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005351" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005352 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005353 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005354 let &aw= awkeep
5355" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005356 return
5357 endif
5358 endif
5359
Bram Moolenaar446cb832008-06-24 21:56:24 +00005360 " set up the filename
5361 " (lower case the extension, make a local copy of a remote file)
5362 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005363 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005364 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005365 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005366 if exten =~ "[\\/]"
5367 let exten= ""
5368 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005369" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005370
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005371 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005372 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005373" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005374 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005375 call netrw#NetRead(3,a:fname)
5376 " attempt to rename tempfile
5377 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005378 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005379" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5380" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005381 if s:netrw_tmpfile != newname && newname != ""
5382 if rename(s:netrw_tmpfile,newname) == 0
5383 " renaming succeeded
5384" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5385 let fname= newname
5386 else
5387 " renaming failed
5388" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5389 let fname= s:netrw_tmpfile
5390 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005391 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005392 let fname= s:netrw_tmpfile
5393 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005394 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005395" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005396 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005397 " special ~ handler for local
5398 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005399" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5400 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005401 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005402 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005403" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5404" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005405
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005406 " set up redirection (avoids browser messages)
5407 " by default, g:netrw_suppress_gx_mesg is true
5408 if g:netrw_suppress_gx_mesg
5409 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005410 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005411 let redir= substitute(&srr,"%s","nul","")
5412 else
5413 let redir= substitute(&srr,"%s","/dev/null","")
5414 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005415 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005416 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005417 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005418 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005419 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005420 else
5421 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005422 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005423" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005424
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005425 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005426 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005427" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005428 if g:netrw_browsex_viewer =~ '\s'
5429 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5430 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5431 let oviewer = ''
5432 let cnt = 1
5433 while !executable(viewer) && viewer != oviewer
5434 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5435 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5436 let cnt = cnt + 1
5437 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005438" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005439 endwhile
5440 else
5441 let viewer = g:netrw_browsex_viewer
5442 let viewopt = ""
5443 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005444" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005445 endif
5446
5447 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005448" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005449 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005450" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005451 let ret= netrwFileHandlers#Invoke(exten,fname)
5452
5453 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005454" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005455 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005456 let ret= v:shell_error
5457
Nir Lichtman1e34b952024-05-08 19:19:34 +02005458 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005459" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005460 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005461 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005462 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005463 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005464 else
5465 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5466 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005467 let ret= v:shell_error
5468
Bram Moolenaar97d62492012-11-15 21:28:22 +01005469 elseif has("win32unix")
5470 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005471" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005472 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005473" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005474 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005475 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005476" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005477 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005478 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005479" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005480 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005481 else
5482 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5483 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005484 let ret= v:shell_error
5485
Bram Moolenaar85850f32019-07-19 22:05:51 +02005486 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005487" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5488 if a:fname =~ '^https\=://'
5489 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5490 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005491" call Decho("fname<".fname.">")
5492" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005493 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5494
5495 else
5496 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5497 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005498 let ret= v:shell_error
5499
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005500 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5501" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5502 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5503 let ret= v:shell_error
5504
5505 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5506" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5507 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5508 let ret= v:shell_error
5509
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005510 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005511" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005512 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005513 let ret= v:shell_error
5514
5515 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005516" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005517 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005518 let ret= v:shell_error
5519
5520 else
5521 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005522" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005523 let ret= netrwFileHandlers#Invoke(exten,fname)
5524 endif
5525
5526 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5527 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005528" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005529 let ret= netrwFileHandlers#Invoke(exten,fname)
5530 endif
5531
Bram Moolenaarc236c162008-07-13 17:41:49 +00005532 " restoring redraw! after external file handlers
5533 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005534
5535 " cleanup: remove temporary file,
5536 " delete current buffer if success with handler,
5537 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005538 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005539 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005540" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005541"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005542" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543" endif
5544
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005545 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005546 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005547 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005548 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005550 if use_ctrlo
5551 exe "sil! NetrwKeepj norm! \<c-o>"
5552 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005554" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005555 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005556 let @@ = ykeep
5557 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005558
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005559" call Dret("netrw#BrowseX")
5560endfun
5561
5562" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005563" netrw#GX: gets word under cursor for gx support {{{2
5564" See also: netrw#BrowseXVis
5565" netrw#BrowseX
5566fun! netrw#GX()
5567" call Dfunc("netrw#GX()")
5568 if &ft == "netrw"
5569 let fname= s:NetrwGetWord()
5570 else
5571 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5572 endif
5573" call Dret("netrw#GX <".fname.">")
5574 return fname
5575endfun
5576
5577" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005578" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5579fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005580 let dict={}
5581 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005582 norm! gv"ay
5583 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005584 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005585 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005586endfun
5587
5588" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005589" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5590" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5591" to become an unlisted buffer, so in that case don't bwipe it.
5592fun! s:NetrwBufRename(newname)
5593" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5594" call Dredir("ls!","s:NetrwBufRename (before rename)")
5595 let oldbufname= bufname(bufnr("%"))
5596" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5597
5598 if oldbufname != a:newname
5599" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5600 let b:junk= 1
5601" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5602 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005603" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005604 let oldbufnr= bufnr(oldbufname)
5605" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5606" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5607 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5608" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5609 exe "bwipe! ".oldbufnr
5610" else " Decho
5611" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005612" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5613" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5614" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005615 endif
5616" call Dredir("ls!","s:NetrwBufRename (after rename)")
5617" else " Decho
5618" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5619 endif
5620
5621" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5622endfun
5623
5624" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005625" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005626fun! netrw#CheckIfRemote(...)
5627" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5628 if a:0 > 0
5629 let curfile= a:1
5630 else
5631 let curfile= expand("%")
5632 endif
5633" call Decho("curfile<".curfile.">")
5634 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005635" call Dret("netrw#CheckIfRemote 1")
5636 return 1
5637 else
5638" call Dret("netrw#CheckIfRemote 0")
5639 return 0
5640 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005641endfun
5642
5643" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005644" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5645fun! s:NetrwChgPerm(islocal,curdir)
5646" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005647 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005648 call inputsave()
5649 let newperm= input("Enter new permission: ")
5650 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005651 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5652 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5653" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654 call system(chgperm)
5655 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005656 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005657 endif
5658 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005659 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005660 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005661 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005662" call Dret("s:NetrwChgPerm")
5663endfun
5664
5665" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005666" s:CheckIfKde: checks if kdeinit is running {{{2
5667" Returns 0: kdeinit not running
5668" 1: kdeinit is running
5669fun! s:CheckIfKde()
5670" call Dfunc("s:CheckIfKde()")
5671 " seems kde systems often have gnome-open due to dependencies, even though
5672 " gnome-open's subsidiary display tools are largely absent. Kde systems
5673 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5674 if !exists("s:haskdeinit")
5675 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005676 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005677 if v:shell_error
5678 let s:haskdeinit = 0
5679 endif
5680 else
5681 let s:haskdeinit= 0
5682 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005683" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005684 endif
5685
5686" call Dret("s:CheckIfKde ".s:haskdeinit)
5687 return s:haskdeinit
5688endfun
5689
5690" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005691" s:NetrwClearExplore: clear explore variables (if any) {{{2
5692fun! s:NetrwClearExplore()
5693" call Dfunc("s:NetrwClearExplore()")
5694 2match none
5695 if exists("s:explore_match") |unlet s:explore_match |endif
5696 if exists("s:explore_indx") |unlet s:explore_indx |endif
5697 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5698 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5699 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5700 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5701 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5702 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5703 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5704" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005705" call Dret("s:NetrwClearExplore")
5706endfun
5707
5708" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005709" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5710fun! s:NetrwEditBuf(bufnum)
5711" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5712 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5713" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5714 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5715 else
5716" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005717 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005718 endif
5719" call Dret("s:NetrwEditBuf")
5720endfun
5721
5722" ---------------------------------------------------------------------
5723" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5724" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5725fun! s:NetrwEditFile(cmd,opt,fname)
5726" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5727 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5728" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5729 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5730 else
5731" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005732 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5733 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5734 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005735 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5736 endif
5737" call Dret("s:NetrwEditFile")
5738endfun
5739
5740" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005741" s:NetrwExploreListUniq: {{{2
5742fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005743" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005744
5745 " this assumes that the list is already sorted
5746 let newexplist= []
5747 for member in a:explist
5748 if !exists("uniqmember") || member != uniqmember
5749 let uniqmember = member
5750 let newexplist = newexplist + [ member ]
5751 endif
5752 endfor
5753
Bram Moolenaar15146672011-10-20 22:22:38 +02005754" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005755 return newexplist
5756endfun
5757
5758" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005759" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5760fun! s:NetrwForceChgDir(islocal,newdir)
5761" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005762 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005763 if a:newdir !~ '/$'
5764 " ok, looks like force is needed to get directory-style treatment
5765 if a:newdir =~ '@$'
5766 let newdir= substitute(a:newdir,'@$','/','')
5767 elseif a:newdir =~ '[*=|\\]$'
5768 let newdir= substitute(a:newdir,'.$','/','')
5769 else
5770 let newdir= a:newdir.'/'
5771 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005772" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005773 else
5774 " should already be getting treatment as a directory
5775 let newdir= a:newdir
5776 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005777 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005778 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005779 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005780" call Dret("s:NetrwForceChgDir")
5781endfun
5782
5783" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005784" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005785" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5786" expr : this is the expression to follow the directory. Will use s:ComposePath()
5787" pare =1: remove the current directory from the resulting glob() filelist
5788" =0: leave the current directory in the resulting glob() filelist
5789fun! s:NetrwGlob(direntry,expr,pare)
5790" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005791 if netrw#CheckIfRemote()
5792 keepalt 1sp
5793 keepalt enew
5794 let keep_liststyle = w:netrw_liststyle
5795 let w:netrw_liststyle = s:THINLIST
5796 if s:NetrwRemoteListing() == 0
5797 keepj keepalt %s@/@@
5798 let filelist= getline(1,$)
5799 q!
5800 else
5801 " remote listing error -- leave treedict unchanged
5802 let filelist= w:netrw_treedict[a:direntry]
5803 endif
5804 let w:netrw_liststyle= keep_liststyle
5805 else
Christian Brabandt14879472024-06-13 21:25:35 +02005806 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005807 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005808 " escape [ so it is not detected as wildcard character, see :h wildcard
5809 let path= substitute(path, '[', '[[]', 'g')
5810 endif
5811 if v:version > 704 || (v:version == 704 && has("patch656"))
5812 let filelist= glob(path,0,1,1)
5813 else
5814 let filelist= glob(path,0,1)
5815 endif
5816 if a:pare
5817 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5818 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005819 endif
5820" call Dret("s:NetrwGlob ".string(filelist))
5821 return filelist
5822endfun
5823
5824" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005825" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5826fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005827" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005828 if a:newfile =~ '[/@*=|\\]$'
5829 let newfile= substitute(a:newfile,'.$','','')
5830 else
5831 let newfile= a:newfile
5832 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005833 if a:islocal
5834 call s:NetrwBrowseChgDir(a:islocal,newfile)
5835 else
5836 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5837 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005838" call Dret("s:NetrwForceFile")
5839endfun
5840
5841" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005842" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5843" and switches the hiding mode. The actual hiding is done by
5844" s:NetrwListHide().
5845" g:netrw_hide= 0: show all
5846" 1: show not-hidden files
5847" 2: show hidden files only
5848fun! s:NetrwHide(islocal)
5849" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005850 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005851 let svpos= winsaveview()
5852" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005853
5854 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005855" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5856" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005857
5858 " hide the files in the markfile list
5859 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005860" 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 +00005861 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5862 " remove fname from hiding list
5863 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5864 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5865 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005866" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005867 else
5868 " append fname to hiding list
5869 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5870 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5871 else
5872 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5873 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005874" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005875 endif
5876 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005877 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005878 let g:netrw_hide= 1
5879
5880 else
5881
5882 " switch between show-all/show-not-hidden/show-hidden
5883 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005884 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005886 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005887 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005888" call Dret("NetrwHide")
5889 return
5890 endif
5891 endif
5892
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005893 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005894" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5895 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005896 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005897" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005898endfun
5899
5900" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005901" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5902fun! s:NetrwHideEdit(islocal)
5903" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5904
5905 let ykeep= @@
5906 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005907 let svpos= winsaveview()
5908" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005909
5910 " get new hiding list from user
5911 call inputsave()
5912 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5913 call inputrestore()
5914 let g:netrw_list_hide= newhide
5915" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5916
5917 " refresh the listing
5918 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5919
5920 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005921" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5922 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005923 let @@= ykeep
5924
5925" call Dret("NetrwHideEdit")
5926endfun
5927
5928" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005929" s:NetrwHidden: invoked by "gh" {{{2
5930fun! s:NetrwHidden(islocal)
5931" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005932 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005933 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005934 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005935" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005936
5937 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005938 " remove .file pattern from hiding list
5939" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005940 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005941 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005942" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5944 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005945" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005946 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5947 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005948 if g:netrw_list_hide =~ '^,'
5949 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5950 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005951
5952 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005953 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005954" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5955 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005956 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005957" call Dret("s:NetrwHidden")
5958endfun
5959
5960" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005961" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5962fun! s:NetrwHome()
5963 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005964 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005965 else
5966 " go to vim plugin home
5967 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005968 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005969 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005970 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005971 let home= basehome."/.vim"
5972 break
5973 endif
5974 endfor
5975 if home == ""
5976 " just pick the first directory
5977 let home= substitute(&rtp,',.*$','','')
5978 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005979 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005980 let home= substitute(home,'/','\\','g')
5981 endif
5982 endif
5983 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005984 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005985" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005986 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005987" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005988 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005989 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005990" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005991 call mkdir(home)
5992 endif
5993 endif
5994 let g:netrw_home= home
5995 return home
5996endfun
5997
5998" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005999" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6000fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006001 if exists("s:netrwdrag")
6002 return
6003 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006004 if &ft != "netrw"
6005 return
6006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006007" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006008
Bram Moolenaar97d62492012-11-15 21:28:22 +01006009 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006010 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006011 while getchar(0) != 0
6012 "clear the input stream
6013 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006014 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006015 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006016 let mouse_lnum = v:mouse_lnum
6017 let wlastline = line('w$')
6018 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006019" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6020" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006021 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6022 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006023 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006024" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6025 return
6026 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006027 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006028 " 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 +01006029 " without this test when its disabled.
6030 " 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 +01006031" 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 +01006032 if v:mouse_col > virtcol('.')
6033 let @@= ykeep
6034" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6035 return
6036 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006037
Bram Moolenaar446cb832008-06-24 21:56:24 +00006038 if a:islocal
6039 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006040 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006041 endif
6042 else
6043 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006044 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006045 endif
6046 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006047 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006048" call Dret("s:NetrwLeftmouse")
6049endfun
6050
6051" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006052" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6053fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006054 if &ft != "netrw"
6055 return
6056 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006057" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6058 call s:NetrwMarkFileTgt(a:islocal)
6059" call Dret("s:NetrwCLeftmouse")
6060endfun
6061
6062" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006063" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6064" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006065" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006066" a:islocal=2 : <c-r> used, remote
6067" a:islocal=3 : <c-r> used, local
6068fun! s:NetrwServerEdit(islocal,fname)
6069" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6070 let islocal = a:islocal%2 " =0: remote =1: local
6071 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006072" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006073
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006074 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006075 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006076 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006077" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006078 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006079 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006080 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6081 unlet s:netrw_browse_split_{winnr()}
6082 endif
6083 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6084" call Dret("s:NetrwServerEdit")
6085 return
6086 endif
6087
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006088" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006089 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006091
6092 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006093" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006094 let srvrname = g:netrw_browse_split[0]
6095 let tabnum = g:netrw_browse_split[1]
6096 let winnum = g:netrw_browse_split[2]
6097
6098 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006099" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006100
6101 if !ctrlr
6102 " user must have closed the server window and the user did not use <c-r>, but
6103 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006104" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006105 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006106 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006107 endif
6108 let g:netrw_browse_split= 0
6109 if exists("s:netrw_browse_split_".winnr())
6110 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6111 endif
6112 call s:NetrwBrowseChgDir(islocal,a:fname)
6113" call Dret("s:NetrwServerEdit")
6114 return
6115
6116 elseif has("win32") && executable("start")
6117 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006118" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006119 call system("start gvim --servername ".srvrname)
6120
6121 else
6122 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006123" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006124 call system("gvim --servername ".srvrname)
6125 endif
6126 endif
6127
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006129 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6130 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006131 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006132
6133 else
6134
6135 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6136
6137 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006138" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006139 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006140 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006141 endif
6142 let g:netrw_browse_split= 0
6143 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6144" call Dret("s:NetrwServerEdit")
6145 return
6146
6147 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 if has("win32") && executable("start")
6150 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006151" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006152 call system("start gvim --servername ".g:netrw_servername)
6153 else
6154 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006155" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006156 call system("gvim --servername ".g:netrw_servername)
6157 endif
6158 endif
6159 endif
6160
6161 while 1
6162 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006163" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6164 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006165 break
6166 catch /^Vim\%((\a\+)\)\=:E241/
6167 sleep 200m
6168 endtry
6169 endwhile
6170
6171 if exists("g:netrw_browse_split")
6172 if type(g:netrw_browse_split) != 3
6173 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6174 endif
6175 unlet g:netrw_browse_split
6176 endif
6177 let g:netrw_browse_split= [g:netrw_servername,1,1]
6178 endif
6179
6180 else
6181 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6182 endif
6183
6184" call Dret("s:NetrwServerEdit")
6185endfun
6186
6187" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006188" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6189fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006190 if &ft != "netrw"
6191 return
6192 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006193" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006194
Bram Moolenaar8d043172014-01-23 14:24:41 +01006195 let s:ngw= s:NetrwGetWord()
6196 call s:NetrwMarkFile(a:islocal,s:ngw)
6197
6198" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006199endfun
6200
6201" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006202" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6203" Used to mark multiple files.
6204fun! s:NetrwSLeftdrag(islocal)
6205" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6206 if !exists("s:netrwdrag")
6207 let s:netrwdrag = winnr()
6208 if a:islocal
6209 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006210 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006211 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006212 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006213 endif
6214 let ngw = s:NetrwGetWord()
6215 if !exists("s:ngw") || s:ngw != ngw
6216 call s:NetrwMarkFile(a:islocal,ngw)
6217 endif
6218 let s:ngw= ngw
6219" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6220endfun
6221
6222" ---------------------------------------------------------------------
6223" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6224fun! s:NetrwSLeftrelease(islocal)
6225" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6226 if exists("s:netrwdrag")
6227 nunmap <s-leftrelease>
6228 let ngw = s:NetrwGetWord()
6229 if !exists("s:ngw") || s:ngw != ngw
6230 call s:NetrwMarkFile(a:islocal,ngw)
6231 endif
6232 if exists("s:ngw")
6233 unlet s:ngw
6234 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006235 unlet s:netrwdrag
6236 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006237" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006238endfun
6239
6240" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006241" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6242" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006243fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006244" call Dfunc("s:NetrwListHide() g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02006245" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006246 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006247
6248 " find a character not in the "hide" string to use as a separator for :g and :v commands
Bram Moolenaar85850f32019-07-19 22:05:51 +02006249 " How-it-works: take the hiding command, convert it into a range.
6250 " Duplicate characters don't matter.
6251 " Remove all such characters from the '/~@#...890' string.
6252 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006253" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006254 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006255 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006256" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006257
6258 while listhide != ""
6259 if listhide =~ ','
6260 let hide = substitute(listhide,',.*$','','e')
6261 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6262 else
6263 let hide = listhide
6264 let listhide = ""
6265 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006266" call Decho("..extracted pattern from listhide: hide<".hide."> g:netrw_sort_by<".g:netrw_sort_by.'>','~'.expand("<slnum>"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006267 if g:netrw_sort_by =~ '^[ts]'
6268 if hide =~ '^\^'
6269" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6270 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6271 elseif hide =~ '^\\(\^'
6272 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6273 endif
6274" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6275 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006276
6277 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006278" call Decho("..prune the list by hiding any files which ".((g:netrw_hide == 1)? "" : "don't")."match hide<".hide.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006279 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006280" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006281 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006282 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006283" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006284 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006285 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006286" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006287 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006288
Bram Moolenaar446cb832008-06-24 21:56:24 +00006289 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006290 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006291" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006292 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006293" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006294 endif
6295
Bram Moolenaaradc21822011-04-01 18:03:16 +02006296 " remove any blank lines that have somehow remained.
6297 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006298 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006299
Bram Moolenaar97d62492012-11-15 21:28:22 +01006300 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006301" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006302endfun
6303
6304" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006305" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006306" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006307fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006308" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006309
Bram Moolenaar97d62492012-11-15 21:28:22 +01006310 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006311 " get name of new directory from user. A bare <CR> will skip.
6312 " if its currently a directory, also request will be skipped, but with
6313 " a message.
6314 call inputsave()
6315 let newdirname= input("Please give directory name: ")
6316 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006317" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006318
6319 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006320 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006321" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006322 return
6323 endif
6324
6325 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006326" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006327
6328 " Local mkdir:
6329 " sanity checks
6330 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006331" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6332 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006333 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006334 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006335 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006336 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006337" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006338 return
6339 endif
6340 if s:FileReadable(fullnewdir)
6341 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006342 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006343 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006344 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006345" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006346 return
6347 endif
6348
6349 " requested new local directory is neither a pre-existing file or
6350 " directory, so make it!
6351 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006352 if has("unix")
6353 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6354 else
6355 call mkdir(fullnewdir,"p")
6356 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006357 else
6358 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006359 if s:NetrwLcd(b:netrw_curdir)
6360" call Dret("s:NetrwMakeDir : lcd failure")
6361 return
6362 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006363" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006364 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006365 if v:shell_error != 0
6366 let @@= ykeep
6367 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 +01006368" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006369 return
6370 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006371 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006372" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006373 if s:NetrwLcd(netrw_origdir)
6374" call Dret("s:NetrwBrowse : lcd failure")
6375 return
6376 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006377 endif
6378 endif
6379
6380 if v:shell_error == 0
6381 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006382" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006383 let svpos= winsaveview()
6384" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006385 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006386" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6387 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006388 elseif !exists("g:netrw_quiet")
6389 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6390 endif
6391" redraw!
6392
6393 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006394 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006395" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006396 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6397 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006398 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006399 if v:shell_error == 0
6400 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006401 let svpos= winsaveview()
6402" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006403 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006404" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6405 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006406 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006407 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006408 endif
6409" redraw!
6410
6411 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006412 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006413 let svpos= winsaveview()
6414" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006415" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006416 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006417" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006418 let remotepath= b:netrw_fname
6419 else
6420 let remotepath= ""
6421 endif
6422 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006423 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006424" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6425 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006426
Bram Moolenaar446cb832008-06-24 21:56:24 +00006427 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006428 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006429 let svpos= winsaveview()
6430" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006431" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006432 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006433" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006434 let remotepath= b:netrw_fname
6435 else
6436 let remotepath= ""
6437 endif
6438 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006439 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006440" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6441 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006442 endif
6443
Bram Moolenaar97d62492012-11-15 21:28:22 +01006444 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006445" call Dret("s:NetrwMakeDir")
6446endfun
6447
6448" ---------------------------------------------------------------------
6449" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6450fun! s:TreeSqueezeDir(islocal)
6451" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6452 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6453 " its a tree-listing style
6454 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006455 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006456 let depth = strchars(substitute(curdepth,' ','','g'))
6457 let srch = -1
6458" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6459" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006460" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006461" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6462 if depth >= 2
6463 NetrwKeepj norm! 0
6464 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6465 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6466" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6467" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6468 elseif depth == 1
6469 NetrwKeepj norm! 0
6470 let treedepthchr= substitute(s:treedepthstring,' ','','')
6471 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6472" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6473 endif
6474 if srch > 0
6475" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6476 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6477 exe srch
6478 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006479 endif
6480" call Dret("s:TreeSqueezeDir")
6481endfun
6482
6483" ---------------------------------------------------------------------
6484" s:NetrwMaps: {{{2
6485fun! s:NetrwMaps(islocal)
6486" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6487
Bram Moolenaar85850f32019-07-19 22:05:51 +02006488 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006489 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006490" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006491 if !hasmapto("<Plug>NetrwReturn")
6492 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006493" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006494 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6495 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006496" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006497 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6498 endif
6499 endif
6500 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006501" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006502 endif
6503
Bram Moolenaar85850f32019-07-19 22:05:51 +02006504 " generate default <Plug> maps {{{3
6505 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006506 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006507 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6508 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6509 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6510 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6511 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6512 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6513 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6514 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6515 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6516 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6517" ---------------------------------------------------------------------
6518" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6519" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6520" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6521" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6522" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6523" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6524" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6525" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6526" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6527" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6528" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6529" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6530" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6531" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6532" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6533" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6534" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6535" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6536" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6537" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6538" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6539" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6540" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6541" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6542" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6543" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6544" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6545" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6546" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6547" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6548" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6549" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6550" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6551" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6552" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6553" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6554" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6555" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6556" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6557" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6558" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6559" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6560" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6561" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6562" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6563" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6564" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6565
Bram Moolenaara6878372014-03-22 21:02:50 +01006566 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006567" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006568 " local normal-mode maps {{{3
6569 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6570 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6571 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6572 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6573 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6574 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6575 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6576 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6577 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6578 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6579 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6580" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006581 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6582 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6583 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006584 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006585 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006586 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6587 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6588 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6589 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006590 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6591 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6592 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6593 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6594 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6595 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6596 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6597 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6599 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6600 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6601 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6602 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006603 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006604 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006605 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6606 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6607 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6608 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6609 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006610 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006612 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6613 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006614 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6615 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6616 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006617 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006618 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006619 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6620 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006621 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006622 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006623 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6624 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6625 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006626 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6627 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006628
6629 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 +01006630 if !hasmapto('<Plug>NetrwHideEdit')
6631 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006632 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006633 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006634 if !hasmapto('<Plug>NetrwRefresh')
6635 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006636 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006637 nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006638 if s:didstarstar || !mapcheck("<s-down>","n")
6639 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006640 endif
6641 if s:didstarstar || !mapcheck("<s-up>","n")
6642 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006643 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006644 if !hasmapto('<Plug>NetrwTreeSqueeze')
6645 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006646 endif
6647 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006648 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6649 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006650 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6651 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6652 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6653 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6654 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6655 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6656 imap <buffer> <leftmouse> <Plug>ILeftmouse
6657 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006658 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6659 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6660 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6661 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6662 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006663 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006664 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6665 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006666 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006667 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6668 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6669 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6670 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6671 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6672 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6673 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006674 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6675
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006676 " support user-specified maps
6677 call netrw#UserMaps(1)
6678
Bram Moolenaar85850f32019-07-19 22:05:51 +02006679 else
6680 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006681" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006682 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006683 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6684 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6685 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6686 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6687 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6688 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6689 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6690 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6691 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6692 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6693 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6694" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006695 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6696 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6697 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6698 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6699 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6700 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6701 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6702 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006703 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006704 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006705 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6706 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6707 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6709 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6710 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6712 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6713 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6714 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6715 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006716 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006717 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006718 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6719 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6720 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6721 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6722 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006723 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6724 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6725 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6726 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006727 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006728 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6729 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006730 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006731 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 +01006732 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6733 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6734 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6735 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6736 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6737 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6738 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6739 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6740 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006741 if !hasmapto('<Plug>NetrwHideEdit')
6742 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006743 endif
6744 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6745 if !hasmapto('<Plug>NetrwRefresh')
6746 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006747 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006748 if !hasmapto('<Plug>NetrwTreeSqueeze')
6749 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006750 endif
6751 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006752
6753 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006754 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006755
6756 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6757 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006758 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006759 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006760 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006761 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006762 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006763 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006764 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006765 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006766 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006767 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006768 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6769 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6770 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006772 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006773 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6774 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006775 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006776 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6777 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6778 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6779 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6780 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6781 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6782 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006783 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006784
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006785 " support user-specified maps
6786 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006787 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006788
6789" call Dret("s:NetrwMaps")
6790endfun
6791
6792" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006793" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006794" If -buffer, the command is only available from within netrw buffers
6795" Otherwise, the command is available from any window, so long as netrw
6796" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006797fun! s:NetrwCommands(islocal)
6798" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6799
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006800 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6801 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006802 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 +01006803 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006804 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006805 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006806 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006807 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006808 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006809
6810" call Dret("s:NetrwCommands")
6811endfun
6812
6813" ---------------------------------------------------------------------
6814" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6815" glob()ing only works with local files
6816fun! s:NetrwMarkFiles(islocal,...)
6817" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006818 let curdir = s:NetrwGetCurdir(a:islocal)
6819 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006820 while i <= a:0
6821 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006822 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006823 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006824 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006825 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006826 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006827 else
6828 let mffiles= [a:{i}]
6829 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006830" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006831 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006832" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006833 call s:NetrwMarkFile(a:islocal,mffile)
6834 endfor
6835 let i= i + 1
6836 endwhile
6837" call Dret("s:NetrwMarkFiles")
6838endfun
6839
6840" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006841" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006842fun! s:NetrwMarkTarget(...)
6843" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6844 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006845 let curdir = s:NetrwGetCurdir(1)
6846 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006847 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006848 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6849 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006850 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006851" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006852 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006853 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6854 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006855 let svpos = winsaveview()
6856" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006857 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006858" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6859 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006860" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006861endfun
6862
6863" ---------------------------------------------------------------------
6864" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6865" mark and unmark files. If a markfile list exists,
6866" then the rename and delete functions will use it instead
6867" of whatever may happen to be under the cursor at that
6868" moment. When the mouse and gui are available,
6869" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006870"
6871" Creates two lists
6872" s:netrwmarkfilelist -- holds complete paths to all marked files
6873" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6874"
6875" Creates a marked file match string
6876" s:netrwmarfilemtch_# -- used with 2match to display marked files
6877"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006878" Creates a buffer version of islocal
6879" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006880fun! s:NetrwMarkFile(islocal,fname)
6881" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006882" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006883
6884 " sanity check
6885 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006886" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006887 return
6888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006889 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006890
Bram Moolenaar97d62492012-11-15 21:28:22 +01006891 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006892 let curbufnr= bufnr("%")
yasuda38cfa2b2024-08-22 20:54:47 +02006893 let leader= '\(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006894 if a:fname =~ '\a$'
6895 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6896 else
6897 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6898 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006899
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006900 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006901 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006902" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6903" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6904" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006905 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006906
6907 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006908 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006909" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006910 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006911 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006912
6913 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006914 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006915" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006916 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6917 if s:netrwmarkfilelist_{curbufnr} == []
6918 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006919" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006920 call s:NetrwUnmarkList(curbufnr,curdir)
6921 else
6922 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006923" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006925 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006926 for fname in s:netrwmarkfilelist_{curbufnr}
6927 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006928 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006929 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006930 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006931 endif
6932 let first= 0
6933 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006934" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006935 endif
6936 endif
6937
6938 else
6939 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006940" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006941
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006942" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006943 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006944 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6945" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006946
6947 " build initial markfile matching pattern
6948 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006949 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006950 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006951 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006953" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006954 endif
6955
6956 " handle global markfilelist
6957 if exists("s:netrwmarkfilelist")
6958 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6959 if index(s:netrwmarkfilelist,dname) == -1
6960 " append new filename to global markfilelist
6961 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006962" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006963 else
6964 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006965" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6966" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006967 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006968" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006970" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006971 unlet s:netrwmarkfilelist
6972 endif
6973 endif
6974 else
6975 " initialize new global-directory markfilelist
6976 let s:netrwmarkfilelist= []
6977 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006978" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006979 endif
6980
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006981 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006982 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6983 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6984" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6985 if exists("g:did_drchip_netrwlist_syntax")
6986 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6987 endif
6988 else
6989" " call Decho("2match none",'~'.expand("<slnum>"))
6990 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006991 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006992 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006993 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006994" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6995" call Dret("s:NetrwMarkFile : s:netrwmarkfilelist_".curbufnr."<".(exists("s:netrwmarkfilelist_{curbufnr}")? string(s:netrwmarkfilelist_{curbufnr}) : " doesn't exist")."> (buf#".curbufnr."list)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006996endfun
6997
6998" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006999" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7000" mA: move the argument list to marked file list (tomflist=1)
7001" Uses the global marked file list
7002fun! s:NetrwMarkFileArgList(islocal,tomflist)
7003" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7004
7005 let svpos = winsaveview()
7006" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7007 let curdir = s:NetrwGetCurdir(a:islocal)
7008 let curbufnr = bufnr("%")
7009
7010 if a:tomflist
7011 " mA: move argument list to marked file list
7012 while argc()
7013 let fname= argv(0)
7014" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7015 exe "argdel ".fnameescape(fname)
7016 call s:NetrwMarkFile(a:islocal,fname)
7017 endwhile
7018
7019 else
7020 " ma: move marked file list to argument list
7021 if exists("s:netrwmarkfilelist")
7022
7023 " for every filename in the marked list
7024 for fname in s:netrwmarkfilelist
7025" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7026 exe "argadd ".fnameescape(fname)
7027 endfor " for every file in the marked list
7028
7029 " unmark list and refresh
7030 call s:NetrwUnmarkList(curbufnr,curdir)
7031 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7032" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7033 NetrwKeepj call winrestview(svpos)
7034 endif
7035 endif
7036
7037" call Dret("s:NetrwMarkFileArgList")
7038endfun
7039
7040" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007041" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7042" compress/decompress files using the programs
7043" in g:netrw_compress and g:netrw_uncompress,
7044" using g:netrw_compress_suffix to know which to
7045" do. By default:
7046" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007047" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007048fun! s:NetrwMarkFileCompress(islocal)
7049" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007050 let svpos = winsaveview()
7051" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007052 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007053 let curbufnr = bufnr("%")
7054
Bram Moolenaarff034192013-04-24 18:51:19 +02007055 " sanity check
7056 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007057 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007058" call Dret("s:NetrwMarkFileCompress")
7059 return
7060 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007061" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007062
Bram Moolenaar446cb832008-06-24 21:56:24 +00007063 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007064
7065 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007066 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007067 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007068" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007069 if exists("g:netrw_decompress['".sfx."']")
7070 " fname has a suffix indicating that its compressed; apply associated decompression routine
7071 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007072" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007073 let exe= netrw#WinPath(exe)
7074 if a:islocal
7075 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007076 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007078 call system(exe." ".fname)
7079 if v:shell_error
7080 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007081 endif
7082 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007083 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7084 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007085 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007086
Bram Moolenaarff034192013-04-24 18:51:19 +02007087 endif
7088 unlet sfx
7089
Bram Moolenaar446cb832008-06-24 21:56:24 +00007090 if exists("exe")
7091 unlet exe
7092 elseif a:islocal
7093 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007094 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007095 if v:shell_error
7096 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7097 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007098 else
7099 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007100 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007101 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007102 endfor " for every file in the marked list
7103
Bram Moolenaar446cb832008-06-24 21:56:24 +00007104 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007105 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007106" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7107 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007108 endif
7109" call Dret("s:NetrwMarkFileCompress")
7110endfun
7111
7112" ---------------------------------------------------------------------
7113" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7114" If no marked files, then set up directory as the
7115" target. Currently does not support copying entire
7116" directories. Uses the local-buffer marked file list.
7117" Returns 1=success (used by NetrwMarkFileMove())
7118" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007119fun! s:NetrwMarkFileCopy(islocal,...)
7120" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7121
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007122 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007123 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007124 if b:netrw_curdir !~ '/$'
7125 if !exists("b:netrw_curdir")
7126 let b:netrw_curdir= curdir
7127 endif
7128 let b:netrw_curdir= b:netrw_curdir."/"
7129 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007130
Bram Moolenaarff034192013-04-24 18:51:19 +02007131 " sanity check
7132 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007133 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007134" call Dret("s:NetrwMarkFileCopy")
7135 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007136 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007137" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007138
Bram Moolenaar446cb832008-06-24 21:56:24 +00007139 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007140 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007141" call Dret("s:NetrwMarkFileCopy 0")
7142 return 0
7143 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007144" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007145
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007146 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007147 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007148" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007149 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007150 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7151" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7152 return
7153 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007154
7155 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007156 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007157 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7158 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007159" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007160 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007161 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7162 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007163" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007164 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007165 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007166 let oldname = a:1
7167 else
7168 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007169" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007170 let s:recursive= 1
7171 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7172 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7173 if ret == 0
7174 break
7175 endif
7176 endfor
7177 unlet s:recursive
7178 call s:NetrwUnmarkList(curbufnr,curdir)
7179" call Dret("s:NetrwMarkFileCopy ".ret)
7180 return ret
7181 endif
7182
7183 call inputsave()
7184 let newname= input("Copy ".oldname." to : ",oldname,"file")
7185 call inputrestore()
7186 if newname == ""
7187" call Dret("s:NetrwMarkFileCopy 0")
7188 return 0
7189 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007190 let args= s:ShellEscape(oldname)
7191 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007192 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007193 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7194 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007195 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007196 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007197 let args= substitute(args,'/','\\','g')
7198 let tgt = substitute(tgt, '/','\\','g')
7199 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007200 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7201 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7202 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7203 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7204" call Decho("args <".args.">",'~'.expand("<slnum>"))
7205" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007206 if isdirectory(s:NetrwFile(args))
7207" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007208 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007209" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007210 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007211 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7212 " contents to a target. One must append the source directory name to the target to get xcopy to
7213 " do the right thing.
7214 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007215" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007216 endif
7217 else
7218 let copycmd= g:netrw_localcopycmd
7219 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007220 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007221 let copycmd = substitute(copycmd,'\s.*$','','')
7222 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007223 let copycmd = netrw#WinPath(copycmd).copycmdargs
7224 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007225 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007226 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007227" call Decho("args <".args.">",'~'.expand("<slnum>"))
7228" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7229" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7230" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007231 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007232 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007233 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007234 call netrw#ErrorMsg(s:ERROR,"copy failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",101)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007235 else
7236 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7237 endif
7238" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007239 return 0
7240 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007241
7242 elseif a:islocal && !s:netrwmftgt_islocal
7243 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007244" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007245 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007246
7247 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007248 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007249" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007250 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007251
7252 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007253 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007254" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007255 let curdir = getcwd()
7256 let tmpdir = s:GetTempfile("")
7257 if tmpdir !~ '/'
7258 let tmpdir= curdir."/".tmpdir
7259 endif
7260 if exists("*mkdir")
7261 call mkdir(tmpdir)
7262 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007263 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007264 if v:shell_error != 0
7265 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 +01007266" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007267 return
7268 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007269 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007270 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007271 if s:NetrwLcd(tmpdir)
7272" call Dret("s:NetrwMarkFileCopy : lcd failure")
7273 return
7274 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007275 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007276 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007277 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007278 if getcwd() == tmpdir
7279 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007280 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007281 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007282 if s:NetrwLcd(curdir)
7283" call Dret("s:NetrwMarkFileCopy : lcd failure")
7284 return
7285 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007286 if delete(tmpdir,"d")
7287 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007288 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007289 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007290 if s:NetrwLcd(curdir)
7291" call Dret("s:NetrwMarkFileCopy : lcd failure")
7292 return
7293 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007294 endif
7295 endif
7296 endif
7297
7298 " -------
7299 " cleanup
7300 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007301" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007302 " remove markings from local buffer
7303 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007304" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7305" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7306" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7307" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7308" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7309" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7310 if exists("s:recursive")
7311" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7312 else
7313" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007314 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007315 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007316 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007317 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007318 else
7319 " refresh local and targets for fast browsing
7320 if !exists("s:recursive")
7321 " remove markings from local buffer
7322" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7323 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7324 endif
7325
7326 " refresh buffers
7327 if s:netrwmftgt_islocal
7328" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7329 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7330 endif
7331 if a:islocal && s:netrwmftgt != curdir
7332" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7333 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7334 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007335 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007336
Bram Moolenaar446cb832008-06-24 21:56:24 +00007337" call Dret("s:NetrwMarkFileCopy 1")
7338 return 1
7339endfun
7340
7341" ---------------------------------------------------------------------
7342" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7343" invoke vim's diff mode on the marked files.
7344" Either two or three files can be so handled.
7345" Uses the global marked file list.
7346fun! s:NetrwMarkFileDiff(islocal)
7347" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7348 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007349
Bram Moolenaarff034192013-04-24 18:51:19 +02007350 " sanity check
7351 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007352 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007353" call Dret("s:NetrwMarkFileDiff")
7354 return
7355 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007356 let curdir= s:NetrwGetCurdir(a:islocal)
7357" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007358
Bram Moolenaara6878372014-03-22 21:02:50 +01007359 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007360 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 for fname in s:netrwmarkfilelist
7362 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007363 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007364" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007365 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007366 diffthis
7367 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007368 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007369" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007370 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007371 diffthis
7372 else
7373 break
7374 endif
7375 endfor
7376 call s:NetrwUnmarkList(curbufnr,curdir)
7377 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007378
Bram Moolenaar446cb832008-06-24 21:56:24 +00007379" call Dret("s:NetrwMarkFileDiff")
7380endfun
7381
7382" ---------------------------------------------------------------------
7383" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7384" Uses global markfilelist
7385fun! s:NetrwMarkFileEdit(islocal)
7386" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7387
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007388 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007389 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007390
7391 " sanity check
7392 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007393 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007394" call Dret("s:NetrwMarkFileEdit")
7395 return
7396 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007397" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007398
Bram Moolenaar446cb832008-06-24 21:56:24 +00007399 if exists("s:netrwmarkfilelist_{curbufnr}")
7400 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007401 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007402 " unmark markedfile list
7403" call s:NetrwUnmarkList(curbufnr,curdir)
7404 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007405" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007406 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007407 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007408 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007409
Bram Moolenaar446cb832008-06-24 21:56:24 +00007410" call Dret("s:NetrwMarkFileEdit")
7411endfun
7412
7413" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007414" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007415fun! s:NetrwMarkFileQFEL(islocal,qfel)
7416" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7417 call s:NetrwUnmarkAll()
7418 let curbufnr= bufnr("%")
7419
7420 if !empty(a:qfel)
7421 for entry in a:qfel
7422 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007424 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007426 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7427 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7428 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7429 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007430" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007431 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7432 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007433" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007434 endif
7435 endfor
7436 echo "(use me to edit marked files)"
7437 else
7438 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7439 endif
7440
7441" call Dret("s:NetrwMarkFileQFEL")
7442endfun
7443
7444" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007445" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7446" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7447" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7448fun! s:NetrwMarkFileExe(islocal,enbloc)
7449" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007450 let svpos = winsaveview()
7451" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007452 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007453 let curbufnr = bufnr("%")
7454
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007455 if a:enbloc == 0
7456 " individually apply command to files, one at a time
7457 " sanity check
7458 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7459 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7460" call Dret("s:NetrwMarkFileExe")
7461 return
7462 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007463" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007464
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007465 if exists("s:netrwmarkfilelist_{curbufnr}")
7466 " get the command
7467 call inputsave()
7468 let cmd= input("Enter command: ","","file")
7469 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007470" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007471 if cmd == ""
7472" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7473 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007474 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007475
7476 " apply command to marked files, individually. Substitute: filename -> %
7477 " If no %, then append a space and the filename to the command
7478 for fname in s:netrwmarkfilelist_{curbufnr}
7479 if a:islocal
7480 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007481 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007482 endif
7483 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007484 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007485 endif
7486 if cmd =~ '%'
7487 let xcmd= substitute(cmd,'%',fname,'g')
7488 else
7489 let xcmd= cmd.' '.fname
7490 endif
7491 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007492" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007493 let ret= system(xcmd)
7494 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007495" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007496 let ret= s:RemoteSystem(xcmd)
7497 endif
7498 if v:shell_error < 0
7499 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7500 break
7501 else
yasudac75dad02024-08-22 21:06:32 +02007502 if ret !=# ''
7503 echo "\n"
7504 " skip trailing new line
7505 echo ret[0:-2]
7506 else
7507 echo ret
7508 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007509 endif
7510 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007511
7512 " unmark marked file list
7513 call s:NetrwUnmarkList(curbufnr,curdir)
7514
7515 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007516 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007517" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7518 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007519 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007520 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007521 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007522
7523 else " apply command to global list of files, en bloc
7524
7525 call inputsave()
7526 let cmd= input("Enter command: ","","file")
7527 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007528" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007529 if cmd == ""
7530" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7531 return
7532 endif
7533 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007534 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007535 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007536 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007537 endif
7538 if a:islocal
7539 call system(cmd)
7540 if v:shell_error < 0
7541 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7542 endif
7543 else
7544 let ret= s:RemoteSystem(cmd)
7545 endif
7546 call s:NetrwUnmarkAll()
7547
7548 " refresh the listing
7549 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007550" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7551 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007552
7553 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007554
Bram Moolenaar446cb832008-06-24 21:56:24 +00007555" call Dret("s:NetrwMarkFileExe")
7556endfun
7557
7558" ---------------------------------------------------------------------
7559" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7560" as the marked file(s) (toggles suffix presence)
7561" Uses the local marked file list.
7562fun! s:NetrwMarkHideSfx(islocal)
7563" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007564 let svpos = winsaveview()
7565" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007566 let curbufnr = bufnr("%")
7567
7568 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7569 if exists("s:netrwmarkfilelist_{curbufnr}")
7570
7571 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007572" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007573 " construct suffix pattern
7574 if fname =~ '\.'
7575 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7576 else
7577 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7578 endif
7579 " determine if its in the hiding list or not
7580 let inhidelist= 0
7581 if g:netrw_list_hide != ""
7582 let itemnum = 0
7583 let hidelist= split(g:netrw_list_hide,',')
7584 for hidepat in hidelist
7585 if sfxpat == hidepat
7586 let inhidelist= 1
7587 break
7588 endif
7589 let itemnum= itemnum + 1
7590 endfor
7591 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007592" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007593 if inhidelist
7594 " remove sfxpat from list
7595 call remove(hidelist,itemnum)
7596 let g:netrw_list_hide= join(hidelist,",")
7597 elseif g:netrw_list_hide != ""
7598 " append sfxpat to non-empty list
7599 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7600 else
7601 " set hiding list to sfxpat
7602 let g:netrw_list_hide= sfxpat
7603 endif
7604 endfor
7605
7606 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007607 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007608" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7609 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007610 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007611 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007612 endif
7613
7614" call Dret("s:NetrwMarkHideSfx")
7615endfun
7616
7617" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007618" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007619" Uses the local marked-file list.
7620fun! s:NetrwMarkFileVimCmd(islocal)
7621" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007622 let svpos = winsaveview()
7623" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007624 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007625 let curbufnr = bufnr("%")
7626
Bram Moolenaarff034192013-04-24 18:51:19 +02007627 " sanity check
7628 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007629 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007630" call Dret("s:NetrwMarkFileVimCmd")
7631 return
7632 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007633" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007634
Bram Moolenaar15146672011-10-20 22:22:38 +02007635 if exists("s:netrwmarkfilelist_{curbufnr}")
7636 " get the command
7637 call inputsave()
7638 let cmd= input("Enter vim command: ","","file")
7639 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007640" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007641 if cmd == ""
7642" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7643 return
7644 endif
7645
7646 " apply command to marked files. Substitute: filename -> %
7647 " If no %, then append a space and the filename to the command
7648 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007649" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007650 if a:islocal
7651 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007652 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007653" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007654 exe cmd
7655 exe "sil! keepalt wq!"
7656 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007657" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007658 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007659 endif
7660 endfor
7661
7662 " unmark marked file list
7663 call s:NetrwUnmarkList(curbufnr,curdir)
7664
7665 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007666 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007667" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7668 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007669 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007670 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007671 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007672
Bram Moolenaar15146672011-10-20 22:22:38 +02007673" call Dret("s:NetrwMarkFileVimCmd")
7674endfun
7675
7676" ---------------------------------------------------------------------
7677" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7678" as the marked file(s) (toggles suffix presence)
7679" Uses the local marked file list.
7680fun! s:NetrwMarkHideSfx(islocal)
7681" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007682 let svpos = winsaveview()
7683" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007684 let curbufnr = bufnr("%")
7685
7686 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7687 if exists("s:netrwmarkfilelist_{curbufnr}")
7688
7689 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007690" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007691 " construct suffix pattern
7692 if fname =~ '\.'
7693 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7694 else
7695 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7696 endif
7697 " determine if its in the hiding list or not
7698 let inhidelist= 0
7699 if g:netrw_list_hide != ""
7700 let itemnum = 0
7701 let hidelist= split(g:netrw_list_hide,',')
7702 for hidepat in hidelist
7703 if sfxpat == hidepat
7704 let inhidelist= 1
7705 break
7706 endif
7707 let itemnum= itemnum + 1
7708 endfor
7709 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007710" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007711 if inhidelist
7712 " remove sfxpat from list
7713 call remove(hidelist,itemnum)
7714 let g:netrw_list_hide= join(hidelist,",")
7715 elseif g:netrw_list_hide != ""
7716 " append sfxpat to non-empty list
7717 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7718 else
7719 " set hiding list to sfxpat
7720 let g:netrw_list_hide= sfxpat
7721 endif
7722 endfor
7723
7724 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007725 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007726" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7727 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007728 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007729 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007730 endif
7731
7732" call Dret("s:NetrwMarkHideSfx")
7733endfun
7734
7735" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007736" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7737" Uses the global markfilelist
7738fun! s:NetrwMarkFileGrep(islocal)
7739" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007740 let svpos = winsaveview()
7741" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007742 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007743 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744
7745 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007746" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007747 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007748" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007749 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007750 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007751" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007752 let netrwmarkfilelist= "*"
7753 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007754
Bram Moolenaarff034192013-04-24 18:51:19 +02007755 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007756" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007757 call inputsave()
7758 let pat= input("Enter pattern: ","")
7759 call inputrestore()
7760 let patbang = ""
7761 if pat =~ '^!'
7762 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007763 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007764 endif
7765 if pat =~ '^\i'
7766 let pat = escape(pat,'/')
7767 let pat = '/'.pat.'/'
7768 else
7769 let nonisi = pat[0]
7770 endif
7771
7772 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007773" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007774 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007775 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007776 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007777 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007778" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7779 return
7780 endtry
7781 echo "(use :cn, :cp to navigate, :Rex to return)"
7782
7783 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007784" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7785 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007786
7787 if exists("nonisi")
7788 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007789" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007790 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007791 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007792 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007793 endif
7794
7795" call Dret("s:NetrwMarkFileGrep")
7796endfun
7797
7798" ---------------------------------------------------------------------
7799" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7800" uses the global marked file list
7801" s:netrwmfloc= 0: target directory is remote
7802" = 1: target directory is local
7803fun! s:NetrwMarkFileMove(islocal)
7804" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007805 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007806 let curbufnr = bufnr("%")
7807
7808 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007809 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007810 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007811" call Dret("s:NetrwMarkFileMove")
7812 return
7813 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007814" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007815
Bram Moolenaar446cb832008-06-24 21:56:24 +00007816 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007817 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007818" call Dret("s:NetrwMarkFileCopy 0")
7819 return 0
7820 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007821" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007822
7823 if a:islocal && s:netrwmftgt_islocal
7824 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007825" call Decho("move from local to local",'~'.expand("<slnum>"))
7826" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007827 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007828 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7829" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7830 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007832 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007834 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007835 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007836" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007837 if g:netrw_localmovecmd =~ '\s'
7838 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7839 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7840 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007841" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007842 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007843 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007844" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007845 endif
7846 else
7847 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007848" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007849 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007850 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007851 if g:netrw_keepdir
7852 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7853 let fname= b:netrw_curdir."/".fname
7854 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007855 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007856 let fname= substitute(fname,'/','\\','g')
7857 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007858" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007859 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007860 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007862 call netrw#ErrorMsg(s:ERROR,"move failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",100)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007863 else
7864 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7865 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007866 break
7867 endif
7868 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007869
7870 elseif a:islocal && !s:netrwmftgt_islocal
7871 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007872" call Decho("move from local to remote",'~'.expand("<slnum>"))
7873" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007874 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007875 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007876" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007877 for fname in mflist
7878 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7879 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7880 endfor
7881 unlet mflist
7882
7883 elseif !a:islocal && s:netrwmftgt_islocal
7884 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007885" call Decho("move from remote to local",'~'.expand("<slnum>"))
7886" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007887 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007888 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007889" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007890 for fname in mflist
7891 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7892 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7893 endfor
7894 unlet mflist
7895
7896 elseif !a:islocal && !s:netrwmftgt_islocal
7897 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007898" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7899" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007900 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007901 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007902" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007903 for fname in mflist
7904 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7905 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7906 endfor
7907 unlet mflist
7908 endif
7909
7910 " -------
7911 " cleanup
7912 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007913" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007914
7915 " remove markings from local buffer
7916 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7917
7918 " refresh buffers
7919 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007920" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007921 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007922 endif
7923 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007924" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007925 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007926 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007927 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007928" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007929 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007930 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007931
Bram Moolenaar446cb832008-06-24 21:56:24 +00007932" call Dret("s:NetrwMarkFileMove")
7933endfun
7934
7935" ---------------------------------------------------------------------
7936" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7937" using the hardcopy command. Local marked-file list only.
7938fun! s:NetrwMarkFilePrint(islocal)
7939" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7940 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007941
7942 " sanity check
7943 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007944 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007945" call Dret("s:NetrwMarkFilePrint")
7946 return
7947 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007948" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7949 let curdir= s:NetrwGetCurdir(a:islocal)
7950
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951 if exists("s:netrwmarkfilelist_{curbufnr}")
7952 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007953 call s:NetrwUnmarkList(curbufnr,curdir)
7954 for fname in netrwmarkfilelist
7955 if a:islocal
7956 if g:netrw_keepdir
7957 let fname= s:ComposePath(curdir,fname)
7958 endif
7959 else
7960 let fname= curdir.fname
7961 endif
7962 1split
7963 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007964" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007965 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007966" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007967 hardcopy
7968 q
7969 endfor
7970 2match none
7971 endif
7972" call Dret("s:NetrwMarkFilePrint")
7973endfun
7974
7975" ---------------------------------------------------------------------
7976" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7977" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007978" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007979fun! s:NetrwMarkFileRegexp(islocal)
7980" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7981
7982 " get the regular expression
7983 call inputsave()
7984 let regexp= input("Enter regexp: ","","file")
7985 call inputrestore()
7986
7987 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007988 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007989" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007990 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007991" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007992 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007993 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007994 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007995 else
7996 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007997 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007998 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007999" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008000
8001 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008002 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008003 if fname =~ '^'.fnameescape(curdir)
8004" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8005 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8006 else
8007" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8008 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8009 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008010 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008011
8012 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008013" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008014
8015 " convert displayed listing into a filelist
8016 let eikeep = &ei
8017 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008018 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008019 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008020" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008023 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008024 sil NetrwKeepj norm! "ap
8025 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008026 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008027 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008028 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008029 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008030 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008031 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008033 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008034 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008035 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008036 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8037 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008038 call histdel("/",-1)
8039 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040 endif
8041 " convert regexp into the more usual glob-style format
8042 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008043" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008044 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008045 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008046 let filelist= getline(1,line("$"))
8047 q!
8048 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008049 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008050 endfor
8051 unlet filelist
8052 let @a = areg
8053 let &ei = eikeep
8054 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008055 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008056
8057" call Dret("s:NetrwMarkFileRegexp")
8058endfun
8059
8060" ---------------------------------------------------------------------
8061" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8062" Uses the local marked file list.
8063fun! s:NetrwMarkFileSource(islocal)
8064" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8065 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008066
8067 " sanity check
8068 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008069 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008070" call Dret("s:NetrwMarkFileSource")
8071 return
8072 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008073" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8074 let curdir= s:NetrwGetCurdir(a:islocal)
8075
Bram Moolenaar446cb832008-06-24 21:56:24 +00008076 if exists("s:netrwmarkfilelist_{curbufnr}")
8077 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008078 call s:NetrwUnmarkList(curbufnr,curdir)
8079 for fname in netrwmarkfilelist
8080 if a:islocal
8081 if g:netrw_keepdir
8082 let fname= s:ComposePath(curdir,fname)
8083 endif
8084 else
8085 let fname= curdir.fname
8086 endif
8087 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008088" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008089 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008090 endfor
8091 2match none
8092 endif
8093" call Dret("s:NetrwMarkFileSource")
8094endfun
8095
8096" ---------------------------------------------------------------------
8097" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8098" Uses the global markfilelist
8099fun! s:NetrwMarkFileTag(islocal)
8100" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008101 let svpos = winsaveview()
8102" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008103 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008104 let curbufnr = bufnr("%")
8105
Bram Moolenaarff034192013-04-24 18:51:19 +02008106 " sanity check
8107 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008108 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008109" call Dret("s:NetrwMarkFileTag")
8110 return
8111 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008112" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008113
Bram Moolenaar446cb832008-06-24 21:56:24 +00008114 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008115" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8116 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008117 call s:NetrwUnmarkAll()
8118
8119 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008120
8121" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8122 call system(g:netrw_ctags." ".netrwmarkfilelist)
8123 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008124 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8125 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008126
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008128 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008129 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008130 let curdir= b:netrw_curdir
8131 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008132 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008133 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008134" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008135 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008136 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008137 wq!
8138 endif
8139 2match none
8140 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008141" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8142 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008143 endif
8144
8145" call Dret("s:NetrwMarkFileTag")
8146endfun
8147
8148" ---------------------------------------------------------------------
8149" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008150" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008151" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008152" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008153" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008155" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8156 let svpos = winsaveview()
8157" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008158 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008159 let hadtgt = exists("s:netrwmftgt")
8160 if !exists("w:netrw_bannercnt")
8161 let w:netrw_bannercnt= b:netrw_bannercnt
8162 endif
8163
8164 " set up target
8165 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008166" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008167 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8168 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008169" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008170 unlet s:netrwmftgt s:netrwmftgt_islocal
8171 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008172 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008173 endif
8174 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008175" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8176 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008177" call Dret("s:NetrwMarkFileTgt : removed target")
8178 return
8179 else
8180 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008181" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008182 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008183
8184 else
8185 " get word under cursor.
8186 " * If directory, use it for the target.
8187 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189 let curword= s:NetrwGetWord()
8190 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008191 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008192 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008193" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008194 elseif !a:islocal && tgtdir =~ '/$'
8195 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008196" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008197 else
8198 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008199" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008200 endif
8201 endif
8202 if a:islocal
8203 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8204 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008205" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008206 endif
8207 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008208 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008209 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8210 endif
8211 let s:netrwmftgt_islocal= a:islocal
8212
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213 " need to do refresh so that the banner will be updated
8214 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008215 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008216" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008217 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008218 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008219" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008220 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8222 else
8223 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8224 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008225" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8226 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008227 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008228 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008229 endif
8230
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008231" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8232" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008233" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8234endfun
8235
8236" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008237" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8238fun! s:NetrwGetCurdir(islocal)
8239" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8240
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008241 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008242 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8243" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8244 elseif !exists("b:netrw_curdir")
8245 let b:netrw_curdir= getcwd()
8246" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8247 endif
8248
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008249" 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 +01008250 if b:netrw_curdir !~ '\<\a\{3,}://'
8251 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008252" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008253 if g:netrw_keepdir == 0
8254 call s:NetrwLcd(curdir)
8255 endif
8256 endif
8257
8258" call Dret("s:NetrwGetCurdir <".curdir.">")
8259 return b:netrw_curdir
8260endfun
8261
8262" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008263" s:NetrwOpenFile: query user for a filename and open it {{{2
8264fun! s:NetrwOpenFile(islocal)
8265" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008266 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008267 call inputsave()
8268 let fname= input("Enter filename: ")
8269 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008270" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8271
8272 " determine if Lexplore is in use
8273 if exists("t:netrw_lexbufnr")
8274 " check if t:netrw_lexbufnr refers to a netrw window
8275" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8276 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8277 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8278" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8279 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8280 exe "NetrwKeepj e ".fnameescape(fname)
8281 let @@= ykeep
8282" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8283 endif
8284 endif
8285
8286 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008287 if fname !~ '[/\\]'
8288 if exists("b:netrw_curdir")
8289 if exists("g:netrw_quiet")
8290 let netrw_quiet_keep = g:netrw_quiet
8291 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008292 let g:netrw_quiet = 1
8293 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008294 let s:rexposn_{bufnr("%")}= winsaveview()
8295" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008296 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008297 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008298 else
8299 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8300 endif
8301 if exists("netrw_quiet_keep")
8302 let g:netrw_quiet= netrw_quiet_keep
8303 else
8304 unlet g:netrw_quiet
8305 endif
8306 endif
8307 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008308 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008309 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008310 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008311" call Dret("s:NetrwOpenFile")
8312endfun
8313
8314" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008315" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8316" For the mapping to this function be made via
8317" netrwPlugin, you'll need to have had
8318" g:netrw_usetab set to non-zero.
8319fun! netrw#Shrink()
8320" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8321 let curwin = winnr()
8322 let wiwkeep = &wiw
8323 set wiw=1
8324
8325 if &ft == "netrw"
8326 if winwidth(0) > g:netrw_wiw
8327 let t:netrw_winwidth= winwidth(0)
8328 exe "vert resize ".g:netrw_wiw
8329 wincmd l
8330 if winnr() == curwin
8331 wincmd h
8332 endif
8333" call Decho("vert resize 0",'~'.expand("<slnum>"))
8334 else
8335 exe "vert resize ".t:netrw_winwidth
8336" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8337 endif
8338
8339 elseif exists("t:netrw_lexbufnr")
8340 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8341 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8342 let t:netrw_winwidth= winwidth(0)
8343 exe "vert resize ".g:netrw_wiw
8344 wincmd l
8345 if winnr() == curwin
8346 wincmd h
8347 endif
8348" call Decho("vert resize 0",'~'.expand("<slnum>"))
8349 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8350 exe "vert resize ".t:netrw_winwidth
8351" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8352 else
8353 call netrw#Lexplore(0,0)
8354 endif
8355
8356 else
8357 call netrw#Lexplore(0,0)
8358 endif
8359 let wiw= wiwkeep
8360
8361" call Dret("netrw#Shrink")
8362endfun
8363
8364" ---------------------------------------------------------------------
8365" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8366fun! s:NetSortSequence(islocal)
8367" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8368
8369 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008370 let svpos= winsaveview()
8371" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008372 call inputsave()
8373 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8374 call inputrestore()
8375
8376 " refresh the listing
8377 let g:netrw_sort_sequence= newsortseq
8378 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008379" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8380 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008381 let @@= ykeep
8382
8383" call Dret("NetSortSequence")
8384endfun
8385
8386" ---------------------------------------------------------------------
8387" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8388" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008389" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008390fun! s:NetrwUnmarkList(curbufnr,curdir)
8391" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8392
8393 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008394 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008395 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8396 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8397 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8398 call remove(s:netrwmarkfilelist,idx) " remove from global list
8399 endfor
8400 if s:netrwmarkfilelist == []
8401 unlet s:netrwmarkfilelist
8402 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008403
Bram Moolenaar446cb832008-06-24 21:56:24 +00008404 " getting rid of the local marked-file lists is easy
8405 unlet s:netrwmarkfilelist_{a:curbufnr}
8406 endif
8407 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8408 unlet s:netrwmarkfilemtch_{a:curbufnr}
8409 endif
8410 2match none
8411" call Dret("s:NetrwUnmarkList")
8412endfun
8413
8414" ---------------------------------------------------------------------
8415" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8416fun! s:NetrwUnmarkAll()
8417" call Dfunc("s:NetrwUnmarkAll()")
8418 if exists("s:netrwmarkfilelist")
8419 unlet s:netrwmarkfilelist
8420 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008421 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008422 2match none
8423" call Dret("s:NetrwUnmarkAll")
8424endfun
8425
8426" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008427" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008428fun! s:NetrwUnmarkAll2()
8429" call Dfunc("s:NetrwUnmarkAll2()")
8430 redir => netrwmarkfilelist_let
8431 let
8432 redir END
8433 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008434 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008435 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8436 for flist in netrwmarkfilelist_list
8437 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8438 unlet s:netrwmarkfilelist_{curbufnr}
8439 unlet s:netrwmarkfilemtch_{curbufnr}
8440 endfor
8441" call Dret("s:NetrwUnmarkAll2")
8442endfun
8443
8444" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008445" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8446"
8447" Marked files are in two types of lists:
8448" s:netrwmarkfilelist -- holds complete paths to all marked files
8449" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8450"
8451" Marked files suitable for use with 2match are in:
8452" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008453fun! s:NetrwUnMarkFile(islocal)
8454" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008455 let svpos = winsaveview()
8456" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008457 let curbufnr = bufnr("%")
8458
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008459 " unmark marked file list
8460 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8461 if exists("s:netrwmarkfilelist")
8462" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008463 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008464 endif
8465
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008466 let ibuf= 1
8467 while ibuf < bufnr("$")
8468 if exists("s:netrwmarkfilelist_".ibuf)
8469 unlet s:netrwmarkfilelist_{ibuf}
8470 unlet s:netrwmarkfilemtch_{ibuf}
8471 endif
8472 let ibuf = ibuf + 1
8473 endwhile
8474 2match none
8475
Bram Moolenaar446cb832008-06-24 21:56:24 +00008476" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008477"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8478call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008479" call Dret("s:NetrwUnMarkFile")
8480endfun
8481
8482" ---------------------------------------------------------------------
8483" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8484fun! s:NetrwMenu(domenu)
8485
8486 if !exists("g:NetrwMenuPriority")
8487 let g:NetrwMenuPriority= 80
8488 endif
8489
Bram Moolenaaradc21822011-04-01 18:03:16 +02008490 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008491" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8492
8493 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008494" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008495 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008496 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8497 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8498 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8499 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8500 if g:netrw_dirhistmax > 0
8501 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8502 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8503 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8504 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8505 else
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8507 endif
8508 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8513 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8515 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8522 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 +01008523 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 +02008524 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8530 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8531 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8532 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8553 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>'
8554 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>'
8555 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>'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8557 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>'
8558 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>'
8559 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 +01008560 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 +02008561 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8562 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008563 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008564 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8565 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566
8567 elseif !a:domenu
8568 let s:netrwcnt = 0
8569 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008570 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008571 exe curwin."wincmd w"
8572
8573 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008574" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008575 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008576" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008577 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008578 endif
8579 endif
8580" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008581 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008582 endif
8583
8584endfun
8585
8586" ---------------------------------------------------------------------
8587" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8588" Used by the O maps (as <SID>NetrwObtain())
8589fun! s:NetrwObtain(islocal)
8590" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8591
Bram Moolenaar97d62492012-11-15 21:28:22 +01008592 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008593 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008594 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008595 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008596 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8597 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008598 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008599 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008600 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601
8602" call Dret("NetrwObtain")
8603endfun
8604
8605" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8607" If there's only one window, then the window will first be split.
8608" Returns:
8609" choice = 0 : didn't have to choose
8610" choice = 1 : saved modified file in window first
8611" choice = 2 : didn't save modified file, opened window
8612" choice = 3 : cancel open
8613fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008614" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008615
Bram Moolenaar97d62492012-11-15 21:28:22 +01008616 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008617 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008618 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008619" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008620
8621 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008622 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008624" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8625" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8626 let curword = s:NetrwGetWord()
8627 let choice = 0
8628 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8629" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008630 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008631" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008632 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008633" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008634" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008635" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008636
Bram Moolenaar8d043172014-01-23 14:24:41 +01008637 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008638 if lastwinnr == 1
8639 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008640" call Decho("only one window, so open a new one (g:netrw_alto=".g:netrw_alto.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008641 " g:netrw_preview=0: preview window shown in a horizontally split window
8642 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008643 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008644 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008645 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008646" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008647 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008648 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008649 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008650 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008651" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008652 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008653 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008654 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008655" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008656
8657 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008658" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008659 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008660" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008661 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008662" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008663 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008664" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008665 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008666" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008667" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008668" call Decho("COMBAK#12: mod=".&mod)
8669
8670 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8671 " whoops -- user trying to open file in the Lexplore window.
8672 " Use Lexplore's opening-file window instead.
8673" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8674" exe g:netrw_chgwin."wincmd w"
8675 wincmd p
8676 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8677 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008678
8679 " prevwinnr: the window number of the "prev" window
8680 " prevbufnr: the buffer number of the buffer in the "prev" window
8681 " bnrcnt : the qty of windows open on the "prev" buffer
8682 let prevwinnr = winnr()
8683 let prevbufnr = bufnr("%")
8684 let prevbufname = bufname("%")
8685 let prevmod = &mod
8686 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008687" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008688 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008689" call Decho("after wincmd p: win#".winnr()." win($)#".winnr("$")." origwin#".origwin." &mod=".&mod." bufname(%)<".bufname("%")."> prevbufnr=".prevbufnr,'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008690" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008691
8692 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008693 " and it doesn't appear in any other extant window, then ask the
8694 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008695 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008696" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008697 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008698" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008699 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008700" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008701
8702 if bnrcnt == 1 && &hidden == 0
8703 " only one copy of the modified buffer in a window, and
8704 " hidden not set, so overwriting will lose the modified file. Ask first...
8705 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008706" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008707 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008708" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008709
8710 if choice == 1
8711 " Yes -- write file & then browse
8712 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008713 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008714 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008715 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008716 exe origwin."wincmd w"
8717 let &ei = eikeep
8718 let @@ = ykeep
8719" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008720 return choice
8721 endif
8722
8723 elseif choice == 2
8724 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008725" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008726 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008727
8728 else
8729 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008730" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008731 exe origwin."wincmd w"
8732 let &ei= eikeep
8733 let @@ = ykeep
8734" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008735 return choice
8736 endif
8737 endif
8738 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008739 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008740 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008741" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008742
8743 " restore b:netrw_curdir (window split/enew may have lost it)
8744 let b:netrw_curdir= curdir
8745 if a:islocal < 2
8746 if a:islocal
8747 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8748 else
8749 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8750 endif
8751 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008752 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008753" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008754 return choice
8755endfun
8756
8757" ---------------------------------------------------------------------
8758" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8759" Always assumed to be local -> remote
8760" call s:NetrwUpload(filename, target)
8761" call s:NetrwUpload(filename, target, fromdirectory)
8762fun! s:NetrwUpload(fname,tgt,...)
8763" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8764
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008765 if a:tgt =~ '^\a\{3,}://'
8766 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008767 else
8768 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8769 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008770" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008771
8772 if a:0 > 0
8773 let fromdir= a:1
8774 else
8775 let fromdir= getcwd()
8776 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008777" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008778
8779 if type(a:fname) == 1
8780 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008781" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008782 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008783" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8784 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8785" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786 if a:tgt =~ '/$'
8787 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008788" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008789 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008790 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008791" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008792 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008793" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008794 endif
8795 q!
8796
8797 elseif type(a:fname) == 3
8798 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800 let curdir= getcwd()
8801 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008802 if s:NetrwLcd(fromdir)
8803" call Dret("s:NetrwUpload : lcd failure")
8804 return
8805 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008806 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 if exists("g:netrw_port") && g:netrw_port != ""
8809 let useport= " ".g:netrw_scpport." ".g:netrw_port
8810 else
8811 let useport= ""
8812 endif
8813 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8814 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_scp_cmd.s:ShellEscape(useport,1)." ".args." ".s:ShellEscape(machine.":".tgt,1))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008816 if s:NetrwLcd(curdir)
8817" call Dret("s:NetrwUpload : lcd failure")
8818 return
8819 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008820
8821 elseif a:tgt =~ '^ftp:'
8822 call s:NetrwMethod(a:tgt)
8823
8824 if b:netrw_method == 2
8825 " handle uploading a list of files via ftp+.netrc
8826 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008827 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008828" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008829
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008830 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008831" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008832
8833 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008834 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008835" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008836 endif
8837
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008838 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008839" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008840
Bram Moolenaaradc21822011-04-01 18:03:16 +02008841 if tgtdir == ""
8842 let tgtdir= '/'
8843 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008844 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008845" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008846
8847 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008848 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8849" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008850 endfor
8851
8852 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008853 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 +00008854 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008855" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8856 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008857 endif
8858 " 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 +01008859 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008860 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008861 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8862 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8863 else
8864 bw!|q
8865 endif
8866
8867 elseif b:netrw_method == 3
8868 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8869 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008870 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008871 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008872 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008873
8874 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008875 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008876" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008877 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008878 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008879" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008880 endif
8881
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008882 if exists("g:netrw_uid") && g:netrw_uid != ""
8883 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008884 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008885" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008886 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008887 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008889" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008890 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008891 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008892" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008893 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008894 endif
8895
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008896 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008897" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008898
8899 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008900 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008901" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endif
8903
8904 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008905 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008906" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 endif
8908
8909 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008910 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008911" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008912 endfor
8913
8914 " perform ftp:
8915 " -i : turns off interactive prompting from ftp
8916 " -n unix : DON'T use <.netrc>, even though it exists
8917 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008918 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008919 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008920 " 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 +01008921 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008922 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8924 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008925 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008926 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8927 let &debug = debugkeep
8928 let mod = 1
8929 else
8930 bw!|q
8931 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008932 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008933" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008934 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008935 endif
8936 else
8937 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8938 endif
8939 endif
8940
8941" call Dret("s:NetrwUpload")
8942endfun
8943
8944" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008945" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008946fun! s:NetrwPreview(path) range
8947" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008948" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8949" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008950 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008951 NetrwKeepj call s:NetrwOptionsSave("s:")
8952 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8953 NetrwKeepj call s:NetrwOptionsSafe(1)
8954 else
8955 NetrwKeepj call s:NetrwOptionsSafe(0)
8956 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008957 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008958" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008959 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008960" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8961 if g:netrw_preview
8962 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008963 let pvhkeep = &pvh
8964 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8965 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008966" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8967 else
8968 " horizontal split
8969 let pvhkeep = &pvh
8970 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8971 let &pvh = winheight(0) - winsz
8972" call Decho("!g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008973 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008974 " g:netrw_preview g:netrw_alto
8975 " 1 : vert 1: top -- preview window is vertically split off and on the left
8976 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8977 " 0 : 1: top -- preview window is horizontally split off and on the top
8978 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8979 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008980 " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
Bram Moolenaar85850f32019-07-19 22:05:51 +02008981 " the BufEnter event set up in netrwPlugin.vim
8982" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8983 let eikeep = &ei
8984 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008985 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008986 let &ei= eikeep
8987" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008988 if exists("pvhkeep")
8989 let &pvh= pvhkeep
8990 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008991 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008992 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008993 endif
8994 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008995 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 +00008996 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008997 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008998 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008999" call Dret("NetrwPreview")
9000endfun
9001
9002" ---------------------------------------------------------------------
9003" s:NetrwRefresh: {{{2
9004fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009005" call Dfunc("s:NetrwRefresh(islocal<".a:islocal.">,dirname=".a:dirname.") g:netrw_hide=".g:netrw_hide." g:netrw_sort_direction=".g:netrw_sort_direction)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009006 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009007 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009008" call Decho("setl ma noro",'~'.expand("<slnum>"))
9009" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009010 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009011 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9012 if !exists("w:netrw_treetop")
9013 if exists("b:netrw_curdir")
9014 let w:netrw_treetop= b:netrw_curdir
9015 else
9016 let w:netrw_treetop= getcwd()
9017 endif
9018 endif
9019 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9020 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009021
9022 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009023 let screenposn = winsaveview()
9024" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009025
9026" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9027" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9028 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009029 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009030 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009031 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009032 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009033 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009034
9035 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009036" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9037 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009038
9039 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009040 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9041 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9042" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9043 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9044 else
9045" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9046 2match none
9047 endif
9048 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009049
Bram Moolenaar97d62492012-11-15 21:28:22 +01009050" restore
9051 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009052" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009053endfun
9054
9055" ---------------------------------------------------------------------
9056" s:NetrwRefreshDir: refreshes a directory by name {{{2
9057" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009058" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009059fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009060" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061 if g:netrw_fastbrowse == 0
9062 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009063" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009064 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009065" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009066
9067 if tgtwin > 0
9068 " tgtwin is being displayed, so refresh it
9069 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009070" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009071 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009072 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009073 exe curwin."wincmd w"
9074
9075 elseif bufnr(a:dirname) > 0
9076 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009077" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9078 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 endif
9080
9081 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009082" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009083 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009084 endif
9085" call Dret("s:NetrwRefreshDir")
9086endfun
9087
9088" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009089" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9090" window number to do its editing in.
9091" Supports [count]C where the count, if present, is used to specify
9092" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009093fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009094" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009095 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009096" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009097 if a:1 == "" " :NetrwC win#
9098 let g:netrw_chgwin= winnr()
9099 else " :NetrwC
9100 let g:netrw_chgwin= a:1
9101 endif
9102 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009103 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009104 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009105 let g:netrw_chgwin= winnr()
9106 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009107 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009108" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009109endfun
9110
9111" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9113" What this function does is to compute a priority for the patterns
9114" in the g:netrw_sort_sequence. It applies a substitute to any
9115" "files" that satisfy each pattern, putting the priority / in
9116" front. An "*" pattern handles the default priority.
9117fun! s:NetrwSetSort()
9118" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009119 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009120 if w:netrw_liststyle == s:LONGLIST
9121 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9122 else
9123 let seqlist = g:netrw_sort_sequence
9124 endif
9125 " sanity check -- insure that * appears somewhere
9126 if seqlist == ""
9127 let seqlist= '*'
9128 elseif seqlist !~ '\*'
9129 let seqlist= seqlist.',*'
9130 endif
9131 let priority = 1
9132 while seqlist != ""
9133 if seqlist =~ ','
9134 let seq = substitute(seqlist,',.*$','','e')
9135 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9136 else
9137 let seq = seqlist
9138 let seqlist = ""
9139 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009140 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009141 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009142 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009143 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009144 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009145 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009146 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009147" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009148
9149 " sanity check
9150 if w:netrw_bannercnt > line("$")
9151 " apparently no files were left after a Hiding pattern was used
9152" call Dret("SetSort : no files left after hiding")
9153 return
9154 endif
9155 if seq == '*'
9156 let starpriority= spriority
9157 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009158 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009159 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009160 " sometimes multiple sorting patterns will match the same file or directory.
9161 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009162 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9163 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164 endif
9165 let priority = priority + 1
9166 endwhile
9167 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009168 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9169 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170 endif
9171
9172 " Following line associated with priority -- items that satisfy a priority
9173 " pattern get prefixed by ###/ which permits easy sorting by priority.
9174 " Sometimes files can satisfy multiple priority patterns -- only the latest
9175 " priority pattern needs to be retained. So, at this point, these excess
9176 " priority prefixes need to be removed, but not directories that happen to
9177 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009178 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9179 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009180 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009181
9182" call Dret("SetSort")
9183endfun
9184
Bram Moolenaarff034192013-04-24 18:51:19 +02009185" ---------------------------------------------------------------------
9186" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9187" Implements [count]Tb (bookhist<b>)
9188" [count]Th (bookhist<h>)
9189" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009190fun! s:NetrwSetTgt(islocal,bookhist,choice)
9191" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009192
9193 if a:bookhist == 'b'
9194 " supports choosing a bookmark as a target using a qb-generated list
9195 let choice= a:choice - 1
9196 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009197 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009198 else
9199 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9200 endif
9201
9202 elseif a:bookhist == 'h'
9203 " supports choosing a history stack entry as a target using a qb-generated list
9204 let choice= (a:choice % g:netrw_dirhistmax) + 1
9205 if exists("g:netrw_dirhist_".choice)
9206 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009207 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009208 else
9209 echomsg "Sorry, history#".a:choice." not available!"
9210 endif
9211 endif
9212
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009213 " refresh the display
9214 if !exists("b:netrw_curdir")
9215 let b:netrw_curdir= getcwd()
9216 endif
9217 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9218
Bram Moolenaarff034192013-04-24 18:51:19 +02009219" call Dret("s:NetrwSetTgt")
9220endfun
9221
Bram Moolenaar446cb832008-06-24 21:56:24 +00009222" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009223" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009224fun! s:NetrwSortStyle(islocal)
9225" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009226 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009227 let svpos= winsaveview()
9228" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009229
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009230 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 +01009231 NetrwKeepj norm! 0
9232 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009233" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9234 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009235
9236" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9237endfun
9238
9239" ---------------------------------------------------------------------
9240" s:NetrwSplit: mode {{{2
9241" =0 : net and o
9242" =1 : net and t
9243" =2 : net and v
9244" =3 : local and o
9245" =4 : local and t
9246" =5 : local and v
9247fun! s:NetrwSplit(mode)
9248" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9249
Bram Moolenaar97d62492012-11-15 21:28:22 +01009250 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009251 call s:SaveWinVars()
9252
9253 if a:mode == 0
9254 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009255 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009256 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009257" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009258 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009259 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009260 NetrwKeepj call s:RestoreWinVars()
9261 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009262 unlet s:didsplit
9263
9264 elseif a:mode == 1
9265 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009266 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009267" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009268 tabnew
9269 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009270 NetrwKeepj call s:RestoreWinVars()
9271 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009272 unlet s:didsplit
9273
9274 elseif a:mode == 2
9275 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009276 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009277 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009278" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009279 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009280 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009281 NetrwKeepj call s:RestoreWinVars()
9282 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283 unlet s:didsplit
9284
9285 elseif a:mode == 3
9286 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009287 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009288 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009289" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009290 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009291 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009292 NetrwKeepj call s:RestoreWinVars()
9293 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009294 unlet s:didsplit
9295
9296 elseif a:mode == 4
9297 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009298 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009299 let eikeep = &ei
9300 let netrw_winnr = winnr()
9301 let netrw_line = line(".")
9302 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009303 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009304 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009305 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009306 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9307 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009308 let &ei = eikeep
9309 let netrw_curdir = s:NetrwTreeDir(0)
9310" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009311 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009312 let b:netrw_curdir = netrw_curdir
9313 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009314 NetrwKeepj call s:RestoreWinVars()
9315 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009316 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009317 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009318 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9319 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009320 let &ei= eikeep
9321 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009322 unlet s:didsplit
9323
9324 elseif a:mode == 5
9325 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009326 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009327 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009328" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009329 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 NetrwKeepj call s:RestoreWinVars()
9332 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333 unlet s:didsplit
9334
9335 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009336 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009337 endif
9338
Bram Moolenaar97d62492012-11-15 21:28:22 +01009339 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009340" call Dret("s:NetrwSplit")
9341endfun
9342
9343" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009344" s:NetrwTgtMenu: {{{2
9345fun! s:NetrwTgtMenu()
9346 if !exists("s:netrw_menucnt")
9347 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009348 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009349" call Dfunc("s:NetrwTgtMenu()")
9350
9351 " the following test assures that gvim is running, has menus available, and has menus enabled.
9352 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9353 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009354" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009355 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9356 endif
9357 if !exists("s:netrw_initbookhist")
9358 call s:NetrwBookHistRead()
9359 endif
9360
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361 " try to cull duplicate entries
9362 let tgtdict={}
9363
Bram Moolenaarff034192013-04-24 18:51:19 +02009364 " target bookmarked places
9365 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009366" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009367 let cnt= 1
9368 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009369 if has_key(tgtdict,bmd)
9370 let cnt= cnt + 1
9371 continue
9372 endif
9373 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009374 let ebmd= escape(bmd,g:netrw_menu_escape)
9375 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009376" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009377 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 +02009378 let cnt= cnt + 1
9379 endfor
9380 endif
9381
9382 " target directory browsing history
9383 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009384" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009385 let histcnt = 1
9386 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009387 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009388 if exists("g:netrw_dirhist_{histcnt}")
9389 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009390 if has_key(tgtdict,histentry)
9391 let histcnt = histcnt + 1
9392 continue
9393 endif
9394 let tgtdict[histentry] = histcnt
9395 let ehistentry = escape(histentry,g:netrw_menu_escape)
9396" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009397 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 +02009398 endif
9399 let histcnt = histcnt + 1
9400 endwhile
9401 endif
9402 endif
9403" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009404endfun
9405
9406" ---------------------------------------------------------------------
9407" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9408" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009409fun! s:NetrwTreeDir(islocal)
9410" call Dfunc("s:NetrwTreeDir(islocal=".a:islocal.") getline(".line(".").")"."<".getline('.')."> b:netrw_curdir<".b:netrw_curdir."> tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009411" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009412" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9413" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9414" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009415" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009416
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009417 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009418 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009419" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
Bram Moolenaar8d043172014-01-23 14:24:41 +01009420 let treedir= s:treedir
9421 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009422 unlet s:prevwinopen
9423" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009424 return treedir
9425 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009426 if exists("s:prevwinopen")
9427 unlet s:prevwinopen
9428 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009429" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009430
Bram Moolenaar8d043172014-01-23 14:24:41 +01009431 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9432 let b:netrw_curdir= getcwd()
9433 endif
9434 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009435" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009436" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009437
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009438 let s:treecurpos= winsaveview()
9439" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009440" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009441
9442 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009443" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9444" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009445" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009446
9447 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009448 let curline= substitute(getline('.'),"\t -->.*$",'','')
9449 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009450" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009451 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009452" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9453 elseif curline =~ '@$'
9454" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009455 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009456" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009457 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009459 let treedir= ""
9460 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009461" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009462
9463 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009464" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9465" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009466" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009467 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009468" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009469 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009470" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9471 sil! NetrwKeepj %d _
9472" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009473 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009474" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009475" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009476 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009477" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009478
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009479" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009480" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009481" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009482
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009483 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9484" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9485" let newdir = w:netrw_treetop.'/'.potentialdir
9486" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9487" let treedir = s:NetrwTreePath(newdir)
9488" let w:netrw_treetop = newdir
9489" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9490" else
9491" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009492 if a:islocal && curline =~ '@$'
9493 if isdirectory(s:NetrwFile(potentialdir))
9494 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9495 let w:netrw_treetop = treedir
9496 endif
9497 else
9498 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9499 let treedir = s:NetrwTreePath(w:netrw_treetop)
9500 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009501 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009502" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009503
9504 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009505 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009506" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009507" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009508
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009509" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009510 return treedir
9511endfun
9512
9513" ---------------------------------------------------------------------
9514" s:NetrwTreeDisplay: recursive tree display {{{2
9515fun! s:NetrwTreeDisplay(dir,depth)
9516" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9517
9518 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009519 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009520
9521 " install ../ and shortdir
9522 if a:depth == ""
9523 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009524" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009525 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009526 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009527 if a:dir == w:netrw_treetop
9528 let shortdir= a:dir
9529 else
9530 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9531 endif
9532 call setline(line("$")+1,a:depth.shortdir)
9533 else
9534 let shortdir= substitute(a:dir,'^.*/','','e')
9535 call setline(line("$")+1,a:depth.shortdir.'/')
9536 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009537" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009538 " append a / to dir if its missing one
9539 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009540
9541 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009542 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009543" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009544
Bram Moolenaar85850f32019-07-19 22:05:51 +02009545 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9546 if g:netrw_hide == 1
9547 " hide given patterns
9548 let listhide= split(g:netrw_list_hide,',')
9549" call Decho("listhide=".string(listhide))
9550 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009551 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009552 endfor
9553
9554 elseif g:netrw_hide == 2
9555 " show given patterns (only)
9556 let listhide= split(g:netrw_list_hide,',')
9557" call Decho("listhide=".string(listhide))
9558 let entries=[]
9559 for entry in w:netrw_treedict[dir]
9560 for pat in listhide
9561 if entry =~ pat
9562 call add(entries,entry)
9563 break
9564 endif
9565 endfor
9566 endfor
9567 let w:netrw_treedict[dir]= entries
9568 endif
9569 if depth != ""
9570 " always remove "." and ".." entries when there's depth
9571 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9572 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9573 endif
9574
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009575" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009576 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009577 if dir =~ '/$'
9578 let direntry= substitute(dir.entry,'[@/]$','','e')
9579 else
9580 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9581 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009582" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009583 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009584" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009585 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009586 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009587" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9588 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9589 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9590" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009591 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009592 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009593" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009594 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009595 endif
9596 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009597" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009598
Bram Moolenaar446cb832008-06-24 21:56:24 +00009599" call Dret("NetrwTreeDisplay")
9600endfun
9601
9602" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009603" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9604fun! s:NetrwRefreshTreeDict(dir)
9605" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009606 if !exists("w:netrw_treedict")
9607" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9608 return
9609 endif
9610
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009611 for entry in w:netrw_treedict[a:dir]
9612 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9613" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9614
9615 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
9616" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9617 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009618 let liststar = s:NetrwGlob(direntry,'*',1)
9619 let listdotstar = s:NetrwGlob(direntry,'.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009620 let w:netrw_treedict[direntry] = liststar + listdotstar
9621" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9622
9623 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
9624" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9625 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009626 let liststar = s:NetrwGlob(direntry.'/','*',1)
9627 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009628 let w:netrw_treedict[direntry]= liststar + listdotstar
9629" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9630
9631 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9632" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9633 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009634 let liststar = s:NetrwGlob(direntry.'/','*',1)
9635 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009636" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9637
9638 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009639" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009640 endif
9641 endfor
9642" call Dret("s:NetrwRefreshTreeDict")
9643endfun
9644
9645" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009646" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009647" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009648fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009649 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009650" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009651" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9652" 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>"))
9653" 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 +00009654
9655 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009657" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009659 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009660" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009661 elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009662" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009663 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009664 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009665" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009667 if exists("w:netrw_treetop")
9668 let s:netrw_treetop= w:netrw_treetop
9669 else
9670 let w:netrw_treetop= getcwd()
9671 let s:netrw_treetop= w:netrw_treetop
9672 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009673
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009675 " insure that we have a treedict, albeit empty
9676" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009677 let w:netrw_treedict= {}
9678 endif
9679
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009680 " update the dictionary for the current directory
9681" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009682" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009683 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009684 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009685" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009686 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009687
9688 " if past banner, record word
9689 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9690 let fname= expand("<cword>")
9691 else
9692 let fname= ""
9693 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009694" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9695" 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 +00009696
9697 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009698" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009699 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009700" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009701
9702 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9703 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009704" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009705 1d
9706 endwhile
9707
Bram Moolenaar13600302014-05-22 18:26:40 +02009708 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009709
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009710" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009711 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009712 endif
9713endfun
9714
9715" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009716" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009717" Normally, treetop is w:netrw_treetop, but a
9718" user of the function ( netrw#SetTreetop() )
9719" wipes that out prior to calling this function
9720fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009721" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9722 if line(".") < w:netrw_bannercnt + 2
9723 let treedir= a:treetop
9724 if treedir !~ '/$'
9725 let treedir= treedir.'/'
9726 endif
9727" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9728 return treedir
9729 endif
9730
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009731 let svpos = winsaveview()
9732" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009733 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009734" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009735 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009736" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9737 let curline= getline('.')
9738" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9739 if curline =~ '/$'
9740" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9741 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9742" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9743 elseif curline =~ '@\s\+-->'
9744" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9745 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9746 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9747" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009748 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009749" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009750 let treedir= ""
9751 endif
9752 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009753" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9754" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009755 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9756 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9757 let treedir= dirname.treedir
9758 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009759" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009760 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009761" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009762 if a:treetop =~ '/$'
9763 let treedir= a:treetop.treedir
9764 else
9765 let treedir= a:treetop.'/'.treedir
9766 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009767" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009768 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009769" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009770" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9771 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009772" call Dret("s:NetrwTreePath <".treedir.">")
9773 return treedir
9774endfun
9775
9776" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009777" s:NetrwWideListing: {{{2
9778fun! s:NetrwWideListing()
9779
9780 if w:netrw_liststyle == s:WIDELIST
9781" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9782 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009783 " cpf: characters per filename
9784 " fpl: filenames per line
9785 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009786 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009787 let dict={}
9788 " save the unnamed register and register 0-9 and a
9789 let dict.a=[getreg('a'), getregtype('a')]
9790 for i in range(0, 9)
9791 let dict[i] = [getreg(i), getregtype(i)]
9792 endfor
9793 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009794" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009795 let b:netrw_cpf= 0
9796 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009797 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009798 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9799 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009800 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009801 " restore stored registers
9802 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009803" call Dret("NetrwWideListing")
9804 return
9805 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009806 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009807 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009808" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009809
9810 " determine qty files per line (fpl)
9811 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9812 if w:netrw_fpl <= 0
9813 let w:netrw_fpl= 1
9814 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009815" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816
9817 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009818 " fpc: files per column of wide listing
9819 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009820 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009821 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9822 let newcolstart = w:netrw_bannercnt + fpc
9823 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009825 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009826" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009827 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009828 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009829 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009830 while line("$") >= newcolstart
9831 if newcolend > line("$") | let newcolend= line("$") | endif
9832 let newcolqty= newcolend - newcolstart
9833 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009834 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009835 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009836 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009837 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009838 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009839 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009840 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009841 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009842 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009843 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009844" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009845 if @* != keepregstar | sil! let @* = keepregstar | endif
9846 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009847 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009848 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9849 NetrwKeepj call histdel("/",-1)
9850 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9851 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009852" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009853 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009854 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009855" 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 +00009856" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009857 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009858 else
9859 if hasmapto("w","n")
9860 sil! nunmap <buffer> w
9861 endif
9862 if hasmapto("b","n")
9863 sil! nunmap <buffer> b
9864 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009865 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009866endfun
9867
9868" ---------------------------------------------------------------------
9869" s:PerformListing: {{{2
9870fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009871" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9872" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009873" 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>"))
9874 sil! NetrwKeepj %d _
9875" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009876
Bram Moolenaar15146672011-10-20 22:22:38 +02009877 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009878" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009879 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009880
Bram Moolenaar85850f32019-07-19 22:05:51 +02009881 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009882 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009883" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009884
9885" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009886" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009887" endif " Decho
9888
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009889" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009890 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9891 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009892" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9893 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009894 endif
9895
9896 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009897 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898
9899 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009900 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009901" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009902 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903 if exists("g:netrw_pchk")
9904 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9905 " failure detections.
9906 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009907 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009908 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9909 endif
9910 if exists("g:netrw_pchk")
9911 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9912 else
9913 let curdir= b:netrw_curdir
9914 endif
9915 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9916 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9917 else
9918 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009919 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009920 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009921 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009922 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009923" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009924 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009925 let w:netrw_bannercnt= 1
9926 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009927" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9928" 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 +00009929
Bram Moolenaar85850f32019-07-19 22:05:51 +02009930 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009931 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009932 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009933 let sortby= sortby." reversed"
9934 endif
9935
9936 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009937 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009938" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009939 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009940" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009941 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009942 NetrwKeepj put ='\" Sorted by '.sortby
9943 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009944 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9945 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009946" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009947 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009948 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009949 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9950 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009951 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009952" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009953" 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 +00009954 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955
Bram Moolenaar85850f32019-07-19 22:05:51 +02009956 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009957 if g:netrw_banner
9958 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009959" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009960 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009961 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009962 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009963 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009964 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009965 endif
9966 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009967 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009968" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009969 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009971 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009972
9973 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009974 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009975" call Decho("--handle hiding/showing in banner (g:netrw_hide=".g:netrw_hide." g:netrw_list_hide<".g:netrw_list_hide.">)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009976 if g:netrw_list_hide != "" && g:netrw_hide
9977 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009978 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009979 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009980 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009981 endif
9982 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009983 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009984 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009985
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009986" 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 +01009987 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009988" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009989 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009990" 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 +01009991 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009992 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009993" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009994" 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 +00009995 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009996
9997 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009998 if g:netrw_banner
9999 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010000 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010001" 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 +010010002" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010003" 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 +010010004 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010005
Bram Moolenaar446cb832008-06-24 21:56:24 +000010006 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010007" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010008 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010009 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010010 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010011 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010012 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010013" 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 +010010014" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10015 return
10016 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010017 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018
10019 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010020 if !exists("w:netrw_bannercnt")
10021 let w:netrw_bannercnt= 0
10022 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010023" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10024" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10025" 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 +010010026
Bram Moolenaar5c736222010-01-06 20:54:52 +010010027 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010028" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010029" 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 +000010030 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010031 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010032 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010033 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010035
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010036 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010037 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010038" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010039 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010040
Bram Moolenaar5c736222010-01-06 20:54:52 +010010041 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010042" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010043 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010044 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010045 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010046 else
10047 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010048 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010049 endif
10050 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010051
Bram Moolenaar446cb832008-06-24 21:56:24 +000010052 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010053" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010054 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10055 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010056
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010057 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010058 " exten: sort by extension
10059 " The histdel(...,-1) calls remove the last search from the search history
10060" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010061 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10062 NetrwKeepj call histdel("/",-1)
10063 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10064 NetrwKeepj call histdel("/",-1)
10065 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10066 NetrwKeepj call histdel("/",-1)
10067 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10068" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010069 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010070 " normal direction sorting
10071 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10072 else
10073 " reverse direction sorting
10074 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10075 endif
10076 endif
10077 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10078 NetrwKeepj call histdel("/",-1)
10079
Bram Moolenaar446cb832008-06-24 21:56:24 +000010080 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010081 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010082" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010083 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010084" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010085 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010086 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010087" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010088 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010089 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010090" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010091 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10092 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010093 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010094 endif
10095
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010096 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010097" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010098 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010099 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010100 call histdel("/",-1)
10101 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010102 endif
10103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010104" 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 +000010105
10106 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010107" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10108" 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 +010010109 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010110" 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 +010010111 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112" 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 +000010113
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010114 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010115 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010116" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010117 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010118 endif
10119
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010121 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010122" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10123 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010124 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010125" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10126 else
10127" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10128" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10129" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10130" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131 endif
10132
10133 " record previous current directory
10134 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010135" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010136
10137 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010138" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10139" 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 +010010140 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo. " (internal#5)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010142 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" 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 +000010144
10145 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010146" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010147 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148" 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 +010010149 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010150" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010151 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10152 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010153" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010154" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010155
Bram Moolenaar8d043172014-01-23 14:24:41 +010010156 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010157" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10158" 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 +010010159" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10160 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010161 unlet s:treecurpos
10162 endif
10163
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010164" 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>"))
10165" 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 +000010166" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10167endfun
10168
10169" ---------------------------------------------------------------------
10170" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010171fun! s:SetupNetrwStatusLine(statline)
10172" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10173
10174 if !exists("s:netrw_setup_statline")
10175 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010176" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010177
10178 if !exists("s:netrw_users_stl")
10179 let s:netrw_users_stl= &stl
10180 endif
10181 if !exists("s:netrw_users_ls")
10182 let s:netrw_users_ls= &laststatus
10183 endif
10184
10185 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010186 let dict={}
10187 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010188 redir @a
10189 try
10190 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010191 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010192 if &bg == "dark"
10193 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10194 else
10195 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10196 endif
10197 endtry
10198 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010199 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010200 endif
10201
10202 " set up status line (may use User9 highlighting)
10203 " insure that windows have a statusline
10204 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010205 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010206 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010207" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010208 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010209
10210" call Dret("SetupNetrwStatusLine : stl=".&stl)
10211endfun
10212
Bram Moolenaar85850f32019-07-19 22:05:51 +020010213" =========================================
10214" Remote Directory Browsing Support: {{{1
10215" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010216
10217" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010218" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10219" This function assumes that a long listing will be received. Size, time,
10220" and reverse sorts will be requested of the server but not otherwise
10221" enforced here.
10222fun! s:NetrwRemoteFtpCmd(path,listcmd)
10223" 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 +010010224" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010225 " sanity check: {{{3
10226 if !exists("w:netrw_method")
10227 if exists("b:netrw_method")
10228 let w:netrw_method= b:netrw_method
10229 else
10230 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10231" call Dret("NetrwRemoteFtpCmd")
10232 return
10233 endif
10234 endif
10235
10236 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10237 let ffkeep= &ff
10238 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010239" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010240
10241 " clear off any older non-banner lines " {{{3
10242 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010243" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10244 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010245
10246 ".........................................
10247 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10248 " ftp + <.netrc>: Method #2
10249 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010250 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010251 endif
10252 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010253 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010255 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010256 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010257" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010258 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010259" 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>"))
10260 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 +010010261 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010262" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10263 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 +010010264 endif
10265
10266 ".........................................
10267 elseif w:netrw_method == 3 " {{{3
10268 " ftp + machine,id,passwd,filename: Method #3
10269 setl ff=unix
10270 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010271 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010272 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010273 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010274 endif
10275
10276 " handle userid and password
10277 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010278" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010279 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10280 call NetUserPass("ftp:".host)
10281 endif
10282 if exists("g:netrw_uid") && g:netrw_uid != ""
10283 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010284 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010285 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010286 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010287 endif
10288 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010289 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 endif
10291 endif
10292
10293 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010294 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 endif
10296 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010297 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010298" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010299 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010300 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010301
10302 " perform ftp:
10303 " -i : turns off interactive prompting from ftp
10304 " -n unix : DON'T use <.netrc>, even though it exists
10305 " -n win32: quit being obnoxious about password
10306 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010307" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010308 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010309" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010310" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10311" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010312 endif
10313
10314 ".........................................
10315 elseif w:netrw_method == 9 " {{{3
10316 " sftp username@machine: Method #9
10317 " s:netrw_sftp_cmd
10318 setl ff=unix
10319
10320 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010321 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010322" call Dret("NetrwRemoteFtpCmd")
10323 return
10324
10325 ".........................................
10326 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010327 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010328 endif
10329
10330 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010331 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010332 sil! NetrwKeepj %s/\r$//e
10333 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010334 endif
10335 if a:listcmd == "dir"
10336 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010337 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10338 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10339 NetrwKeepj call histdel("/",-1)
10340 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010341 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 +010010342 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10343 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010344 endif
10345 endif
10346
10347 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10348 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010349 exe 'NetrwKeepj '.w:netrw_bannercnt
10350 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010351 endif
10352 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010353 exe 'NetrwKeepj '.w:netrw_bannercnt
10354 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 endif
10356
10357 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010358 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010359" call Dret("NetrwRemoteFtpCmd")
10360endfun
10361
10362" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010363" s:NetrwRemoteListing: {{{2
10364fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010365" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010366
Bram Moolenaara6878372014-03-22 21:02:50 +010010367 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10368 let w:netrw_bannercnt= s:bannercnt
10369 endif
10370 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010371 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010372 endif
10373
Bram Moolenaar446cb832008-06-24 21:56:24 +000010374 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010375
Bram Moolenaar446cb832008-06-24 21:56:24 +000010376 " sanity check:
10377 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010378" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010379 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010380" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010381 if !exists("g:netrw_quiet")
10382 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10383 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010384 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010385" call Dret("s:NetrwRemoteListing -1")
10386 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010387 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010388
Bram Moolenaar8d043172014-01-23 14:24:41 +010010389 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010390" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010391 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010392 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010393 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 +000010394 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010395 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 +000010396 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010397 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010398
Bram Moolenaar85850f32019-07-19 22:05:51 +020010399 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010400" call Dret("s:NetrwRemoteListing -1")
10401 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010402 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010403" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010404
Bram Moolenaar446cb832008-06-24 21:56:24 +000010405 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010406" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010407 let w:netrw_method= b:netrw_method
10408 endif
10409
Bram Moolenaar13600302014-05-22 18:26:40 +020010410 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010411 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010412" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010413 let s:method = "ftp"
10414 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010415 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010416 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010417 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010418 let listcmd= g:netrw_ftp_sizelist_cmd
10419 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010420" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010421 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010422" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010423
Bram Moolenaara6878372014-03-22 21:02:50 +010010424 " report on missing file or directory messages
10425 if search('[Nn]o such file or directory\|Failed to change directory')
10426 let mesg= getline(".")
10427 if exists("w:netrw_bannercnt")
10428 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010429 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010430 setl noma
10431 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010432 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010433 call netrw#ErrorMsg(s:WARNING,mesg,96)
10434" call Dret("s:NetrwRemoteListing : -1")
10435 return -1
10436 endif
10437
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010438 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 +000010439 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010440" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010441 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010442
10443 " cleanup
10444 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010445 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10446 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010447 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010448 sil! NetrwKeepj %s/\r$//e
10449 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010450
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010451 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010452 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010454 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010455" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010456 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010457" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010458 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010459 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010460 exe "sil! NetrwKeepj ".line1
10461 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010462
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010463" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010465" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010466 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10467 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010468 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010469" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010470 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10471 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10472 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10473 NetrwKeepj call histdel("/",-1)
10474 NetrwKeepj call histdel("/",-1)
10475 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476 endif
10477 endif
10478
Bram Moolenaar13600302014-05-22 18:26:40 +020010479 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010480 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010481" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010482 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010483" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010484 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010485" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10486 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010487 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010488 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10489 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10490 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10491 NetrwKeepj call histdel("/",-1)
10492 NetrwKeepj call histdel("/",-1)
10493 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010494 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010495 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10496 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010497 endif
10498 else
10499 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010500" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010501 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010503" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10504 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10505" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010506 endif
10507 endif
10508
10509 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010510 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010511" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010512 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10513 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 endif
10515 endif
10516
10517 if w:netrw_liststyle == s:LONGLIST
10518 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010519" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010520
10521 if s:method == "ftp"
10522 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010523 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010524 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010525 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010526 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010527 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 sil! NetrwKeepj 1
10530 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010531 let line2= line(".")
10532 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010533 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010534 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010535 endif
10536 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010537 exe "sil! NetrwKeepj ".line1
10538 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010539 endif
10540
10541 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010542" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010543 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 +000010544 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010545" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010546 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010547 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010548 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10549 NetrwKeepj call histdel("/",-1)
10550 NetrwKeepj call histdel("/",-1)
10551 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010552 endif
10553 endif
10554
10555" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010556" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010558
10559" call Dret("s:NetrwRemoteListing 0")
10560 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010561endfun
10562
Bram Moolenaar446cb832008-06-24 21:56:24 +000010563" ---------------------------------------------------------------------
10564" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10565fun! s:NetrwRemoteRm(usrhost,path) range
10566" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010567" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010568 let svpos= winsaveview()
10569" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570
10571 let all= 0
10572 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10573 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010574" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010575 for fname in s:netrwmarkfilelist_{bufnr("%")}
10576 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010577 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010579 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580 let all= 1
10581 endif
10582 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010583 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010584
10585 else
10586 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010587" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588
10589 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010590 let keepsol = &l:sol
10591 setl nosol
10592 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593
10594 " remove multiple files and directories
10595 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010596 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010597 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010598 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010599 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010600 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601 let all= 1
10602 endif
10603 let ctr= ctr + 1
10604 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010605 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010606 endif
10607
10608 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010609" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010610 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010611" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10612 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010613
10614" call Dret("s:NetrwRemoteRm")
10615endfun
10616
10617" ---------------------------------------------------------------------
10618" s:NetrwRemoteRmFile: {{{2
10619fun! s:NetrwRemoteRmFile(path,rmfile,all)
10620" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10621
10622 let all= a:all
10623 let ok = ""
10624
10625 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10626 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010627" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010628 if !all
10629 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010630" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010631 call inputsave()
10632 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10633 call inputrestore()
10634 echohl NONE
10635 if ok == ""
10636 let ok="no"
10637 endif
10638 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010639 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010640 let all= 1
10641 endif
10642 endif
10643
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010644 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010645" 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 +000010646 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010647" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010649 if path =~ '^\a\{3,}://'
10650 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010651 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010652 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10654 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010656 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010657" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010658 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010659 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010660 let ok="q"
10661 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010662 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10664" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10665" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010667 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010669 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010671" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010672 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010673 if v:shell_error != 0
10674 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010675 call netrw#ErrorMsg(s:ERROR,"remove failed; perhaps due to vim's current directory<".getcwd()."> not matching netrw's (".b:netrw_curdir.") (see :help netrw-cd)",102)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010676 else
10677 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10678 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010679 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010680 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010681 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010682" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010683 endif
10684 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010685 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010686" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010687 endif
10688
10689 else
10690 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010691" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010692 if !all
10693 call inputsave()
10694 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10695 call inputrestore()
10696 if ok == ""
10697 let ok="no"
10698 endif
10699 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010700 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010701 let all= 1
10702 endif
10703 endif
10704
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010705 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010706 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010707 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010708 else
10709 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010710 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10711" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010712 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010713" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010714
10715 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010716" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10717 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10718" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010719 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010720" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010721
10722 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010723 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010724 endif
10725 endif
10726 endif
10727
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010728 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010729" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010730 endif
10731 endif
10732
10733" call Dret("s:NetrwRemoteRmFile ".ok)
10734 return ok
10735endfun
10736
10737" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010738" s:NetrwRemoteRename: rename a remote file or directory {{{2
10739fun! s:NetrwRemoteRename(usrhost,path) range
10740" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10741
10742 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010743 let svpos = winsaveview()
10744" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010745 let ctr = a:firstline
10746 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10747
10748 " rename files given by the markfilelist
10749 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10750 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010751" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010752 if exists("subfrom")
10753 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010754" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010755 else
10756 call inputsave()
10757 let newname= input("Moving ".oldname." to : ",oldname)
10758 call inputrestore()
10759 if newname =~ '^s/'
10760 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10761 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10762 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010763" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010764 endif
10765 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010766
Bram Moolenaar446cb832008-06-24 21:56:24 +000010767 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010768 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010769 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010770 let oldname= s:ShellEscape(a:path.oldname)
10771 let newname= s:ShellEscape(a:path.newname)
10772" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010773 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010774 endif
10775
10776 endfor
10777 call s:NetrwUnMarkFile(1)
10778
10779 else
10780
10781 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010782 let keepsol= &l:sol
10783 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010784 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010785 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010786
10787 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010788" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010789
10790 call inputsave()
10791 let newname= input("Moving ".oldname." to : ",oldname)
10792 call inputrestore()
10793
10794 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10795 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10796 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010797 let oldname= s:ShellEscape(a:path.oldname)
10798 let newname= s:ShellEscape(a:path.newname)
10799" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010800 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010801 endif
10802
10803 let ctr= ctr + 1
10804 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010805 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010806 endif
10807
10808 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010809 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010810" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10811 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010812
10813" call Dret("NetrwRemoteRename")
10814endfun
10815
Bram Moolenaar85850f32019-07-19 22:05:51 +020010816" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010817" Local Directory Browsing Support: {{{1
10818" ==========================================
10819
10820" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010821" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010822" Should accept: file://localhost/etc/fstab
10823" file:///etc/fstab
10824" file:///c:/WINDOWS/clock.avi
10825" file:///c|/WINDOWS/clock.avi
10826" file://localhost/c:/WINDOWS/clock.avi
10827" file://localhost/c|/WINDOWS/clock.avi
10828" file://c:/foo.txt
10829" file:///c:/foo.txt
10830" and %XX (where X is [0-9a-fA-F] is converted into a character with the given hexadecimal value
Bram Moolenaar85850f32019-07-19 22:05:51 +020010831fun! netrw#FileUrlEdit(fname)
10832" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010833 let fname = a:fname
10834 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010835" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010836 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010837" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010838 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010839 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010840 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010841" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010842 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010843" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 endif
10845 endif
10846 let fname2396 = netrw#RFC2396(fname)
10847 let fname2396e= fnameescape(fname2396)
10848 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010849 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010850" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010851 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010852" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010853 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10854 endif
10855 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010856
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010857" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10858" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010859 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010860 exe 'NetrwKeepj keepalt edit '.plainfname
10861 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10862
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010863" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010864" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010865 exe "sil doau BufReadPost ".fname2396e
10866endfun
10867
10868" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010869" netrw#LocalBrowseCheck: {{{2
10870fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010871 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010872 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10873 "
10874 " unfortunate interaction -- split window debugging can't be used here, must use
10875 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10876 " another call to LocalBrowseCheck() when attempts to write
10877 " to the DBG buffer are made.
10878 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010879 " The &ft == "netrw" test was installed because the BufEnter event
10880 " would hit when re-entering netrw windows, creating unexpected
10881 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010882" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010883" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010884" 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 Moolenaar71badf92023-04-22 22:40:14 +010010885 " getting E930: Cannot use :redir inside execute
10886"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010887" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10888" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010889
Bram Moolenaar97d62492012-11-15 21:28:22 +010010890 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010891 if isdirectory(s:NetrwFile(a:dirname))
10892" 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 +010010893
Bram Moolenaar97d62492012-11-15 21:28:22 +010010894 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010895" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10896" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010897 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010898
Bram Moolenaar446cb832008-06-24 21:56:24 +000010899 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010900" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010901 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010902
Bram Moolenaar5c736222010-01-06 20:54:52 +010010903 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010904" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010905 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010906 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010907 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010908" 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 +010010909" call Dret("netrw#LocalBrowseCheck")
10910 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010911 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010912
Bram Moolenaar85850f32019-07-19 22:05:51 +020010913 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010914 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10915 " AND IF the listing style is not a tree listing
10916 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010917" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010918 let ibuf = 1
10919 let buflast = bufnr("$")
10920 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010921 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10922 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010923 endif
10924 let ibuf= ibuf + 1
10925 endwhile
10926 endif
10927 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010928" 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>"))
10929" 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 +000010930 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010931" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010932endfun
10933
10934" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010935" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010936" performed any shell command. The idea is to cause all local-browsing
10937" buffers to be refreshed after a user has executed some shell command,
10938" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010939fun! s:LocalBrowseRefresh()
10940" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010941" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10942" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010943
Bram Moolenaar446cb832008-06-24 21:56:24 +000010944 " determine which buffers currently reside in a tab
10945 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010946" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010947 return
10948 endif
10949 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010950" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010951 return
10952 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010953 if !empty(getcmdwintype())
10954 " cannot move away from cmdline window, see :h E11
10955 return
10956 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010957 if exists("s:netrw_events") && s:netrw_events == 1
10958 " s:LocalFastBrowser gets called (indirectly) from a
10959 let s:netrw_events= 2
10960" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10961 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010962 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010963 let itab = 1
10964 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010965 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010966 while itab <= tabpagenr("$")
10967 let buftablist = buftablist + tabpagebuflist()
10968 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010969 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010970 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010971" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10972" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010973 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10974 " | refresh any netrw window
10975 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010976 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010977 let ibl = 0
10978 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010980 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10981 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010982 " (ibuf not shown in a current window AND
10983 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010984" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10985 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010986 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010987" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010988 continue
10989 elseif index(tabpagebuflist(),ibuf) != -1
10990 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010991" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010992 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010993 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010994 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10995 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10996 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10997 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010998" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010999 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11000 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11001 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011002 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011003 endif
11004 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011005" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011006 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011007" call Decho("restore window: win_gotoid(".curwinid.")")
11008 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011009 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011010
Bram Moolenaara6878372014-03-22 21:02:50 +010011011" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011012endfun
11013
11014" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011015" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11016"
11017" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011018" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011019" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11020" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011021" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011022"
11023" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11024" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011025" (re-using a buffer may not be as accurate)
11026"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011027" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011028" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11029" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11030" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11031" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011032fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011033" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11034" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11035" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11036" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011037
11038 " initialize browselist, a list of buffer numbers that the local browser has used
11039 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011040" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011041 let s:netrw_browselist= []
11042 endif
11043
11044 " append current buffer to fastbrowse list
11045 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011046" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011047 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011048" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011049 endif
11050
11051 " enable autocmd events to handle refreshing/removing local browser buffers
11052 " If local browse buffer is currently showing: refresh it
11053 " If local browse buffer is currently hidden : wipe it
11054 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11055 " =1 : medium speed, re-use directory listing for remote only
11056 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011057 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11058 let s:netrw_events= 1
11059 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011060 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011061 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011062" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011063 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011064 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011065" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011066 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011067 endif
11068 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011069
11070 " user must have changed fastbrowse to its fast setting, so remove
11071 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011072 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011073" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011074 unlet s:netrw_events
11075 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011076 au!
11077 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011078 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011079 endif
11080
Bram Moolenaar85850f32019-07-19 22:05:51 +020011081" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011082endfun
11083
11084" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011085" s:LocalListing: does the job of "ls" for local directories {{{2
11086fun! s:LocalListing()
11087" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011088" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11089" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11090" 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 +010011091
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011092" 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
11093" 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
11094" 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 +010011095
11096 " get the list of files contained in the current directory
11097 let dirname = b:netrw_curdir
11098 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011099 let filelist = s:NetrwGlob(dirname,"*",0)
11100 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011101" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011102
Nir Lichtman1e34b952024-05-08 19:19:34 +020011103 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011104" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011105 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11106 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011107" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011108 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110 endif
11111
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011112" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011113" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011114" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011115
11116 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11117 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11118 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011119" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11120" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011121 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011122" 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 +010011123
11124 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011125" call Decho(" ",'~'.expand("<slnum>"))
11126" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011127
11128 if getftype(filename) == "link"
11129 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011131 let pfile= filename."@"
11132
11133 elseif getftype(filename) == "socket"
11134 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011135" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011136 let pfile= filename."="
11137
11138 elseif getftype(filename) == "fifo"
11139 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011141 let pfile= filename."|"
11142
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011144 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011145" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011146 let pfile= filename."/"
11147
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011148 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011149 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011150 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
11151 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011152" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011153 let pfile= filename."*"
11154 else
11155 " normal file
11156 let pfile= filename
11157 endif
11158 elseif executable(filename)
11159 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011160" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011161 let pfile= filename."*"
11162 else
11163 " normal file
11164 let pfile= filename
11165 endif
11166
11167 else
11168 " normal file
11169 let pfile= filename
11170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011171" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011172
11173 if pfile =~ '//$'
11174 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011175" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011176 endif
11177 let pfile= strpart(pfile,dirnamelen)
11178 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011179" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11180" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011181
11182 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011183 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11184 let sz = getfsize(filename)
11185 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11186 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011187
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011188 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011189 let sz= s:NetrwHumanReadable(sz)
11190 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011191 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011192 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011193" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011194 endif
11195
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011196 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011197 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011198 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011199" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011200" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011201 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011202 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011203" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011204 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011205 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011206
11207 elseif g:netrw_sort_by =~ "^s"
11208 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011209" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011210" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011211 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011212 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011213" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011214 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011215 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011216
11217 else
11218 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011219" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011220" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011221 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011222 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011223" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011224 endfor
11225
11226 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011227 sil! NetrwKeepj g/^$/d
11228 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011229 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011230" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011231 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11232
11233" call Dret("s:LocalListing")
11234endfun
11235
11236" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011237" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11238fun! s:NetrwLocalExecute(cmd)
11239" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11240 let ykeep= @@
11241 " sanity check
11242 if !executable(a:cmd)
11243 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11244 let @@= ykeep
11245" call Dret("s:NetrwLocalExecute")
11246 return
11247 endif
11248
11249 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011250" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011251 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011252" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011253
11254 " strip any ansi escape sequences off
11255 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11256
11257 " show user the result(s)
11258 echomsg result
11259 let @@= ykeep
11260
11261" call Dret("s:NetrwLocalExecute")
11262endfun
11263
11264" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011265" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011266fun! s:NetrwLocalRename(path) range
11267" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11268
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011269 if !exists("w:netrw_bannercnt")
11270 let w:netrw_bannercnt= b:netrw_bannercnt
11271 endif
11272
Bram Moolenaar97d62492012-11-15 21:28:22 +010011273 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011274 let ykeep = @@
11275 let ctr = a:firstline
11276 let svpos = winsaveview()
11277 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011278" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011279
11280 " rename files given by the markfilelist
11281 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11282 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011283" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011284 if exists("subfrom")
11285 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011286" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011287 else
11288 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011289 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011290 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011291 if newname =~ ''
11292 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11293 let newname = substitute(newname,'^.*','','')
11294 elseif newname =~ ''
11295 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11296 let newname = substitute(newname,'[^/]*','','')
11297 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011298 if newname =~ '^s/'
11299 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11300 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011301" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011302 let newname = substitute(oldname,subfrom,subto,'')
11303 endif
11304 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011305 if !all && filereadable(newname)
11306 call inputsave()
11307 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11308 call inputrestore()
11309 if response == "all"
11310 let all= 1
11311 elseif response != "y" && response != "yes"
11312 " refresh the directory
11313" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11314 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11315" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11316 NetrwKeepj call winrestview(svpos)
11317 let @@= ykeep
11318" call Dret("NetrwLocalRename")
11319 return
11320 endif
11321 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011322 call rename(oldname,newname)
11323 endfor
11324 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011325
Bram Moolenaar97d62492012-11-15 21:28:22 +010011326 else
11327
11328 " attempt to rename files/directories
11329 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011330 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011331
11332 " sanity checks
11333 if line(".") < w:netrw_bannercnt
11334 let ctr= ctr + 1
11335 continue
11336 endif
11337 let curword= s:NetrwGetWord()
11338 if curword == "./" || curword == "../"
11339 let ctr= ctr + 1
11340 continue
11341 endif
11342
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011343 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011344 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011345" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011346
11347 call inputsave()
11348 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11349 call inputrestore()
11350
11351 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011352" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011353
11354 let ctr= ctr + 1
11355 endwhile
11356 endif
11357
11358 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011359" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011360 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011361" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11362 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011363 let @@= ykeep
11364
11365" call Dret("NetrwLocalRename")
11366endfun
11367
11368" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011369" s:NetrwLocalRm: {{{2
11370fun! s:NetrwLocalRm(path) range
11371" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011372" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011373
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011374 if !exists("w:netrw_bannercnt")
11375 let w:netrw_bannercnt= b:netrw_bannercnt
11376 endif
11377
Bram Moolenaar446cb832008-06-24 21:56:24 +000011378 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011379 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011380 let ret = 0
11381 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011382 let svpos = winsaveview()
11383" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011384
11385 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11386 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011387" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011388 for fname in s:netrwmarkfilelist_{bufnr("%")}
11389 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011390 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011391 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011392 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011393 let all= 1
11394 endif
11395 endfor
11396 call s:NetrwUnMarkFile(1)
11397
11398 else
11399 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011400" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011401
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011402 let keepsol= &l:sol
11403 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011404 let ctr = a:firstline
11405 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011406 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011407
11408 " sanity checks
11409 if line(".") < w:netrw_bannercnt
11410 let ctr= ctr + 1
11411 continue
11412 endif
11413 let curword= s:NetrwGetWord()
11414 if curword == "./" || curword == "../"
11415 let ctr= ctr + 1
11416 continue
11417 endif
11418 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011419 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011420 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011421 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011422 let all= 1
11423 endif
11424 let ctr= ctr + 1
11425 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011426 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011427 endif
11428
11429 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011430" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011431 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011432 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011433" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11434 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011435 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011436 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011437
11438" call Dret("s:NetrwLocalRm")
11439endfun
11440
11441" ---------------------------------------------------------------------
11442" s:NetrwLocalRmFile: remove file fname given the path {{{2
11443" Give confirmation prompt unless all==1
11444fun! s:NetrwLocalRmFile(path,fname,all)
11445" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011446
Bram Moolenaar446cb832008-06-24 21:56:24 +000011447 let all= a:all
11448 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011449 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011450 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011451" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011452
11453 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11454 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011455" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011456 if !all
11457 echohl Statement
11458 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011459 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011460 call inputrestore()
11461 echohl NONE
11462 if ok == ""
11463 let ok="no"
11464 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011465" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011466 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011467" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011468 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011469 let all= 1
11470 endif
11471 endif
11472
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011473 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011474 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011475" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011476 endif
11477
11478 else
11479 " attempt to remove directory
11480 if !all
11481 echohl Statement
11482 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011483 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011484 call inputrestore()
11485 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11486 if ok == ""
11487 let ok="no"
11488 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011489 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011490 let all= 1
11491 endif
11492 endif
11493 let rmfile= substitute(rmfile,'[\/]$','','e')
11494
Christian Brabandt0f5effb2024-09-15 19:17:23 +020011495 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011496 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011497 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011498 endif
11499 endif
11500 endif
11501
11502" call Dret("s:NetrwLocalRmFile ".ok)
11503 return ok
11504endfun
11505
Bram Moolenaar85850f32019-07-19 22:05:51 +020011506" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011507" Support Functions: {{{1
11508
Bram Moolenaar488c6512005-08-11 20:09:58 +000011509" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011510" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11511" 0: marked file list of current buffer
11512" 1: marked file target
11513fun! netrw#Access(ilist)
11514 if a:ilist == 0
11515 if exists("s:netrwmarkfilelist_".bufnr('%'))
11516 return s:netrwmarkfilelist_{bufnr('%')}
11517 else
11518 return "no-list-buf#".bufnr('%')
11519 endif
11520 elseif a:ilist == 1
11521 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011522 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011523endfun
11524
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011525" ---------------------------------------------------------------------
11526" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11527fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011528 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011529endfun
11530
Bram Moolenaara6878372014-03-22 21:02:50 +010011531" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011532" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11533" I expect this function to be used in
11534" :PChkAssert netrw#Expose("netrwmarkfilelist")
11535" for example.
11536fun! netrw#Expose(varname)
11537" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011538 if exists("s:".a:varname)
11539 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011540" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011541 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011542" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011543 if type(retval) == 3
11544 let retval = copy(retval)
11545 let i = 0
11546 while i < len(retval)
11547 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11548 let i = i + 1
11549 endwhile
11550 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011551" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011552 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011553 else
11554" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011555 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011556 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011557" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011558 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011559 endif
11560
11561" call Dret("netrw#Expose ".string(retval))
11562 return retval
11563endfun
11564
11565" ---------------------------------------------------------------------
11566" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11567fun! netrw#Modify(varname,newvalue)
11568" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11569 exe "let s:".a:varname."= ".string(a:newvalue)
11570" call Dret("netrw#Modify")
11571endfun
11572
11573" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011574" netrw#RFC2396: converts %xx into characters {{{2
11575fun! netrw#RFC2396(fname)
11576" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011577 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011578" call Dret("netrw#RFC2396 ".fname)
11579 return fname
11580endfun
11581
11582" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011583" netrw#UserMaps: supports user-specified maps {{{2
11584" see :help function()
11585"
11586" g:Netrw_UserMaps is a List with members such as:
11587" [[keymap sequence, function reference],...]
11588"
11589" The referenced function may return a string,
11590" refresh : refresh the display
11591" -other- : this string will be executed
11592" or it may return a List of strings.
11593"
11594" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011595" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011596" Related functions:
11597" netrw#Expose(varname) -- see s:varname variables
11598" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11599" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11600fun! netrw#UserMaps(islocal)
11601" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11602" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11603
11604 " set up usermaplist
11605 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11606" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11607 for umap in g:Netrw_UserMaps
11608" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11609" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11610 " if umap[0] is a string and umap[1] is a string holding a function name
11611 if type(umap[0]) == 1 && type(umap[1]) == 1
11612" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11613 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11614 else
11615 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11616 endif
11617 endfor
11618 endif
11619" call Dret("netrw#UserMaps")
11620endfun
11621
11622" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011623" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11624fun! netrw#WinPath(path)
11625" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011626 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011627 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011628 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011629 " remove trailing slash (Win95)
11630 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11631 " remove escaped spaces
11632 let path = substitute(path, '\ ', ' ', 'g')
11633 " convert slashes to backslashes
11634 let path = substitute(path, '/', '\', 'g')
11635 else
11636 let path= a:path
11637 endif
11638" call Dret("netrw#WinPath <".path.">")
11639 return path
11640endfun
11641
11642" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011643" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11644fun! s:StripTrailingSlash(path)
11645 " remove trailing slash
11646 return substitute(a:path, '[/\\]$', '', 'g')
11647endfun
11648
Travis Sheltone34d0e32024-07-30 21:08:56 +020011649" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011650" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11651" cb : bl2mf=0 add marked files to buffer list
11652" cB : bl2mf=1 use bufferlist to mark files
11653" (mnemonic: cb = copy (marked files) to buffer list)
11654fun! s:NetrwBadd(islocal,bl2mf)
11655" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11656 if a:bl2mf
11657 " cB: add buffer list to marked files
11658 redir => bufl
11659 ls
11660 redir END
11661 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11662 for fname in bufl
11663 call s:NetrwMarkFile(a:islocal,fname)
11664 endfor
11665 else
11666 " cb: add marked files to buffer list
11667 for fname in s:netrwmarkfilelist_{bufnr("%")}
11668" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11669 exe "badd ".fnameescape(fname)
11670 endfor
11671 let curbufnr = bufnr("%")
11672 let curdir = s:NetrwGetCurdir(a:islocal)
11673 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11674 endif
11675" call Dret("s:NetrwBadd")
11676endfun
11677
11678" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011679" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11680fun! s:ComposePath(base,subdir)
11681" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11682
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011683 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011684" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011685 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011686 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011687 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011688 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011689 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011690 endif
11691
Bram Moolenaar85850f32019-07-19 22:05:51 +020011692 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011693 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011694" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011695 let ret= a:subdir
11696
Nir Lichtman1e34b952024-05-08 19:19:34 +020011697 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011698" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011699 if a:base =~ '[/\\]$'
11700 let ret= a:base.a:subdir
11701 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011702 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011703 endif
11704
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011705 elseif a:base =~ '^\a\{3,}://'
11706" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011707 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11708 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11709 if a:subdir == '../'
11710 if curpath =~ '[^/]/[^/]\+/$'
11711 let curpath= substitute(curpath,'[^/]\+/$','','')
11712 else
11713 let curpath=""
11714 endif
11715 let ret= urlbase.curpath
11716 else
11717 let ret= urlbase.curpath.a:subdir
11718 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011719" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11720" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11721" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011722
11723 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011724" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011725 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11726 if a:base =~ '^//'
11727 " keeping initial '//' for the benefit of network share listing support
11728 let ret= '/'.ret
11729 endif
11730 let ret= simplify(ret)
11731 endif
11732
11733" call Dret("s:ComposePath ".ret)
11734 return ret
11735endfun
11736
11737" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011738" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11739" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11740fun! s:DeleteBookmark(fname)
11741" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11742 call s:MergeBookmarks()
11743
11744 if exists("g:netrw_bookmarklist")
11745 let indx= index(g:netrw_bookmarklist,a:fname)
11746 if indx == -1
11747 let indx= 0
11748 while indx < len(g:netrw_bookmarklist)
11749 if g:netrw_bookmarklist[indx] =~ a:fname
11750 call remove(g:netrw_bookmarklist,indx)
11751 let indx= indx - 1
11752 endif
11753 let indx= indx + 1
11754 endwhile
11755 else
11756 " remove exact match
11757 call remove(g:netrw_bookmarklist,indx)
11758 endif
11759 endif
11760
11761" call Dret("s:DeleteBookmark")
11762endfun
11763
11764" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011765" s:FileReadable: o/s independent filereadable {{{2
11766fun! s:FileReadable(fname)
11767" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11768
11769 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011770 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011771 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011772 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011773 endif
11774
11775" call Dret("s:FileReadable ".ret)
11776 return ret
11777endfun
11778
11779" ---------------------------------------------------------------------
11780" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11781" Places correct suffix on end of temporary filename,
11782" using the suffix provided with fname
11783fun! s:GetTempfile(fname)
11784" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11785
11786 if !exists("b:netrw_tmpfile")
11787 " get a brand new temporary filename
11788 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011789" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011790
Bram Moolenaarc236c162008-07-13 17:41:49 +000011791 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011792" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011793
Bram Moolenaar9964e462007-05-05 17:54:07 +000011794 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011795 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11796" 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 +010011797 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011798" call Dret("s:GetTempfile getcwd<".getcwd().">")
11799 return ""
11800 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011801
Bram Moolenaar9964e462007-05-05 17:54:07 +000011802 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011803 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011804" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011805
Bram Moolenaar9964e462007-05-05 17:54:07 +000011806 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011807 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011808 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011809 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011810 if !exists("+shellslash") || !&ssl
11811 let tmpfile = substitute(tmpfile,'/','\','g')
11812 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011813 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011814 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011815 endif
11816 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011817" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011818 else
11819 " re-use temporary filename
11820 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011821" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011822 endif
11823
11824 " use fname's suffix for the temporary file
11825 if a:fname != ""
11826 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011827" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011828 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011829 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011830 elseif a:fname =~ '.txz$'
11831 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011832 else
11833 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11834 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011835" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011836 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011837" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011838 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011839" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011840 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11841 endif
11842 endif
11843
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011844" 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 +000011845" call Dret("s:GetTempfile <".tmpfile.">")
11846 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011847endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011848
11849" ---------------------------------------------------------------------
11850" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011851" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011852fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011853" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011854 if s:user == ""
11855 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11856 else
11857 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11858 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011859 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011860 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011861 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011862 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011863 else
11864 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11865 endif
11866" call Dret("s:MakeSshCmd <".sshcmd.">")
11867 return sshcmd
11868endfun
11869
11870" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011871" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11872fun! s:MakeBookmark(fname)
11873" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11874
11875 if !exists("g:netrw_bookmarklist")
11876 let g:netrw_bookmarklist= []
11877 endif
11878
11879 if index(g:netrw_bookmarklist,a:fname) == -1
11880 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011881 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011882 call add(g:netrw_bookmarklist,a:fname.'/')
11883 elseif a:fname !~ '/'
11884 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11885 else
11886 call add(g:netrw_bookmarklist,a:fname)
11887 endif
11888 call sort(g:netrw_bookmarklist)
11889 endif
11890
11891" call Dret("s:MakeBookmark")
11892endfun
11893
11894" ---------------------------------------------------------------------
11895" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11896fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011897" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011898 " get bookmarks from .netrwbook file
11899 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011900 if filereadable(s:NetrwFile(savefile))
11901" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011902 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011903" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011904 NetrwKeepj call delete(savefile)
11905 endif
11906" call Dret("s:MergeBookmarks")
11907endfun
11908
11909" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011910" s:NetrwBMShow: {{{2
11911fun! s:NetrwBMShow()
11912" call Dfunc("s:NetrwBMShow()")
11913 redir => bmshowraw
11914 menu
11915 redir END
11916 let bmshowlist = split(bmshowraw,'\n')
11917 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011918 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011919 if bmshowfuncs != []
11920 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011921 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011922 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011923 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011924 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011925 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011926" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11927endfun
11928
11929" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011930" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011931fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011932 if !exists("w:netrw_liststyle")
11933 let w:netrw_liststyle= g:netrw_liststyle
11934 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011935" 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 +020011936
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011937" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11938
Bram Moolenaaradc21822011-04-01 18:03:16 +020011939 if &ft != "netrw"
11940 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11941 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011942" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011943
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011944 elseif g:netrw_cursor == 8
11945 if w:netrw_liststyle == s:WIDELIST
11946 setl cursorline
11947 setl cursorcolumn
11948 else
11949 setl cursorline
11950 endif
11951 elseif g:netrw_cursor == 7
11952 setl cursorline
11953 elseif g:netrw_cursor == 6
11954 if w:netrw_liststyle == s:WIDELIST
11955 setl cursorline
11956 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011957 elseif g:netrw_cursor == 4
11958 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011959" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011960 setl cursorline
11961 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011962
11963 elseif g:netrw_cursor == 3
11964 " thin-long-tree: cursorline, user's cursorcolumn
11965 " wide : cursorline, cursorcolumn
11966 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011967" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011968 setl cursorline
11969 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011970 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011971" 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 +020011972 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011973 endif
11974
11975 elseif g:netrw_cursor == 2
11976 " thin-long-tree: cursorline, user's cursorcolumn
11977 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011978" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011979 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011980
11981 elseif g:netrw_cursor == 1
11982 " thin-long-tree: user's cursorline, user's cursorcolumn
11983 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011984 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011985" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011986 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011988" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011989 endif
11990
11991 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011992 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011993" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011994 let &l:cursorline = s:netrw_usercul
11995 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011996 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011997
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011998" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011999" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012000endfun
12001
12002" ---------------------------------------------------------------------
12003" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12004fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012005" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012006 if exists("s:netrw_usercul")
12007 let &l:cursorline = s:netrw_usercul
12008 endif
12009 if exists("s:netrw_usercuc")
12010 let &l:cursorcolumn = s:netrw_usercuc
12011 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012012" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012013" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12014endfun
12015
Christian Brabandt62f7b552024-06-23 20:23:40 +020012016" s:RestoreRegister: restores all registers given in the dict {{{2
12017fun! s:RestoreRegister(dict)
12018 for [key, val] in items(a:dict)
12019 if key == 'unnamed'
12020 let key = ''
12021 endif
12022 call setreg(key, val[0], val[1])
12023 endfor
12024endfun
12025
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012026" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012027" s:NetrwDelete: Deletes a file. {{{2
12028" Uses Steve Hall's idea to insure that Windows paths stay
12029" acceptable. No effect on Unix paths.
12030" Examples of use: let result= s:NetrwDelete(path)
12031fun! s:NetrwDelete(path)
12032" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12033
Bram Moolenaar5c736222010-01-06 20:54:52 +010012034 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012035 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012036 if exists("+shellslash")
12037 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012038 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012039 let result = delete(path)
12040 let &shellslash = sskeep
12041 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012042" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012043 let result= delete(path)
12044 endif
12045 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012046" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012047 let result= delete(path)
12048 endif
12049 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012050 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012051 endif
12052
12053" call Dret("s:NetrwDelete ".result)
12054 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012055endfun
12056
12057" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012058" s:NetrwBufRemover: removes a buffer that: {{{2s
12059" has buffer-id > 1
12060" is unlisted
12061" is unnamed
12062" does not appear in any window
12063fun! s:NetrwBufRemover(bufid)
12064" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12065" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12066" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12067" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12068" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12069
yasuda4dbb2662023-10-04 20:50:35 +020012070 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012071" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012072 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012073 endif
12074
12075" call Dret("s:NetrwBufRemover")
12076endfun
12077
12078" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012079" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012080fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012081" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012082" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012083
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012084 " Clean out the last buffer:
12085 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12086 " If so, delete it.
12087 call s:NetrwBufRemover(bufnr("$"))
12088
Bram Moolenaar446cb832008-06-24 21:56:24 +000012089 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012090" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012091 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12092 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12093 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12094 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12095 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12096 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12097 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12098 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12099 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12100 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12101 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12102 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12103 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12104 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12105 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12106 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12107
Bram Moolenaar85850f32019-07-19 22:05:51 +020012108 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012109" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012110 " when tree listing uses file TreeListing... a new buffer is made.
12111 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012112 " COMBAK: this causes a problem, see P43
12113" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012114 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012115 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012116 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012117" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012118 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012119
Bram Moolenaar446cb832008-06-24 21:56:24 +000012120 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012121" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012122 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12123 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12124 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12125 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12126 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12127 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12128 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12129 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12130 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12131 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12132 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12133 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12134 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12135 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12136 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12137 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12138
Bram Moolenaar5c736222010-01-06 20:54:52 +010012139 if a:0 > 0
12140 let b:netrw_curdir= a:1
12141 if b:netrw_curdir =~ '/$'
12142 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012143 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012144 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012145 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012146 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12147 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012148 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012149 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012150 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012151 endif
12152 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012153 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12154 let &l:bexpr = "netrw#BalloonHelp()"
12155 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012156
Bram Moolenaar8d043172014-01-23 14:24:41 +010012157" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012158endfun
12159
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012160" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012161" s:NetrwExe: executes a string using "!" {{{2
12162fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012163" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012164 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012165" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012166 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12167 set shell& shellcmdflag& shellxquote& shellxescape&
12168 set shellquote& shellpipe& shellredir& shellslash&
12169 exe a:cmd
12170 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12171 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012172" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012173 exe a:cmd
12174 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012175 if v:shell_error
12176 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12177 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012178" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012179endfun
12180
12181" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012182" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12183fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012184 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012185" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012186 let curbuf = bufnr("%")
12187 let curwin = winnr()
12188 let iwin = 1
12189 while iwin <= winnr("$")
12190 exe iwin."wincmd w"
12191 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12192 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12193 let winvars= w:
12194 break
12195 endif
12196 let iwin= iwin + 1
12197 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012198 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012199 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012200" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012201 for k in keys(winvars)
12202 let w:{k}= winvars[k]
12203 endfor
12204 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012205" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012206 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012207endfun
12208
Bram Moolenaara6878372014-03-22 21:02:50 +010012209" ---------------------------------------------------------------------
12210" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012211" Returns: 0=success
12212" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012213fun! s:NetrwLcd(newdir)
12214" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012215" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012216
Bram Moolenaar85850f32019-07-19 22:05:51 +020012217 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012218 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012219 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012220 catch /^Vim\%((\a\+)\)\=:E344/
12221 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12222 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012223 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012224 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12225 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012226 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012227 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12228 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012229 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012230 endif
12231 endif
12232 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012233 let err472= 1
12234 endtry
12235
12236 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012237 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12238 if exists("w:netrw_prvdir")
12239 let a:newdir= w:netrw_prvdir
12240 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012241 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012242" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012243 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012244" 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 +010012245 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012246 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012247" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12248 return -1
12249 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012250
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012251" call Decho("getcwd <".getcwd().">")
12252" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012253" call Dret("s:NetrwLcd 0")
12254 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012255endfun
12256
Bram Moolenaar9964e462007-05-05 17:54:07 +000012257" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012258" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12259" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12260fun! s:NetrwSaveWordPosn()
12261" call Dfunc("NetrwSaveWordPosn()")
12262 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12263" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12264endfun
12265
12266" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012267" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12268" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12269fun! s:NetrwHumanReadable(sz)
12270" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12271
12272 if g:netrw_sizestyle == 'h'
12273 if a:sz >= 1000000000
12274 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12275 elseif a:sz >= 10000000
12276 let sz = printf("%d",a:sz/1000000)."m"
12277 elseif a:sz >= 1000000
12278 let sz = printf("%.1f",a:sz/1000000.0)."m"
12279 elseif a:sz >= 10000
12280 let sz = printf("%d",a:sz/1000)."k"
12281 elseif a:sz >= 1000
12282 let sz = printf("%.1f",a:sz/1000.0)."k"
12283 else
12284 let sz= a:sz
12285 endif
12286
12287 elseif g:netrw_sizestyle == 'H'
12288 if a:sz >= 1073741824
12289 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12290 elseif a:sz >= 10485760
12291 let sz = printf("%d",a:sz/1048576)."M"
12292 elseif a:sz >= 1048576
12293 let sz = printf("%.1f",a:sz/1048576.0)."M"
12294 elseif a:sz >= 10240
12295 let sz = printf("%d",a:sz/1024)."K"
12296 elseif a:sz >= 1024
12297 let sz = printf("%.1f",a:sz/1024.0)."K"
12298 else
12299 let sz= a:sz
12300 endif
12301
12302 else
12303 let sz= a:sz
12304 endif
12305
12306" call Dret("s:NetrwHumanReadable ".sz)
12307 return sz
12308endfun
12309
12310" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012311" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12312" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12313fun! s:NetrwRestoreWordPosn()
12314" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012315 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012316" call Dret("NetrwRestoreWordPosn")
12317endfun
12318
12319" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012320" s:RestoreBufVars: {{{2
12321fun! s:RestoreBufVars()
12322" call Dfunc("s:RestoreBufVars()")
12323
12324 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12325 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12326 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12327 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12328 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12329 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12330
12331" call Dret("s:RestoreBufVars")
12332endfun
12333
12334" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012335" s:RemotePathAnalysis: {{{2
12336fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012337" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012338
Bram Moolenaara6878372014-03-22 21:02:50 +010012339 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012340 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012341 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012342 let s:user = substitute(a:dirname,dirpat,'\3','')
12343 let s:machine = substitute(a:dirname,dirpat,'\4','')
12344 let s:port = substitute(a:dirname,dirpat,'\5','')
12345 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012346 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012347 if s:machine =~ '@'
12348 let dirpat = '^\(.*\)@\(.\{-}\)$'
12349 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12350 let s:machine = substitute(s:machine,dirpat,'\2','')
12351 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012352
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012353" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12354" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12355" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12356" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12357" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12358" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012359
12360" call Dret("s:RemotePathAnalysis")
12361endfun
12362
12363" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012364" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12365" Returns status
12366" Runs system() on
12367" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012368" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012369fun! s:RemoteSystem(cmd)
12370" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12371 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012372 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 +000012373 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012374 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012375 else
12376 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12377 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12378 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012379 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012380 else
12381 let cmd= cmd.' '
12382 endif
12383 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012384" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012385 let ret= system(cmd)
12386 endif
12387" call Dret("s:RemoteSystem ".ret)
12388 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012389endfun
12390
12391" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012392" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012393fun! s:RestoreWinVars()
12394" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012395 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012396 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12397 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12398 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12399 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12400 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12401 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12402 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12403 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12404 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12405 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12406 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12407 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012408 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12409 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012410 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12411 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12412 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12413" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012414endfun
12415
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012416" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012417" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12418"
12419" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12420" is true) and a command, :Rexplore, which call this function.
12421"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012422" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012423"
12424" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012425fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012426 if exists("s:netrwdrag")
12427 return
12428 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012429" 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 +010012430" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12431" 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 +010012432
12433 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012434 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012435" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012436 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012437 unlet w:netrw_rexfile
12438" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012439 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012440" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012441" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12442" 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 +020012443 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012444
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012445 " ---------------------------
12446 " :Rex issued while in a file
12447 " ---------------------------
12448
Bram Moolenaara6878372014-03-22 21:02:50 +010012449 " record current file so :Rex can return to it from netrw
12450 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012451" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012452
12453 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012454" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012455 return
12456 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012457" 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 +020012458 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012459 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012460 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012461 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012462 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012463 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012464 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012465 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012466 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012467" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12468 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012469" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12470 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012471 if exists("s:rexposn_".bufnr('%'))
12472 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012473 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012474 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012475" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012476 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012477
Bram Moolenaar85850f32019-07-19 22:05:51 +020012478 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12479 if exists("s:explore_match")
12480 exe "2match netrwMarkFile /".s:explore_match."/"
12481 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012482 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012483
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012484" 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 +010012485" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012486endfun
12487
12488" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012489" s:SaveBufVars: save selected b: variables to s: variables {{{2
12490" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012491fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012492" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012493
12494 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12495 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12496 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12497 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12498 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12499 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12500
12501" call Dret("s:SaveBufVars")
12502endfun
12503
12504" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012505" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12506fun! s:SavePosn(posndict)
12507" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12508
Bram Moolenaar85850f32019-07-19 22:05:51 +020012509 if !exists("a:posndict[bufnr('%')]")
12510 let a:posndict[bufnr("%")]= []
12511 endif
12512" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12513 call add(a:posndict[bufnr("%")],winsaveview())
12514" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012515
12516" call Dret("s:SavePosn posndict")
12517 return a:posndict
12518endfun
12519
12520" ---------------------------------------------------------------------
12521" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12522fun! s:RestorePosn(posndict)
12523" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012524 if exists("a:posndict")
12525 if has_key(a:posndict,bufnr("%"))
12526" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12527 let posnlen= len(a:posndict[bufnr("%")])
12528 if posnlen > 0
12529 let posnlen= posnlen - 1
12530" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12531 call winrestview(a:posndict[bufnr("%")][posnlen])
12532 call remove(a:posndict[bufnr("%")],posnlen)
12533" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12534 endif
12535 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012536 endif
12537" call Dret("s:RestorePosn")
12538endfun
12539
12540" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012541" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012542fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012543" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012544 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12545 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12546 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12547 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12548 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12549 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12550 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12551 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12552 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12553 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12554 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12555 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12556 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12557 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12558 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12559 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12560 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12561 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12562" call Dret("s:SaveWinVars")
12563endfun
12564
12565" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012566" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012567" To allow separate windows to have their own activities, such as
12568" Explore **/pattern, several variables have been made window-oriented.
12569" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012570" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012571" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012572fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012573" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012574 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12575 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12576 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12577 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12578 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12579 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12580 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12581 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12582 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12583 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12584" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012585endfun
12586
12587" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012588" s:SetRexDir: set directory for :Rexplore {{{2
12589fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012590" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012591 let w:netrw_rexdir = a:dirname
12592 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012593 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012594" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12595" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012596" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012597" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012598" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012599endfun
12600
12601" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012602" s:ShowLink: used to modify thin and tree listings to show links {{{2
12603fun! s:ShowLink()
12604" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012605" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12606" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012607 if exists("b:netrw_curdir")
12608 norm! $?\a
12609 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12610 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012611" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12612" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12613" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12614 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012615 let dirlen = strlen(b:netrw_curdir)
12616 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012617" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012618 endif
12619 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012620" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12621" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012622 setl noro ma
12623 call setline(".",modline)
12624 setl ro noma nomod
12625 endif
12626" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12627endfun
12628
12629" ---------------------------------------------------------------------
12630" s:ShowStyle: {{{2
12631fun! s:ShowStyle()
12632 if !exists("w:netrw_liststyle")
12633 let liststyle= g:netrw_liststyle
12634 else
12635 let liststyle= w:netrw_liststyle
12636 endif
12637 if liststyle == s:THINLIST
12638 return s:THINLIST.":thin"
12639 elseif liststyle == s:LONGLIST
12640 return s:LONGLIST.":long"
12641 elseif liststyle == s:WIDELIST
12642 return s:WIDELIST.":wide"
12643 elseif liststyle == s:TREELIST
12644 return s:TREELIST.":tree"
12645 else
12646 return 'n/a'
12647 endif
12648endfun
12649
12650" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012651" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12652" Solution from Nicolai Weibull, vim docs (:help strlen()),
12653" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012654fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012655" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12656
12657 if v:version >= 703 && exists("*strdisplaywidth")
12658 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012659
Bram Moolenaar8d043172014-01-23 14:24:41 +010012660 elseif type(g:Align_xstrlen) == 1
12661 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12662 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012663
Bram Moolenaar8d043172014-01-23 14:24:41 +010012664 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012665 " number of codepoints (Latin a + combining circumflex is two codepoints)
12666 " (comment from TM, solution from NW)
12667 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012668
Bram Moolenaar8d043172014-01-23 14:24:41 +010012669 elseif g:Align_xstrlen == 2
12670 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012671 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12672 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012673 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012674
Bram Moolenaar8d043172014-01-23 14:24:41 +010012675 elseif g:Align_xstrlen == 3
12676 " virtual length (counting, for instance, tabs as anything between 1 and
12677 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012678 " preceded by lam, one otherwise, etc.)
12679 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012680 let modkeep= &l:mod
12681 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012682 call setline(line("."),a:x)
12683 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012684 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012685 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012686 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012687
Bram Moolenaar446cb832008-06-24 21:56:24 +000012688 else
12689 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012690 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012691 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012692" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012693 return ret
12694endfun
12695
12696" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012697" s:ShellEscape: shellescape(), or special windows handling {{{2
12698fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012699 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012700 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12701 endif
12702 let f = a:0 > 0 ? a:1 : 0
12703 return shellescape(a:s, f)
12704endfun
12705
12706" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012707" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012708fun! s:TreeListMove(dir)
12709" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012710 let curline = getline('.')
12711 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12712 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12713 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12714 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12715 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12716 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12717" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12718" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12719" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12720" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12721" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12722 " COMBAK : need to handle when on a directory
12723 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012724 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012725 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012726 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012727 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012728" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012729 elseif a:dir == '[]' && nxtline != ''
12730 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012731" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012732 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12733 if nl != 0
12734 NetrwKeepj norm! k
12735 else
12736 NetrwKeepj norm! G
12737 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012738" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012739 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012740 endif
12741
12742" call Dret("s:TreeListMove")
12743endfun
12744
12745" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012746" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12747" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12748" can't be called except via emenu. But due to locale, that menu line may not be called
12749" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12750fun! s:UpdateBuffersMenu()
12751" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012752 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012753 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012754 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012755 catch /^Vim\%((\a\+)\)\=:E/
12756 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012757 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012758 endtry
12759 endif
12760" call Dret("s:UpdateBuffersMenu")
12761endfun
12762
12763" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012764" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012765" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012766fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012767" call Dfunc("s:UseBufWinVars()")
12768 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012769 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12770 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12771 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12772 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12773 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12774 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12775 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12776 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12777 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 +000012778" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012779endfun
12780
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012781" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012782" s:UserMaps: supports user-defined UserMaps {{{2
12783" * calls a user-supplied funcref(islocal,curdir)
12784" * interprets result
12785" See netrw#UserMaps()
12786fun! s:UserMaps(islocal,funcname)
12787" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12788
12789 if !exists("b:netrw_curdir")
12790 let b:netrw_curdir= getcwd()
12791 endif
12792 let Funcref = function(a:funcname)
12793 let result = Funcref(a:islocal)
12794
12795 if type(result) == 1
12796 " if result from user's funcref is a string...
12797" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12798 if result == "refresh"
12799" call Decho("refreshing display",'~'.expand("<slnum>"))
12800 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12801 elseif result != ""
12802" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12803 exe result
12804 endif
12805
12806 elseif type(result) == 3
12807 " if result from user's funcref is a List...
12808" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12809 for action in result
12810 if action == "refresh"
12811" call Decho("refreshing display",'~'.expand("<slnum>"))
12812 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12813 elseif action != ""
12814" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12815 exe action
12816 endif
12817 endfor
12818 endif
12819
12820" call Dret("s:UserMaps")
12821endfun
12822
Bram Moolenaar85850f32019-07-19 22:05:51 +020012823" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012824" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012825" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012826let &cpo= s:keepcpo
12827unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012828
Bram Moolenaar85850f32019-07-19 22:05:51 +020012829" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012830" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012831" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012832" vim:ts=8 fdm=marker