blob: cfa85e26faf3b1a080649fd5da6bd129863b4b80 [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)
22" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010023" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000024" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010025" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000026" Permission is hereby granted to use and distribute this code,
27" with or without modifications, provided that this copyright
28" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000029" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000030" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000031" expressed or implied. By using this plugin, you agree that
32" in no event will the copyright holder be liable for any damages
33" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010034"
35" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
36" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
37"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020038"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000039"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000040" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000041" (James 1:22 RSV)
42" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000043" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000044if &cp || exists("g:loaded_netrw")
45 finish
46endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020047
48" Check that vim has patches that netrw requires.
49" Patches needed for v7.4: 1557, and 213.
50" (netrw will benefit from vim's having patch#656, too)
51let s:needspatches=[1557,213]
52if exists("s:needspatches")
53 for ptch in s:needspatches
54 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
55 if !exists("s:needpatch{ptch}")
56 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
57 endif
58 let s:needpatch{ptch}= 1
59 finish
60 endif
61 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020062endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020063
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010064let g:loaded_netrw = "v173"
Bram Moolenaar9964e462007-05-05 17:54:07 +000065if !exists("s:NOTE")
66 let s:NOTE = 0
67 let s:WARNING = 1
68 let s:ERROR = 2
69endif
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
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200107 if g:netrw_use_errorwindow == 2 && (v:version > 802 || (v:version == 802 && has("patch486")))
108 " 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
223" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200224" Default option values: {{{2
225let g:netrw_localcopycmdopt = ""
226let g:netrw_localcopydircmdopt = ""
227let g:netrw_localmkdiropt = ""
228let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200229
230" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000231" Default values for netrw's global protocol variables {{{2
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200232if (v:version > 802 || (v:version == 802 && has("patch486"))) && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on") && has("mouse")
233 call s:NetrwInit("g:netrw_use_errorwindow",2)
234else
235 call s:NetrwInit("g:netrw_use_errorwindow",1)
236endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200237
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000238if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100239 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000240 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100241 elseif executable("curl")
242 let g:netrw_dav_cmd = "curl"
243 else
244 let g:netrw_dav_cmd = ""
245 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000247if !exists("g:netrw_fetch_cmd")
248 if executable("fetch")
249 let g:netrw_fetch_cmd = "fetch -o"
250 else
251 let g:netrw_fetch_cmd = ""
252 endif
253endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100254if !exists("g:netrw_file_cmd")
255 if executable("elinks")
256 call s:NetrwInit("g:netrw_file_cmd","elinks")
257 elseif executable("links")
258 call s:NetrwInit("g:netrw_file_cmd","links")
259 endif
260endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000261if !exists("g:netrw_ftp_cmd")
262 let g:netrw_ftp_cmd = "ftp"
263endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200264let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200265if !exists("g:netrw_ftp_options")
266 let g:netrw_ftp_options= "-i -n"
267endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000268if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100269 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100270 let g:netrw_http_cmd = "wget"
271 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100272 elseif executable("curl")
273 let g:netrw_http_cmd = "curl"
274 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200275 elseif executable("elinks")
276 let g:netrw_http_cmd = "elinks"
277 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000278 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100279 let g:netrw_http_cmd = "fetch"
280 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200281 elseif executable("links")
282 let g:netrw_http_cmd = "links"
283 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000284 else
285 let g:netrw_http_cmd = ""
286 endif
287endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100288call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100289call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100290call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
291call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200292call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200293if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200294 if executable("scp")
295 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
296 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200297 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200298 else
299 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
300 endif
301endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100302call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
303call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000304
Nir Lichtman1e34b952024-05-08 19:19:34 +0200305if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000306 \ && exists("g:netrw_use_nt_rcp")
307 \ && g:netrw_use_nt_rcp
308 \ && executable( $SystemRoot .'/system32/rcp.exe')
309 let s:netrw_has_nt_rcp = 1
310 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000311else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000312 let s:netrw_has_nt_rcp = 0
313 let s:netrw_rcpmode = ''
314endif
315
316" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000317" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000318" Cygwin Detection ------- {{{3
319if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200320 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
321 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000322 else
323 let g:netrw_cygwin= 0
324 endif
325endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000326" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100327call s:NetrwInit("g:netrw_alto" , &sb)
328call s:NetrwInit("g:netrw_altv" , &spr)
329call s:NetrwInit("g:netrw_banner" , 1)
330call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200331call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100332call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200333call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100334call s:NetrwInit("g:netrw_compress" , "gzip")
335call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200336if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
337 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
338 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000339endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200340call s:NetrwInit("g:netrw_cursor" , 2)
341let s:netrw_usercul = &cursorline
342let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200343"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100344call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000345" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200346call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200347call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200348call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100349call s:NetrwInit("g:netrw_dirhistmax" , 10)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200350call s:NetrwInit("g:netrw_errorlvl" , s:NOTE)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100351call s:NetrwInit("g:netrw_fastbrowse" , 1)
352call 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 +0000353if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000354 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
355 let g:netrw_ftp_list_cmd = "ls -lF"
356 let g:netrw_ftp_timelist_cmd = "ls -tlF"
357 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000358 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000359 let g:netrw_ftp_list_cmd = "dir"
360 let g:netrw_ftp_timelist_cmd = "dir"
361 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000362 endif
363endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100364call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000365" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100366call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000367if !exists("g:netrw_ignorenetrc")
368 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
369 let g:netrw_ignorenetrc= 1
370 else
371 let g:netrw_ignorenetrc= 0
372 endif
373endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100374call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000375if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000376 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100377 if exists("g:netrw_list_cmd_options")
378 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
379 else
380 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
381 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000382 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200383 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100384 if exists("g:netrw_list_cmd_options")
385 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
386 else
387 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
388 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000389 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100390" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000391 let g:netrw_list_cmd= ""
392 endif
393endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100394call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000395" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200396if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200397 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200398 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
399endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100400if !exists("g:netrw_localcmdshell")
401 let g:netrw_localcmdshell= ""
402endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000403if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200404 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000405 if g:netrw_cygwin
406 let g:netrw_localcopycmd= "cp"
407 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000408 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200409 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000410 endif
411 elseif has("unix") || has("macunix")
412 let g:netrw_localcopycmd= "cp"
413 else
414 let g:netrw_localcopycmd= ""
415 endif
416endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100417if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200418 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100419 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200420 let g:netrw_localcopydircmd = "cp"
421 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100422 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000423 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200424 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100425 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200426 elseif has("unix")
427 let g:netrw_localcopydircmd = "cp"
428 let g:netrw_localcopydircmdopt= " -R"
429 elseif has("macunix")
430 let g:netrw_localcopydircmd = "cp"
431 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100432 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200433 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100434 endif
435endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200436if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100437 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200438 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
439endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200440if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200441 if g:netrw_cygwin
442 call s:NetrwInit("g:netrw_localmkdir","mkdir")
443 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000444 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200445 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200446 endif
447else
448 call s:NetrwInit("g:netrw_localmkdir","mkdir")
449endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200450call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200451if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200452 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200453 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
454endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000455if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200456 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000457 if g:netrw_cygwin
458 let g:netrw_localmovecmd= "mv"
459 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000460 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200461 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000462 endif
463 elseif has("unix") || has("macunix")
464 let g:netrw_localmovecmd= "mv"
465 else
466 let g:netrw_localmovecmd= ""
467 endif
468endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100469" following serves as an example for how to insert a version&patch specific test
470"if v:version < 704 || (v:version == 704 && !has("patch1107"))
471"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100472call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
473" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000474if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000475 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000476endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000477if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000478 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
479endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000480" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100481call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
482call s:NetrwInit("g:netrw_maxfilenamelen", 32)
483call s:NetrwInit("g:netrw_menu" , 1)
484call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200485call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100486call s:NetrwInit("g:netrw_retmap" , 0)
487if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
488 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200489elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100490 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
491else
492 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000493endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100494call s:NetrwInit("g:netrw_preview" , 0)
495call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100496call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100497call s:NetrwInit("g:netrw_sshport" , "-p")
498call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
499call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
500call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100501call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
502" Default values - q-s ---------- {{{3
503call s:NetrwInit("g:netrw_quickhelp",0)
504let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100505 \ "(create new) %:file d:directory",
506 \ "(windows split&open) o:horz v:vert p:preview",
507 \ "i:style qf:file info O:obtain r:reverse",
508 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
509 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
510 \ "(history) qb:list u:go up U:go down",
511 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100512" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
513call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100514if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
515 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
516else
517 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
518endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100519call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
520call s:NetrwInit("g:netrw_sort_options" , "")
521call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000522if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100523 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200524 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525 else
526 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000527 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000528endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529call s:NetrwInit("g:netrw_special_syntax" , 0)
530call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200531call s:NetrwInit("g:netrw_suppress_gx_mesg", 1)
Bram Moolenaara6878372014-03-22 21:02:50 +0100532call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100533call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000534" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200536if !exists("g:netrw_xstrlen")
537 if exists("g:Align_xstrlen")
538 let g:netrw_xstrlen= g:Align_xstrlen
539 elseif exists("g:drawit_xstrlen")
540 let g:netrw_xstrlen= g:drawit_xstrlen
541 elseif &enc == "latin1" || !has("multi_byte")
542 let g:netrw_xstrlen= 0
543 else
544 let g:netrw_xstrlen= 1
545 endif
546endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100547call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200548call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100549call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200550if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000551" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000552" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100553call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200554if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200555 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200556else
Bram Moolenaarff034192013-04-24 18:51:19 +0200557 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200558endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200559call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100560call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
561call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100562if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100563 let s:treedepthstring= "│ "
564else
565 let s:treedepthstring= "| "
566endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200567call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000568
569" BufEnter event ignored by decho when following variable is true
570" Has a side effect that doau BufReadPost doesn't work, so
571" files read by network transfer aren't appropriately highlighted.
572"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573
Bram Moolenaaradc21822011-04-01 18:03:16 +0200574" ======================
575" Netrw Initialization: {{{1
576" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200577if 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 +0100578" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100579 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200580" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100581 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100582 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
583 au VimEnter * let s:initbeval= &beval
584"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100585" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
586" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
587" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
588" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
589" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
590" 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 +0200591endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200592au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200593
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200594if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100595 com! -nargs=* NetrwKeepj keepj <args>
596else
597 let g:netrw_keepj= ""
598 com! -nargs=* NetrwKeepj <args>
599endif
600
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000601" ==============================
602" Netrw Utility Functions: {{{1
603" ==============================
604
Bram Moolenaaradc21822011-04-01 18:03:16 +0200605" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100606" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100607if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100608" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100609 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100610 if &ft != "netrw"
611 return ""
612 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200613 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
614 " popup error window is still showing
615 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
616 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
617 " text under mouse hasn't changed; only close window when it changes
618 call popup_close(s:popuperr_id)
619 unlet s:popuperr_text
620 else
621 let s:popuperr_text= v:beval_text
622 endif
623 let mesg= ""
624 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 +0100625 let mesg= ""
626 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
627 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
628 elseif getline(v:beval_lnum) =~ '^"\s*/'
629 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
630 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100631 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100632 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
633 let mesg = "S: edit sorting sequence"
634 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
635 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
636 elseif v:beval_text == "Quick" || v:beval_text == "Help"
637 let mesg = "Help: press <F1>"
638 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
639 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
640 else
641 let mesg= ""
642 endif
643 return mesg
644 endfun
645"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100646" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
647" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
648" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
649" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
650" 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 +0200651endif
652
Bram Moolenaar071d4272004-06-13 20:20:40 +0000653" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200654" netrw#Explore: launch the local browser in the directory of the current file {{{2
655" indx: == -1: Nexplore
656" == -2: Pexplore
657" == +: this is overloaded:
658" * If Nexplore/Pexplore is in use, then this refers to the
659" indx'th item in the w:netrw_explore_list[] of items which
660" matched the */pattern **/pattern *//pattern **//pattern
661" * If Hexplore or Vexplore, then this will override
662" g:netrw_winsize to specify the qty of rows or columns the
663" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100664" 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 +0200665" dosplit==1: the window will be split before running the local browser
666" style == 0: Explore style == 1: Explore!
667" == 2: Hexplore style == 3: Hexplore!
668" == 4: Vexplore style == 5: Vexplore!
669" == 6: Texplore
670fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100671" 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 +0100672" 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 +0200673 if !exists("b:netrw_curdir")
674 let b:netrw_curdir= getcwd()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100675" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200676 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100677
678 " record current file for Rexplore's benefit
679 if &ft != "netrw"
680 let w:netrw_rexfile= expand("%:p")
681 endif
682
683 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200684 let curdir = simplify(b:netrw_curdir)
685 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200686 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200687 let curdir= substitute(curdir,'\','/','g')
688 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100689" call Decho("curdir<".curdir."> curfiledir<".curfiledir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100690
691 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
692 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
693 " try Explore again.
694 if a:0 > 0
695" call Decho('considering retry: a:1<'.a:1.'>: '.
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100696 \ ((a:1 =~ "\\\s")? 'has backslash whitespace' : 'does not have backslash whitespace').', '.
697 \ ((filereadable(s:NetrwFile(a:1)))? 'is readable' : 'is not readable').', '.
698 \ ((isdirectory(s:NetrwFile(a:1))))? 'is a directory' : 'is not a directory',
699 \ '~'.expand("<slnum>"))
700 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200701 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
702 if a1 != a:1
703 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
704 return
705 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100706 endif
707 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200708
709 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200710 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100711" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100712 sil! let keepregstar = @*
713 sil! let keepregplus = @+
714 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200715 sil! let keepregslash= @/
716
Bram Moolenaar8d043172014-01-23 14:24:41 +0100717 " if dosplit
718 " -or- file has been modified AND file not hidden when abandoned
719 " -or- Texplore used
720 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100721" call Decho("case dosplit=".a:dosplit." modified=".&modified." a:style=".a:style.": dosplit or file has been modified",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 call s:SaveWinVars()
723 let winsz= g:netrw_winsize
724 if a:indx > 0
725 let winsz= a:indx
726 endif
727
728 if a:style == 0 " Explore, Sexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100729" call Decho("style=0: Explore or Sexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200730 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200731 if winsz == 0|let winsz= ""|endif
732 exe "noswapfile ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100733" call Decho("exe noswapfile ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200734
735 elseif a:style == 1 "Explore!, Sexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100736" call Decho("style=1: Explore! or Sexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200737 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200738 if winsz == 0|let winsz= ""|endif
739 exe "keepalt noswapfile ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100740" call Decho("exe keepalt noswapfile ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200741
742 elseif a:style == 2 " Hexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100743" call Decho("style=2: Hexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200744 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200745 if winsz == 0|let winsz= ""|endif
746 exe "keepalt noswapfile bel ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100747" call Decho("exe keepalt noswapfile bel ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200748
749 elseif a:style == 3 " Hexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100750" call Decho("style=3: Hexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200751 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200752 if winsz == 0|let winsz= ""|endif
753 exe "keepalt noswapfile abo ".winsz."wincmd s"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100754" call Decho("exe keepalt noswapfile abo ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200755
756 elseif a:style == 4 " Vexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100757" call Decho("style=4: Vexplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200759 if winsz == 0|let winsz= ""|endif
760 exe "keepalt noswapfile lefta ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100761" call Decho("exe keepalt noswapfile lefta ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200762
763 elseif a:style == 5 " Vexplore!
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100764" call Decho("style=5: Vexplore!",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200765 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200766 if winsz == 0|let winsz= ""|endif
767 exe "keepalt noswapfile rightb ".winsz."wincmd v"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100768" call Decho("exe keepalt noswapfile rightb ".winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200769
770 elseif a:style == 6 " Texplore
771 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100772" call Decho("style = 6: Texplore",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200773 exe "keepalt tabnew ".fnameescape(curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100774" call Decho("exe keepalt tabnew ".fnameescape(curdir),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 call s:RestoreBufVars()
776 endif
777 call s:RestoreWinVars()
778" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100779" call Decho("case a:dosplit=".a:dosplit." AND modified=".&modified." AND a:style=".a:style." is not 6",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200780 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100781 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200782
783 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100784" call Decho("case [a:0=".a:0."] > 0: a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100786" call Decho("..case a:1<".a:1.">: starts with ~ and unix or cygwin",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200787 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100788" call Decho("..using dirname<".dirname."> (case: ~ && unix||cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200789 elseif a:1 == '.'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100790" call Decho("..case a:1<".a:1.">: matches .",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
792 if dirname !~ '/$'
793 let dirname= dirname."/"
794 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100795" call Decho("..using dirname<".dirname."> (case: ".(exists("b:netrw_curdir")? "b:netrw_curdir" : "getcwd()").")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 elseif a:1 =~ '\$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100797" call Decho("..case a:1<".a:1.">: matches ending $",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200798 let dirname= simplify(expand(a:1))
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100799" call Decho("..using user-specified dirname<".dirname."> with $env-var",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200800 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100801" call Decho("..case a:1<".a:1.">: other, not pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 let dirname= simplify(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100803" call Decho("..using user-specified dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100805" call Decho("..case a:1: pattern or filepattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 let dirname= a:1
807 endif
808 else
809 " clear explore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100810" call Decho("case a:0=".a:0.": clearing Explore list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 call s:NetrwClearExplore()
812" call Dret("netrw#Explore : cleared list")
813 return
814 endif
815
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100816" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200817 if dirname =~ '\.\./\=$'
818 let dirname= simplify(fnamemodify(dirname,':p:h'))
819 elseif dirname =~ '\.\.' || dirname == '.'
820 let dirname= simplify(fnamemodify(dirname,':p'))
821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100822" call Decho("dirname<".dirname."> (after simplify)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200823
824 if dirname =~ '^\*//'
825 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100826" call Decho("case starpat=1: Explore *//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
828 let starpat= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100829" call Decho("..Explore *//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
831
832 elseif dirname =~ '^\*\*//'
833 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100834" call Decho("case starpat=2: Explore **//pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200835 let pattern= substitute(dirname,'^\*\*//','','')
836 let starpat= 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100837" call Decho("..Explore **//pat: (starpat=".starpat.") dirname<".dirname."> -> pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200838
839 elseif dirname =~ '/\*\*/'
840 " handle .../**/.../filepat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100841" call Decho("case starpat=4: Explore .../**/.../filepat",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200842 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200843 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200844 let b:netrw_curdir = prefixdir
845 else
846 let b:netrw_curdir= getcwd().'/'.prefixdir
847 endif
848 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
849 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100850" call Decho("..pwd<".getcwd()."> dirname<".dirname.">",'~'.expand("<slnum>"))
851" call Decho("..case Explore ../**/../filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200852
853 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200854 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200855 let starpat= 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100856" call Decho("case starpat=3: Explore */filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200857
858 elseif dirname=~ '^\*\*/'
859 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
860 let starpat= 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100861" call Decho("case starpat=4: Explore **/filepat (starpat=".starpat.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200862
863 else
864 let starpat= 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100865" call Decho("case starpat=0: default",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200866 endif
867
868 if starpat == 0 && a:indx >= 0
869 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100870" 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 +0200871 if dirname == ""
872 let dirname= curfiledir
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100873" call Decho("..empty dirname, using current file's directory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200874 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200875 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200876 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200877 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200878 if dirname == ""
879 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200880 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100881 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100882 " depending on whether backslashes have been converted to forward slashes by earlier code).
883 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200884 let dirname= b:netrw_curdir."/".dirname
885 endif
886 elseif dirname !~ '^/'
887 let dirname= b:netrw_curdir."/".dirname
888 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100889" call Decho("..calling LocalBrowseCheck(dirname<".dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100891" call Decho(" modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
892" 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 +0200893 endif
894 if exists("w:netrw_bannercnt")
895 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
896 " If one wants to return the same place in the netrw window, use :Rex instead.
897 exe w:netrw_bannercnt
898 endif
899
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100900" call Decho("curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200901 " ---------------------------------------------------------------------
902 " Jan 24, 2013: not sure why the following was present. See P08-Ingelrest
903" if has("win32") || has("win95") || has("win64") || has("win16")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100904" NetrwKeepj call search('\<'.substitute(curdir,'^.*[/\\]','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200905" else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100906" NetrwKeepj call search('\<'.substitute(curdir,'^.*/','','e').'\>','cW')
Bram Moolenaarff034192013-04-24 18:51:19 +0200907" endif
908 " ---------------------------------------------------------------------
909
910 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
911 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
912 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
913 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
914 elseif a:indx <= 0
915 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100916" 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 +0200917 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100918" call Decho("..set up <s-up> and <s-down> maps",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200919 let s:didstarstar= 1
920 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
921 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
922 endif
923
924 if has("path_extra")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100925" call Decho("..starpat=".starpat.": has +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200926 if !exists("w:netrw_explore_indx")
927 let w:netrw_explore_indx= 0
928 endif
929
930 let indx = a:indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100931" call Decho("..starpat=".starpat.": set indx= [a:indx=".indx."]",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200932
933 if indx == -1
934 " Nexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100935" call Decho("..case Nexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200936 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100937 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 +0200938 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100939" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100940 if @* != keepregstar | sil! let @* = keepregstar | endif
941 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100942 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200943 sil! let @/ = keepregslash
944" call Dret("netrw#Explore")
945 return
946 endif
947 let indx= w:netrw_explore_indx
948 if indx < 0 | let indx= 0 | endif
949 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
950 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100951" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
953 let indx= indx + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100954" call Decho("....indx=".indx." (Nexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200955 endwhile
956 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100957" call Decho("....Nexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200958
959 elseif indx == -2
960 " Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100961" call Decho("case Pexplore with starpat=".starpat.": (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200962 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100963 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 +0200964 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100965" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100966 if @* != keepregstar | sil! let @* = keepregstar | endif
967 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100968 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200969 sil! let @/ = keepregslash
970" call Dret("netrw#Explore")
971 return
972 endif
973 let indx= w:netrw_explore_indx
974 if indx < 0 | let indx= 0 | endif
975 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
976 let curfile= w:netrw_explore_list[indx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100977" call Decho("....indx=".indx." curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200978 while indx >= 0 && curfile == w:netrw_explore_list[indx]
979 let indx= indx - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100980" call Decho("....indx=".indx." (Pexplore while loop)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200981 endwhile
982 if indx < 0 | let indx= 0 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100983" call Decho("....Pexplore: indx= [w:netrw_explore_indx=".w:netrw_explore_indx."]=".indx,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200984
985 else
986 " Explore -- initialize
987 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100988" call Decho("..starpat=".starpat.": case Explore: initialize (indx=".indx.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100989 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200990 let w:netrw_explore_indx= 0
991 if !exists("b:netrw_curdir")
992 let b:netrw_curdir= getcwd()
993 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100994" call Decho("....starpat=".starpat.": b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200995
996 " switch on starpat to build the w:netrw_explore_list of files
997 if starpat == 1
998 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100999" call Decho("..case starpat=".starpat.": build *//pattern list (curdir-only srch for files containing pattern) &hls=".&hls,'~'.expand("<slnum>"))
1000" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001002 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001003 catch /^Vim\%((\a\+)\)\=:E480/
1004 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
1005" call Dret("netrw#Explore : unable to find pattern<".pattern.">")
1006 return
1007 endtry
1008 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
1009 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1010
1011 elseif starpat == 2
1012 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001013" call Decho("..case starpat=".starpat.": build **//pattern list (recursive descent files containing pattern)",'~'.expand("<slnum>"))
1014" call Decho("....pattern<".pattern.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001016 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +02001017 catch /^Vim\%((\a\+)\)\=:E480/
1018 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
1019 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001020 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001021" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001022 if @* != keepregstar | sil! let @* = keepregstar | endif
1023 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001024 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001025 sil! let @/ = keepregslash
1026" call Dret("netrw#Explore : no files matched pattern")
1027 return
1028 endtry
1029 let s:netrw_curdir = b:netrw_curdir
1030 let w:netrw_explore_list = getqflist()
1031 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
1032 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
1033
1034 elseif starpat == 3
1035 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001036" 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 +02001037 let filepat= substitute(dirname,'^\*/','','')
1038 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001039" call Decho("....b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
1040" call Decho("....filepat<".filepat.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001041 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1042 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1043
1044 elseif starpat == 4
1045 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001046" 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 +02001047 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1048 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1049 endif " switch on starpat to build w:netrw_explore_list
1050
1051 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001052" call Decho("....w:netrw_explore_list<".string(w:netrw_explore_list).">",'~'.expand("<slnum>"))
1053" call Decho("....w:netrw_explore_listlen=".w:netrw_explore_listlen,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001054
1055 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001056 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001057 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001058" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001059 if @* != keepregstar | sil! let @* = keepregstar | endif
1060 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001061 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001062 sil! let @/ = keepregslash
1063" call Dret("netrw#Explore : no files matched")
1064 return
1065 endif
1066 endif " if indx ... endif
1067
1068 " NetrwStatusLine support - for exploring support
1069 let w:netrw_explore_indx= indx
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001070" 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 +02001071
1072 " wrap the indx around, but issue a note
1073 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001074" call Decho("....wrap indx (indx=".indx." listlen=".w:netrw_explore_listlen.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1076 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001077 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001078 endif
1079
1080 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001081" call Decho("....dirfile=w:netrw_explore_list[indx=".indx."]= <".dirfile.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001083" call Decho("....newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001084
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001085" call Decho("....calling LocalBrowseCheck(newdir<".newdir.">)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001086 call netrw#LocalBrowseCheck(newdir)
1087 if !exists("w:netrw_liststyle")
1088 let w:netrw_liststyle= g:netrw_liststyle
1089 endif
1090 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001091 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001092 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001093 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001094 endif
1095 let w:netrw_explore_mtchcnt = indx + 1
1096 let w:netrw_explore_bufnr = bufnr("%")
1097 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001098 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001099" 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 +02001100
1101 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001102" call Decho("..your vim does not have +path_extra",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001103 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001104 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 +02001105 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001106 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001107" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001108 if @* != keepregstar | sil! let @* = keepregstar | endif
1109 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001110 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001111 sil! let @/ = keepregslash
1112" call Dret("netrw#Explore : missing +path_extra")
1113 return
1114 endif
1115
1116 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001117" call Decho("..default case: Explore newdir<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001118 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1119 sil! unlet w:netrw_treedict
1120 sil! unlet w:netrw_treetop
1121 endif
1122 let newdir= dirname
1123 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001124 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001125 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001126 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir))
Bram Moolenaarff034192013-04-24 18:51:19 +02001127 endif
1128 endif
1129
1130 " visual display of **/ **// */ Exploration files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001131" call Decho("w:netrw_explore_indx=".(exists("w:netrw_explore_indx")? w:netrw_explore_indx : "doesn't exist"),'~'.expand("<slnum>"))
1132" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "n/a").">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001133 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001134" call Decho("s:explore_prvdir<".(exists("s:explore_prvdir")? s:explore_prvdir : "-doesn't exist-"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001135 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001136 " only update match list when current directory isn't the same as before
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001137" call Decho("only update match list when current directory not the same as before",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001138 let s:explore_prvdir = b:netrw_curdir
1139 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001140 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001141 if b:netrw_curdir !~ '/$'
1142 let dirlen= dirlen + 1
1143 endif
1144 let prvfname= ""
1145 for fname in w:netrw_explore_list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001146" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001147 if fname =~ '^'.b:netrw_curdir
1148 if s:explore_match == ""
1149 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1150 else
1151 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1152 endif
1153 elseif fname !~ '^/' && fname != prvfname
1154 if s:explore_match == ""
1155 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1156 else
1157 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1158 endif
1159 endif
1160 let prvfname= fname
1161 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001162" call Decho("explore_match<".s:explore_match.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001163 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1164 exe "2match netrwMarkFile /".s:explore_match."/"
1165 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001166 endif
1167 echo "<s-up>==Pexplore <s-down>==Nexplore"
1168 else
1169 2match none
1170 if exists("s:explore_match") | unlet s:explore_match | endif
1171 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001172" call Decho("cleared explore match list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001173 endif
1174
Bram Moolenaara6878372014-03-22 21:02:50 +01001175 " since Explore may be used to initialize netrw's browser,
1176 " there's no danger of a late FocusGained event on initialization.
1177 " Consequently, set s:netrw_events to 2.
1178 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001179 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001180" call Decho("(netrw#Explore) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001181 if @* != keepregstar | sil! let @* = keepregstar | endif
1182 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001183 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001184 sil! let @/ = keepregslash
1185" call Dret("netrw#Explore : @/<".@/.">")
1186endfun
1187
1188" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001189" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001190" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1191" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1192" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1193" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1194" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001196" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001197 let curwin= winnr()
1198
Bram Moolenaara6878372014-03-22 21:02:50 +01001199 if a:0 > 0 && a:1 != ""
1200 " if a netrw window is already on the left-side of the tab
1201 " and a directory has been specified, explore with that
1202 " directory.
Bram Moolenaar85850f32019-07-19 22:05:51 +02001203" call Decho("case has input argument(s) (a:1<".a:1.">)")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001204 let a1 = expand(a:1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001205" call Decho("a:1<".a:1."> curwin#".curwin,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001206 exe "1wincmd w"
1207 if &ft == "netrw"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001208" call Decho("exe Explore ".fnameescape(a:1),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001209 exe "Explore ".fnameescape(a1)
1210 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001211 let s:lexplore_win= curwin
1212 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001213 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001214" call Decho("forgetting t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001215 unlet t:netrw_lexposn
1216 endif
1217" call Dret("netrw#Lexplore")
1218 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001219 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220 exe curwin."wincmd w"
1221 else
1222 let a1= ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001223" call Decho("no input arguments")
Bram Moolenaara6878372014-03-22 21:02:50 +01001224 endif
1225
Bram Moolenaar8d043172014-01-23 14:24:41 +01001226 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001227 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001228 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001229" call Decho("lexwinnr= bufwinnr(t:netrw_lexbufnr#".t:netrw_lexbufnr.")=".lexwinnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001230 else
1231 let lexwinnr= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001232" call Decho("t:netrw_lexbufnr doesn't exist")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001233 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001234" call Decho("lexwinnr=".lexwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001235
1236 if lexwinnr > 0
1237 " close down netrw explorer window
Bram Moolenaar85850f32019-07-19 22:05:51 +02001238" call Decho("t:netrw_lexbufnr#".t:netrw_lexbufnr.": close down netrw window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001239 exe lexwinnr."wincmd w"
1240 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001241 let t:netrw_lexposn = winsaveview()
1242" call Decho("saving posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001243" call Decho("saving t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001244 close
1245 if lexwinnr < curwin
1246 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001247 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001248 if lexwinnr != curwin
1249 exe curwin."wincmd w"
1250 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001251 unlet t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02001252" call Decho("unlet t:netrw_lexbufnr")
Bram Moolenaar8d043172014-01-23 14:24:41 +01001253
1254 else
1255 " open netrw explorer window
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001256" call Decho("t:netrw_lexbufnr<n/a>: open netrw explorer window",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01001257 exe "1wincmd w"
1258 let keep_altv = g:netrw_altv
1259 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001260 if a:count != 0
1261 let netrw_winsize = g:netrw_winsize
1262 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001263 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001264 let curfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001265" call Decho("curfile<".curfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001266 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 +02001267" call Decho("new buf#".bufnr("%")." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001268 if a:0 > 0 && a1 != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001269" call Decho("case 1: Explore ".a1,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001270 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001271 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001272 elseif curfile =~ '^\a\{3,}://'
1273" call Decho("case 2: Explore ".substitute(curfile,'[^/\\]*$','',''),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001274 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001275 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001276" call Decho("case 3: Explore .",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001277 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001278 endif
1279 if a:count != 0
1280 let g:netrw_winsize = netrw_winsize
1281 endif
1282 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001283 let g:netrw_altv = keep_altv
1284 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001285 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1286 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001287 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001288 set bh=wipe
Bram Moolenaar85850f32019-07-19 22:05:51 +02001289" call Decho("let t:netrw_lexbufnr=".t:netrw_lexbufnr)
1290" call Decho("t:netrw_lexposn".(exists("t:netrw_lexposn")? string(t:netrw_lexposn) : " n/a"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001291 if exists("t:netrw_lexposn")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001292" call Decho("restoring to t:netrw_lexposn",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001293" call Decho("restoring posn to t:netrw_lexposn<".string(t:netrw_lexposn).">",'~'.expand("<slnum>"))
1294 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001295 unlet t:netrw_lexposn
1296 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001297 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001298
1299 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001300 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001301 if a:rightside
1302 let g:netrw_chgwin= 1
1303 else
1304 let g:netrw_chgwin= 2
1305 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001306" call Decho("let g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaara6878372014-03-22 21:02:50 +01001307 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001308
Bram Moolenaar8d043172014-01-23 14:24:41 +01001309" call Dret("netrw#Lexplore")
1310endfun
1311
1312" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001313" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001314" supports :NetrwClean -- remove netrw from first directory on runtimepath
1315" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001316fun! netrw#Clean(sys)
1317" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001318
1319 if a:sys
1320 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1321 else
1322 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1323 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001324" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001325 let diddel= 0
1326 let diddir= ""
1327
1328 if choice == 1
1329 for dir in split(&rtp,',')
1330 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001331" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001332 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1333 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1334 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1335 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1336 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1337 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 +00001338 let diddir= dir
1339 let diddel= diddel + 1
1340 if !a:sys|break|endif
1341 endif
1342 endfor
1343 endif
1344
1345 echohl WarningMsg
1346 if diddel == 0
1347 echomsg "netrw is either not installed or not removable"
1348 elseif diddel == 1
1349 echomsg "removed one copy of netrw from <".diddir.">"
1350 else
1351 echomsg "removed ".diddel." copies of netrw"
1352 endif
1353 echohl None
1354
Bram Moolenaara6878372014-03-22 21:02:50 +01001355" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001356endfun
1357
Bram Moolenaar5c736222010-01-06 20:54:52 +01001358" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001359" netrw#MakeTgt: make a target out of the directory name provided {{{2
1360fun! netrw#MakeTgt(dname)
1361" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1362 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001363 let svpos = winsaveview()
1364" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001365 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1366" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001367 if s:netrwmftgt_islocal
1368 let netrwmftgt= simplify(a:dname)
1369 else
1370 let netrwmftgt= a:dname
1371 endif
1372 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1373 " re-selected target, so just clear it
1374 unlet s:netrwmftgt s:netrwmftgt_islocal
1375 else
1376 let s:netrwmftgt= netrwmftgt
1377 endif
1378 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001379 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001380 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001381" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1382 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001383" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001384endfun
1385
Bram Moolenaara6878372014-03-22 21:02:50 +01001386" ---------------------------------------------------------------------
1387" netrw#Obtain: {{{2
1388" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001389" islocal=0 obtain from remote source
1390" =1 obtain from local source
1391" fname : a filename or a list of filenames
1392" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001393fun! netrw#Obtain(islocal,fname,...)
1394" 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 +02001395 " NetrwStatusLine support - for obtaining support
1396
1397 if type(a:fname) == 1
1398 let fnamelist= [ a:fname ]
1399 elseif type(a:fname) == 3
1400 let fnamelist= a:fname
1401 else
1402 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 +01001403" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 return
1405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001406" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 if a:0 > 0
1408 let tgtdir= a:1
1409 else
1410 let tgtdir= getcwd()
1411 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001412" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001413
1414 if exists("b:netrw_islocal") && b:netrw_islocal
1415 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1418 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001419 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001420 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001421" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001424 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 if v:shell_error != 0
1426 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 +01001427" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001428 return
1429 endif
1430 endfor
1431 else
1432 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001433" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1434 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1435" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001436 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001437 if v:shell_error != 0
1438 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 +01001439" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001440 return
1441 endif
1442 endif
1443 elseif !exists("b:netrw_curdir")
1444 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1445 else
1446 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1447 endif
1448
1449 else
1450 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001451" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001452 if type(a:fname) == 1
1453 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1454 endif
1455 call s:NetrwMethod(b:netrw_curdir)
1456
1457 if b:netrw_method == 4
1458 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001459" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001460 if exists("g:netrw_port") && g:netrw_port != ""
1461 let useport= " ".g:netrw_scpport." ".g:netrw_port
1462 else
1463 let useport= ""
1464 endif
1465 if b:netrw_fname =~ '/'
1466 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1467 else
1468 let path= ""
1469 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001470 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001471 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 +02001472
1473 elseif b:netrw_method == 2
1474 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001475" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001476 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001477 let tmpbufnr= bufnr("%")
1478 setl ff=unix
1479 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001480 NetrwKeepj put =g:netrw_ftpmode
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
1484 if exists("b:netrw_fname") && b:netrw_fname != ""
1485 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001486" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001487 endif
1488
1489 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001490 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001492 endif
1493 for fname in fnamelist
1494 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001495" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001496 endfor
1497 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001498 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 +02001499 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001500 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001501 endif
1502 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1503 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1504 let debugkeep= &debug
1505 setl debug=msg
1506 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1507 let &debug= debugkeep
1508 endif
1509
1510 elseif b:netrw_method == 3
1511 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001512" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001513 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001514 let tmpbufnr= bufnr("%")
1515 setl ff=unix
1516
1517 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001518 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001519" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001520 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001521 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001522" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001523 endif
1524
1525 if exists("g:netrw_uid") && g:netrw_uid != ""
1526 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001527 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001528" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001529 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001530 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001531 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001532" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001533 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001534 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001535" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001536 endif
1537 endif
1538
1539 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001540 NetrwKeepj put =g:netrw_ftpmode
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("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001545 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
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
1549 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001550 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001551" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001552 endif
1553
1554 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001555 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001556" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001557 endif
1558 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001559 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001560 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001561" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001562
1563 " perform ftp:
1564 " -i : turns off interactive prompting from ftp
1565 " -n unix : DON'T use <.netrc>, even though it exists
1566 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001567 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1568 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001569 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001570 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1571 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001572" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001573 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001574 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001575 endif
1576 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001577
1578 elseif b:netrw_method == 9
1579 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001580" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001581 if a:fname =~ '/'
1582 let localfile= substitute(a:fname,'^.*/','','')
1583 else
1584 let localfile= a:fname
1585 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001586 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 +02001587
Bram Moolenaarff034192013-04-24 18:51:19 +02001588 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001589 " probably a badly formed url; protocol not recognized
1590" call Dret("netrw#Obtain : unsupported method")
1591 return
1592
1593 else
1594 " protocol recognized but not supported for Obtain (yet?)
1595 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001596 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001597 endif
1598" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001599 return
1600 endif
1601
1602 " restore status line
1603 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001604 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001605 endif
1606
1607 endif
1608
1609 " cleanup
1610 if exists("tmpbufnr")
1611 if bufnr("%") != tmpbufnr
1612 exe tmpbufnr."bw!"
1613 else
1614 q!
1615 endif
1616 endif
1617
Bram Moolenaara6878372014-03-22 21:02:50 +01001618" call Dret("netrw#Obtain")
1619endfun
1620
1621" ---------------------------------------------------------------------
1622" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1623fun! netrw#Nread(mode,fname)
1624" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001625 let svpos= winsaveview()
1626" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001627 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001628" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1629 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001630
1631 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1632 if exists("w:netrw_bannercnt")
1633 " start with cursor just after the banner
1634 exe w:netrw_bannercnt
1635 endif
1636 endif
1637" call Dret("netrw#Nread")
1638endfun
1639
1640" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001641" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1642" Options get restored by s:NetrwOptionsRestore()
1643"
1644" Option handling:
1645" * save user's options (s:NetrwOptionsSave)
1646" * set netrw-safe options (s:NetrwOptionsSafe)
1647" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1648" * restore user's options (s:netrwOPtionsRestore)
1649" - restore a user option when != safe option (s:NetrwRestoreSetting)
1650" vt: (variable type) normally its either "w:" or "s:"
1651fun! s:NetrwOptionsSave(vt)
1652" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1653" 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 +02001654" 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>"))
1655" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001656
1657 if !exists("{a:vt}netrw_optionsave")
1658 let {a:vt}netrw_optionsave= 1
1659 else
1660" call Dret("s:NetrwOptionsSave : options already saved")
1661 return
1662 endif
1663" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1664
1665 " Save current settings and current directory
1666" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1667 let s:yykeep = @@
1668 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1669 let {a:vt}netrw_aikeep = &l:ai
1670 let {a:vt}netrw_awkeep = &l:aw
1671 let {a:vt}netrw_bhkeep = &l:bh
1672 let {a:vt}netrw_blkeep = &l:bl
1673 let {a:vt}netrw_btkeep = &l:bt
1674 let {a:vt}netrw_bombkeep = &l:bomb
1675 let {a:vt}netrw_cedit = &cedit
1676 let {a:vt}netrw_cikeep = &l:ci
1677 let {a:vt}netrw_cinkeep = &l:cin
1678 let {a:vt}netrw_cinokeep = &l:cino
1679 let {a:vt}netrw_comkeep = &l:com
1680 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001681 let {a:vt}netrw_cuckeep = &l:cuc
1682 let {a:vt}netrw_culkeep = &l:cul
1683" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001684 let {a:vt}netrw_diffkeep = &l:diff
1685 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001686 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1687 let {a:vt}netrw_ffkeep = &l:ff
1688 endif
1689 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1690 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001691 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001692 let {a:vt}netrw_hidkeep = &l:hidden
1693 let {a:vt}netrw_imkeep = &l:im
1694 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001695 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001696 let {a:vt}netrw_lskeep = &l:ls
1697 let {a:vt}netrw_makeep = &l:ma
1698 let {a:vt}netrw_magickeep = &l:magic
1699 let {a:vt}netrw_modkeep = &l:mod
1700 let {a:vt}netrw_nukeep = &l:nu
1701 let {a:vt}netrw_rnukeep = &l:rnu
1702 let {a:vt}netrw_repkeep = &l:report
1703 let {a:vt}netrw_rokeep = &l:ro
1704 let {a:vt}netrw_selkeep = &l:sel
1705 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001706 if !g:netrw_use_noswf
1707 let {a:vt}netrw_swfkeep = &l:swf
1708 endif
1709 let {a:vt}netrw_tskeep = &l:ts
1710 let {a:vt}netrw_twkeep = &l:tw " textwidth
1711 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1712 let {a:vt}netrw_wrapkeep = &l:wrap
1713 let {a:vt}netrw_writekeep = &l:write
1714
1715 " save a few selected netrw-related variables
1716" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1717 if g:netrw_keepdir
1718 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001719" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001721 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001722 sil! let {a:vt}netrw_starkeep = @*
1723 sil! let {a:vt}netrw_pluskeep = @+
1724 endif
1725 sil! let {a:vt}netrw_slashkeep= @/
1726
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001727" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001728" 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>"))
1729" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1730endfun
1731
1732" ---------------------------------------------------------------------
1733" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1734" Use s:NetrwSaveOptions() to save user settings
1735" Use s:NetrwOptionsRestore() to restore user settings
1736fun! s:NetrwOptionsSafe(islocal)
1737" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1738" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1739" 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>"))
1740 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1741 call s:NetrwSetSafeSetting("&l:ai",0)
1742 call s:NetrwSetSafeSetting("&l:aw",0)
1743 call s:NetrwSetSafeSetting("&l:bl",0)
1744 call s:NetrwSetSafeSetting("&l:bomb",0)
1745 if a:islocal
1746 call s:NetrwSetSafeSetting("&l:bt","nofile")
1747 else
1748 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1749 endif
1750 call s:NetrwSetSafeSetting("&l:ci",0)
1751 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001752 if g:netrw_fastbrowse > a:islocal
1753 call s:NetrwSetSafeSetting("&l:bh","hide")
1754 else
1755 call s:NetrwSetSafeSetting("&l:bh","delete")
1756 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001757 call s:NetrwSetSafeSetting("&l:cino","")
1758 call s:NetrwSetSafeSetting("&l:com","")
1759 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1760 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1761 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001762 if &go =~ 'a' | set go-=a | endif
1763 if &go =~ 'A' | set go-=A | endif
1764 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001765 call s:NetrwSetSafeSetting("&l:hid",0)
1766 call s:NetrwSetSafeSetting("&l:im",0)
1767 setl isk+=@ isk+=* isk+=/
1768 call s:NetrwSetSafeSetting("&l:magic",1)
1769 if g:netrw_use_noswf
1770 call s:NetrwSetSafeSetting("swf",0)
1771 endif
1772 call s:NetrwSetSafeSetting("&l:report",10000)
1773 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1774 call s:NetrwSetSafeSetting("&l:spell",0)
1775 call s:NetrwSetSafeSetting("&l:tw",0)
1776 call s:NetrwSetSafeSetting("&l:wig","")
1777 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001778
1779 " set up cuc and cul based on g:netrw_cursor and listing style
1780 " COMBAK -- cuc cul related
1781 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001782
1783 " allow the user to override safe options
1784" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1785 if &ft == "netrw"
1786" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1787 keepalt NetrwKeepj doau FileType netrw
1788 endif
1789
1790" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1791" 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>"))
1792" call Dret("s:NetrwOptionsSafe")
1793endfun
1794
1795" ---------------------------------------------------------------------
1796" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1797fun! s:NetrwOptionsRestore(vt)
1798" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001799" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001800" 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 +01001801 if !exists("{a:vt}netrw_optionsave")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001802" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
Christian Brabandt08d24012024-04-03 22:44:27 +02001803
1804 " filereadable() returns zero for remote files (e.g. scp://localhost//etc/fstab)
1805 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+/'
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001806" call Decho("..doing filetype detect anyway")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001807 filetype detect
1808" 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>"))
1809 else
1810 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001811 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001812" 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 +02001813" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
Bram Moolenaara6878372014-03-22 21:02:50 +01001814 return
1815 endif
1816 unlet {a:vt}netrw_optionsave
1817
1818 if exists("+acd")
1819 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001820" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001821 let curdir = getcwd()
1822 let &l:acd = {a:vt}netrw_acdkeep
1823 unlet {a:vt}netrw_acdkeep
1824 if &l:acd
1825 call s:NetrwLcd(curdir)
1826 endif
1827 endif
1828 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001829" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001830 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1831 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1832 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1833 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1834 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001835" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001836 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1837 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1838 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1839 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1840 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001841" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001842 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1843 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1844 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1845 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1846 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001847 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001848" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
1849 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1850 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001851 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001852 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
1853" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
1854 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1855 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
1856" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
1857 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
1858" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
1859 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1860 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001861 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001862 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1863 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
1864" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
1865 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1866 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1867 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1868 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
1869" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001870 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001871 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1872 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1873 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001874 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001875" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001876 call s:NetrwRestoreSetting("s:yykeep","@@")
1877 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1878 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1879 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1880 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1881
Bram Moolenaara6878372014-03-22 21:02:50 +01001882 if exists("{a:vt}netrw_swfkeep")
1883 if &directory == ""
1884 " user hasn't specified a swapfile directory;
1885 " netrw will temporarily set the swapfile directory
1886 " to the current directory as returned by getcwd().
1887 let &l:directory= getcwd()
1888 sil! let &l:swf = {a:vt}netrw_swfkeep
1889 setl directory=
1890 unlet {a:vt}netrw_swfkeep
1891 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001892 if !g:netrw_use_noswf
1893 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1894 sil! let &l:swf= {a:vt}netrw_swfkeep
1895 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001896 unlet {a:vt}netrw_swfkeep
1897 endif
1898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001899 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001900 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1901 if exists("{a:vt}netrw_dirkeep")
1902 call s:NetrwLcd(dirkeep)
1903 unlet {a:vt}netrw_dirkeep
1904 endif
1905 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001906 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001907" call Decho("has clipboard",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001908 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1909 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001910 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001911 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001912
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001913" call Decho("g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
1914" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist"),'~'.expand("<slnum>"))
1915" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
1916" call Decho("diff=".&l:diff." win#".winnr()." w:netrw_diffkeep=".(exists("w:netrw_diffkeep")? w:netrw_diffkeep : "doesn't exist"),'~'.expand("<slnum>"))
1917" call Decho("ts=".&l:ts,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001918 " Moved the filetype detect here from NetrwGetFile() because remote files
1919 " were having their filetype detect-generated settings overwritten by
1920 " NetrwOptionRestore.
1921 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001922" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
1923 filetype detect
1924" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001925 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001926" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001927" 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 +02001928" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
Bram Moolenaara6878372014-03-22 21:02:50 +01001929endfun
1930
1931" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001932" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1933" but only when the options' value and the safe setting differ
1934" Doing this means that netrw will not come up as having changed a
1935" setting last when it really didn't actually change it.
1936"
1937" Called from s:NetrwOptionsSafe
1938" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1939fun! s:NetrwSetSafeSetting(setting,safesetting)
1940" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001941
Bram Moolenaar85850f32019-07-19 22:05:51 +02001942 if a:setting =~ '^&'
1943" call Decho("fyi: a:setting starts with &")
1944 exe "let settingval= ".a:setting
1945" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001946
Bram Moolenaar85850f32019-07-19 22:05:51 +02001947 if settingval != a:safesetting
1948" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1949 if type(a:safesetting) == 0
1950 exe "let ".a:setting."=".a:safesetting
1951 elseif type(a:safesetting) == 1
1952 exe "let ".a:setting."= '".a:safesetting."'"
1953 else
1954 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1955 endif
1956 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001957 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001958
Bram Moolenaar85850f32019-07-19 22:05:51 +02001959" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001960endfun
1961
1962" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001963" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1964" but only if the setting value differs from the associated keepvar.
1965" Doing this means that netrw will not come up as having changed a
1966" setting last when it really didn't actually change it.
1967"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001968" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001969" keepvars are set up by s:NetrwOptionsSave
1970fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001971""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001972
Bram Moolenaar85850f32019-07-19 22:05:51 +02001973 " typically called from s:NetrwOptionsRestore
1974 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1975 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001976 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001977 if exists(a:keepvar)
1978 exe "let keepvarval= ".a:keepvar
1979 exe "let setting= ".a:setting
1980
1981"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1982"" call Decho("fyi: keepvarval=".keepvarval)
1983"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1984
1985 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001986"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001987 if type(a:setting) == 0
1988 exe "let ".a:setting."= ".keepvarval
1989 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001990 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001991 else
1992 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1993 endif
1994 endif
1995
1996 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001997 endif
1998
Bram Moolenaar85850f32019-07-19 22:05:51 +02001999"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02002000endfun
2001
2002" ---------------------------------------------------------------------
2003" NetrwStatusLine: {{{2
2004fun! NetrwStatusLine()
2005
2006" vvv NetrwStatusLine() debugging vvv
2007" let g:stlmsg=""
2008" if !exists("w:netrw_explore_bufnr")
2009" let g:stlmsg="!X<explore_bufnr>"
2010" elseif w:netrw_explore_bufnr != bufnr("%")
2011" let g:stlmsg="explore_bufnr!=".bufnr("%")
2012" endif
2013" if !exists("w:netrw_explore_line")
2014" let g:stlmsg=" !X<explore_line>"
2015" elseif w:netrw_explore_line != line(".")
2016" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
2017" endif
2018" if !exists("w:netrw_explore_list")
2019" let g:stlmsg=" !X<explore_list>"
2020" endif
2021" ^^^ NetrwStatusLine() debugging ^^^
2022
2023 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")
2024 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09002025 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02002026 let &laststatus = s:netrw_users_ls
2027 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
2028 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
2029 return ""
2030 else
2031 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
2032 endif
2033endfun
2034
Bram Moolenaar85850f32019-07-19 22:05:51 +02002035" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002036" Netrw Transfer Functions: {{{1
2037" ===============================
2038
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002040" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002041" mode: =0 read remote file and insert before current line
2042" =1 read remote file and insert after current line
2043" =2 replace with remote file
2044" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002045fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02002046" 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 +00002047
Bram Moolenaar5c736222010-01-06 20:54:52 +01002048 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02002049 call s:NetrwOptionsSave("w:")
2050 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02002051 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002052 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
2053 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
2054 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02002055" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002056
Bram Moolenaar5c736222010-01-06 20:54:52 +01002057 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002058 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002059 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002060 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002061 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002062 elseif a:mode == 2 " replace with remote file
2063 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00002064 elseif a:mode == 3 " skip read of file (leave as temporary)
2065 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002066 else
2067 exe a:mode
2068 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002069 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002070 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002071" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaar5c736222010-01-06 20:54:52 +01002073 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002074 let tmpfile= s:GetTempfile("")
2075 if tmpfile == ""
2076" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002077 return
2078 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002079
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002080 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002081
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002082 " attempt to repeat with previous host-file-etc
2083 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002084" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002085 let choice = b:netrw_lastfile
2086 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002087
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002088 else
2089 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002090" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002091
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002092 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002093 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002094 echomsg 'NetRead Usage:'
2095 echomsg ':Nread machine:path uses rcp'
2096 echomsg ':Nread "machine path" uses ftp with <.netrc>'
2097 echomsg ':Nread "machine id password path" uses ftp'
2098 echomsg ':Nread dav://machine[:port]/path uses cadaver'
2099 echomsg ':Nread fetch://machine/path uses fetch'
2100 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
2101 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002102 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01002103 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002104 echomsg ':Nread rcp://[user@]machine/path uses rcp'
2105 echomsg ':Nread rsync://machine[:port]/path uses rsync'
2106 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
2107 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002108 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002110
Bram Moolenaar9964e462007-05-05 17:54:07 +00002111 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00002112 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002113" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002114 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002115 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02002116 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 else
2118 " case "... ... ..."
2119 let choice = strpart(choice,1,strlen(choice)-1)
2120 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002121
Bram Moolenaar9964e462007-05-05 17:54:07 +00002122 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 let wholechoice = wholechoice . " " . choice
2124 let ichoice = ichoice + 1
2125 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002126 if !exists("g:netrw_quiet")
2127 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2128 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002129" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002130 return
2131 endif
2132 let choice= a:{ichoice}
2133 endwhile
2134 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2135 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136 endif
2137 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002138
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002139" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002141
Bram Moolenaar5c736222010-01-06 20:54:52 +01002142 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002143 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002144 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002145" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002146 return
2147 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002148 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002149
Bram Moolenaar8d043172014-01-23 14:24:41 +01002150 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151" 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 +02002152 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002153" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002154 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002155" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002156 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002157 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002158
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002160 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002161 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002162 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2163 echo "(netrw) Processing your read request..."
2164 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002165
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002166 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002167 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002169" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002170 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002171 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002172 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002173 " ER: the tmpfile is full path: rcp sees C:\... as host C
2174 if s:netrw_has_nt_rcp == 1
2175 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2176 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2177 else
2178 " Any way needed it machine contains a '.'
2179 let uid_machine = g:netrw_machine .'.'. $USERNAME
2180 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002181 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002182 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2183 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2184 else
2185 let uid_machine = g:netrw_machine
2186 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002188 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 +00002189 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002191
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002193 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002196 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002197 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002198 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002199 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002200 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002201" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002202 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002203 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002205 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002206 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002207" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002208 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002209 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 +00002210 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002211 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 endif
2213 " 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 +00002214 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002215 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002216 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002217 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002218 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002219 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002220 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002221 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002222 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2223 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002224 q!
2225 endif
2226 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002227 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002229
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002230 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002231 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002232 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2233 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002234" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002235 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002236 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002237 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002238 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002239 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002240 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002241" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002242 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002244" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002245 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002246
Bram Moolenaar97d62492012-11-15 21:28:22 +01002247 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002248 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002249 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002250" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002251 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002252 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002253 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002254" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002255 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002256 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002257" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002258 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002259 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002260
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002261 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002262 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002265 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002266 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002268 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002269 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002270" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002271
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 " perform ftp:
2273 " -i : turns off interactive prompting from ftp
2274 " -n unix : DON'T use <.netrc>, even though it exists
2275 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002276 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002277 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002278 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2279 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002280" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002281 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002282 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002283 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002284 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002285 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002286 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002287 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002288
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002289 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002290 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002291 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002292" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002294 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002295 else
2296 let useport= ""
2297 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002298 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2299 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002300 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002301 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2302 else
2303 let tmpfile_get = tmpfile
2304 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002305 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 +00002306 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002307 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002308
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002309 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002310 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002311 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002312" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002313 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002314 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002315 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002316 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002317" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002318 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002319 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002320
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002321 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2322 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002323" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002324 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002325 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 +00002326 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327 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 +00002328 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002329 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002330
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002331 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002332 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002334 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2335 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002336" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2337" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2338 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 +00002339 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002340" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002341 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002342 endif
2343 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002344" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002345 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002346
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002347 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002348 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002349 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002350" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002351
Bram Moolenaar5c736222010-01-06 20:54:52 +01002352 if !executable(g:netrw_dav_cmd)
2353 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2354" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2355 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002356 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002357 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002358 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 +01002359 else
2360 " Construct execution string (four lines) which will be passed through filter
2361 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2362 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002363 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002364 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002365 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002366 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002367 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002368 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002369 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002371 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002372 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2373 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002374
Bram Moolenaar5c736222010-01-06 20:54:52 +01002375 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002376 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002377 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002378 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002379 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002380 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002382
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002383 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002384 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002385 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002386" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002387 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 +00002388 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002389 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002390
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002391 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002392 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002394 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002395" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002396 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002397 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002398 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002399 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002400" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002401 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002402 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002403 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002404 let netrw_option= "http"
2405 else
2406 let netrw_option= "ftp"
2407 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002408" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002409
Bram Moolenaar446cb832008-06-24 21:56:24 +00002410 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002411 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 +00002412 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002413 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 +00002414 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002415
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 Moolenaara0f849e2015-10-30 14:37:44 +01002418" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002419 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002420
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002421 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002422 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002423 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002424" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2425 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 +00002426 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002427 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002428
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002429 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002430 " NetRead: (file) NetRead Method #10 {{{3
2431 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002432" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2433 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002434 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2435 let b:netrw_lastfile = choice
2436
2437 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002438 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002439 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002440 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002441 endif
2442 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002443
Bram Moolenaar5c736222010-01-06 20:54:52 +01002444 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002445 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002446" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002447 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002448 unlet b:netrw_fname
2449 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002450 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 +01002451" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002452 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002453 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002454 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002455
Bram Moolenaar9964e462007-05-05 17:54:07 +00002456" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002457endfun
2458
2459" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002460" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002461fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002462" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002463
Bram Moolenaar5c736222010-01-06 20:54:52 +01002464 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002465 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002466 call s:NetrwOptionsSave("w:")
2467 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002468
Bram Moolenaar5c736222010-01-06 20:54:52 +01002469 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002470 let tmpfile= s:GetTempfile("")
2471 if tmpfile == ""
2472" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002473 return
2474 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002475
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002476 if a:0 == 0
2477 let ichoice = 0
2478 else
2479 let ichoice = 1
2480 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002481
Bram Moolenaar9964e462007-05-05 17:54:07 +00002482 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002483" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002484 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002485 " For binary writes, always write entire file.
2486 " (line numbers don't really make sense for that).
2487 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002488" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002489 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002490 elseif g:netrw_cygwin
2491 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002492 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002493" 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 +01002494 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002495 else
2496 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002497" 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 +01002498 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002499 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002500
Bram Moolenaar9964e462007-05-05 17:54:07 +00002501 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002502 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002503 " on the temporary file's name. Deletion of the temporary file during
2504 " cleanup then causes an error message.
2505 0file!
2506 endif
2507
Bram Moolenaar5c736222010-01-06 20:54:52 +01002508 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002509 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002510
Bram Moolenaar9964e462007-05-05 17:54:07 +00002511 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002512 " attempt to repeat with previous host-file-etc
2513 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002514" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002515 let choice = b:netrw_lastfile
2516 let ichoice= ichoice + 1
2517 else
2518 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002519
Bram Moolenaar8d043172014-01-23 14:24:41 +01002520 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002521 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002522 echomsg 'NetWrite Usage:"'
2523 echomsg ':Nwrite machine:path uses rcp'
2524 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2525 echomsg ':Nwrite "machine id password path" uses ftp'
2526 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2527 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2528 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2529 echomsg ':Nwrite rcp://machine/path uses rcp'
2530 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2531 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2532 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002533 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002534 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002535
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002536 elseif match(choice,"^\"") != -1
2537 if match(choice,"\"$") != -1
2538 " case "..."
2539 let choice=strpart(choice,1,strlen(choice)-2)
2540 else
2541 " case "... ... ..."
2542 let choice = strpart(choice,1,strlen(choice)-1)
2543 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002544
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002545 while match(choice,"\"$") == -1
2546 let wholechoice= wholechoice . " " . choice
2547 let ichoice = ichoice + 1
2548 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002549 if !exists("g:netrw_quiet")
2550 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2551 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002552" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002553 return
2554 endif
2555 let choice= a:{ichoice}
2556 endwhile
2557 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2558 endif
2559 endif
2560 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002561 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002562" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002563
Bram Moolenaar9964e462007-05-05 17:54:07 +00002564 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002565 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002566 if !exists("b:netrw_method") || b:netrw_method < 0
2567" call Dfunc("netrw#NetWrite : unsupported method")
2568 return
2569 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002570
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002571 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002572 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002573 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002574 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2575 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002576" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002577 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002578
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002579 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002580 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002581 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002582" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002583 if s:netrw_has_nt_rcp == 1
2584 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2585 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2586 else
2587 let uid_machine = g:netrw_machine .'.'. $USERNAME
2588 endif
2589 else
2590 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2591 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2592 else
2593 let uid_machine = g:netrw_machine
2594 endif
2595 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002596 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 +00002597 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002598
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002599 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002600 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002601 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002602" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002603 let netrw_fname = b:netrw_fname
2604
2605 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2606 let bhkeep = &l:bh
2607 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002608 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002609 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002610
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002611" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002612 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002613 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002614" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002615 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002616 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002618 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002619 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002620" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002622 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 +00002623 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002624" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2625 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 endif
2627 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2628 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002629 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002630 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002631 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002632 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002634
2635 " remove enew buffer (quietly)
2636 let filtbuf= bufnr("%")
2637 exe curbuf."b!"
2638 let &l:bh = bhkeep
2639 exe filtbuf."bw!"
2640
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002642
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002643 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002644 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002645 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002646 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002647" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002648 let netrw_fname = b:netrw_fname
2649 let bhkeep = &l:bh
2650
2651 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2652 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002653 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002654 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002655 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002656
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002658 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002659" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002660 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002661 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002662" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002663 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002664 if exists("g:netrw_uid") && g:netrw_uid != ""
2665 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002666 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002667" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002668 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002669 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002670 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002672 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002673 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002674" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002675 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002676 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002677 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002679 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002680 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002681" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002682 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002683 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002684" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 " save choice/id/password for future use
2686 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002687
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002688 " perform ftp:
2689 " -i : turns off interactive prompting from ftp
2690 " -n unix : DON'T use <.netrc>, even though it exists
2691 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002692 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002693 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002694 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2695 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002696 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002697 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002698 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002699 let mod=1
2700 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002701
2702 " remove enew buffer (quietly)
2703 let filtbuf= bufnr("%")
2704 exe curbuf."b!"
2705 let &l:bh= bhkeep
2706 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002707
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002708 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002709 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002710 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002711" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002712 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002713 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002714 else
2715 let useport= ""
2716 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002717 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 +00002718 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002719
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002720 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002721 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002722 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002723" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002724 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2725 if executable(curl)
2726 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002727 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 +01002728 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002729 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002730 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002731
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002732 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002733 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002734 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002735" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002736
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002737 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002738 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2739 let bhkeep = &l:bh
2740
2741 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2742 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002743 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002744 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002745
Bram Moolenaarff034192013-04-24 18:51:19 +02002746 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002747 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002748 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002749 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002750 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002751 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002752 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002753 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002754 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002755 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002756
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002757 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002758 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002759 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002760
2761 " remove enew buffer (quietly)
2762 let filtbuf= bufnr("%")
2763 exe curbuf."b!"
2764 let &l:bh = bhkeep
2765 exe filtbuf."bw!"
2766
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002767 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002768
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002769 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002770 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002771 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002772" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002773 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 +00002774 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002775
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002776 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002777 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002778 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002780 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2782 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2783 else
2784 let uid_machine = g:netrw_machine
2785 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002786
2787 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2788 let bhkeep = &l:bh
2789 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002790 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002791 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002792
Bram Moolenaarff034192013-04-24 18:51:19 +02002793 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002794 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002795" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002796 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002797 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002798 let filtbuf= bufnr("%")
2799 exe curbuf."b!"
2800 let &l:bh = bhkeep
2801 exe filtbuf."bw!"
2802 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002803
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002804 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002805 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002806 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002807 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002808 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002810 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002811
Bram Moolenaar5c736222010-01-06 20:54:52 +01002812 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002816 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002817 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002818 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002819
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002820 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002821 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002822 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002823" 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 +02002824 elseif !exists("leavemod")
2825 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002826" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002827 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002828" 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 +00002829 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002830
Bram Moolenaar9964e462007-05-05 17:54:07 +00002831" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002832endfun
2833
2834" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002835" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002836" uses NetRead to get a copy of the file into a temporarily file,
2837" then sources that file,
2838" then removes that file.
2839fun! netrw#NetSource(...)
2840" call Dfunc("netrw#NetSource() a:0=".a:0)
2841 if a:0 > 0 && a:1 == '?'
2842 " give help
2843 echomsg 'NetSource Usage:'
2844 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2845 echomsg ':Nsource fetch://machine/path uses fetch'
2846 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002847 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002848 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2849 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2850 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2851 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2852 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002853 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002854 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002855 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002856 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002858 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002859" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002860 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002862 if delete(s:netrw_tmpfile)
2863 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2864 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002865 unlet s:netrw_tmpfile
2866 else
2867 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2868 endif
2869 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002870 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002871 endif
2872" call Dret("netrw#NetSource")
2873endfun
2874
Bram Moolenaar8d043172014-01-23 14:24:41 +01002875" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002876" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2877" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002878fun! netrw#SetTreetop(iscmd,...)
2879" call Dfunc("netrw#SetTreetop(iscmd=".a:iscmd." ".((a:0 > 0)? a:1 : "").") a:0=".a:0)
2880" call Decho("w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002881
Bram Moolenaar85850f32019-07-19 22:05:51 +02002882 " iscmd==0: netrw#SetTreetop called using gn mapping
2883 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
2884" call Decho("(iscmd=".a:iscmd.": called using :Ntree from command line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 " clear out the current tree
2886 if exists("w:netrw_treetop")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" call Decho("clearing out current tree",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002888 let inittreetop= w:netrw_treetop
2889 unlet w:netrw_treetop
2890 endif
2891 if exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892" call Decho("freeing w:netrw_treedict",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002893 unlet w:netrw_treedict
2894 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002895" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
Bram Moolenaara6878372014-03-22 21:02:50 +01002896
Bram Moolenaar85850f32019-07-19 22:05:51 +02002897 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002898 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002899" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002900 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901 if isdirectory(s:NetrwFile(a:1))
2902" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002903 let treedir = a:1
2904 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002905 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002906 let treedir = b:netrw_curdir."/".a:1
2907 let s:netrw_treetop = treedir
Bram Moolenaar85850f32019-07-19 22:05:51 +02002908" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002909 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002910 " normally the cursor is left in the message window.
2911 " However, here this results in the directory being listed in the message window, which is not wanted.
2912 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002913 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002914 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002915 let treedir = "."
2916 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002917 endif
2918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002919" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002920
2921 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002922 let islocal= expand("%") !~ '^\a\{3,}://'
2923" call Decho("islocal=".islocal,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002924
2925 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002926 if islocal
2927 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir))
2928 else
2929 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir))
2930 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002931
Bram Moolenaara6878372014-03-22 21:02:50 +01002932" call Dret("netrw#SetTreetop")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002933endfun
2934
Bram Moolenaar9964e462007-05-05 17:54:07 +00002935" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002936" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002937" readcmd == %r : replace buffer with newly read file
2938" == 0r : read file at top of buffer
2939" == r : read file after current line
2940" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002941fun! s:NetrwGetFile(readcmd, tfile, method)
2942" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002943
2944 " readcmd=='t': simply do nothing
2945 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002946" 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 +01002947" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002948 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002949 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002950
Bram Moolenaar9964e462007-05-05 17:54:07 +00002951 " get name of remote filename (ie. url and all)
2952 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002953" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002954
Bram Moolenaar9964e462007-05-05 17:54:07 +00002955 if exists("*NetReadFixup")
2956 " for the use of NetReadFixup (not otherwise used internally)
2957 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002958 endif
2959
Bram Moolenaar9964e462007-05-05 17:54:07 +00002960 if a:readcmd[0] == '%'
2961 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002962" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002963
2964 " rename the current buffer to the temp file (ie. tfile)
2965 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002966 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002967 else
2968 let tfile= a:tfile
2969 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002970 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002971
2972 " edit temporary file (ie. read the temporary file in)
2973 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002974" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002975 call zip#Browse(tfile)
2976 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002977" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002978 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002979 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002980" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002981 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002982 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002983" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002984 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002985 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002986" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002987 call tar#Browse(tfile)
2988 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002989" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002990 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002991 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002992" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002993 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002994 endif
2995
2996 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002997 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002998
Bram Moolenaar71badf92023-04-22 22:40:14 +01002999 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01003000 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003001 " Note that isk must not include a "/" for scripts.vim
3002 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01003003" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
3004" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02003005" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01003006" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
3007 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01003008 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01003009 filetype detect
3010" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09003011 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003012" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003013 let line1 = 1
3014 let line2 = line("$")
3015
Bram Moolenaar8d043172014-01-23 14:24:41 +01003016 elseif !&ma
3017 " 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 +01003018 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003019" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003020 return
3021
Bram Moolenaar9964e462007-05-05 17:54:07 +00003022 elseif s:FileReadable(a:tfile)
3023 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003025 let curline = line(".")
3026 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003027" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003028 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003029 let line1= curline + 1
3030 let line2= line("$") - lastline + 1
3031
3032 else
3033 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003034" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
3035" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003036 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003037" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003038 return
3039 endif
3040
3041 " User-provided (ie. optional) fix-it-up command
3042 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003043" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003044 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00003045" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003046" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003047 endif
3048
Bram Moolenaaradc21822011-04-01 18:03:16 +02003049 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00003050 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003051 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00003052 endif
3053
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003054" 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 +00003055
3056 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00003057" redraw!
3058
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003059" 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 +00003060" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003061endfun
3062
Bram Moolenaar9964e462007-05-05 17:54:07 +00003063" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003064" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003065" Input:
3066" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
3067" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003068" b:netrw_method= 1: rcp
3069" 2: ftp + <.netrc>
3070" 3: ftp + machine, id, password, and [path]filename
3071" 4: scp
3072" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003073" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003074" 7: rsync
3075" 8: fetch
3076" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003077" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01003078" g:netrw_machine= hostname
3079" b:netrw_fname = filename
3080" g:netrw_port = optional port number (for ftp)
3081" g:netrw_choice = copy of input url (choice)
3082fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003083" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003084
Bram Moolenaar251e1912011-06-19 05:09:16 +02003085 " sanity check: choice should have at least three slashes in it
3086 if strlen(substitute(a:choice,'[^/]','','g')) < 3
3087 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
3088 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003089" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02003090 return
3091 endif
3092
Bram Moolenaar5c736222010-01-06 20:54:52 +01003093 " record current g:netrw_machine, if any
3094 " curmachine used if protocol == ftp and no .netrc
3095 if exists("g:netrw_machine")
3096 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003097" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003098 else
3099 let curmachine= "N O T A HOST"
3100 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003101 if exists("g:netrw_port")
3102 let netrw_port= g:netrw_port
3103 endif
3104
3105 " insure that netrw_ftp_cmd starts off every method determination
3106 " with the current g:netrw_ftp_cmd
3107 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01003108
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 " initialization
3110 let b:netrw_method = 0
3111 let g:netrw_machine = ""
3112 let b:netrw_fname = ""
3113 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003114 let g:netrw_choice = a:choice
3115
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003117 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00003118 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
3119 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003120 " rcpurm : rcp://[user@]host/filename Use rcp
3121 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003122 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02003123 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01003124 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003125 " rsyncurm : rsync://host[:port]/path Use rsync
3126 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
3127 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003128 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003129 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
3130 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003131 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3132 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003133 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003134 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003135 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003136 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003137 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003138 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003140 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003141
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003142" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003143 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003144 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003145 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003146" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003147 let b:netrw_method = 1
3148 let userid = substitute(a:choice,rcpurm,'\1',"")
3149 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3150 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003151 if userid != ""
3152 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003154
Bram Moolenaaradc21822011-04-01 18:03:16 +02003155 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003156 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003157" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003158 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003159 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3160 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3161 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003162
Bram Moolenaar15146672011-10-20 22:22:38 +02003163 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003164 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003165" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003166 let b:netrw_method = 5
3167 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3168 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003169 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003170
Bram Moolenaaradc21822011-04-01 18:03:16 +02003171 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003172 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003173" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003175 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003176 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3177 else
3178 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3179 endif
3180 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003181
Bram Moolenaaradc21822011-04-01 18:03:16 +02003182 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003183 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003184" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003185 let b:netrw_method = 7
3186 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3187 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003188
Bram Moolenaaradc21822011-04-01 18:03:16 +02003189 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003190 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003191" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003192 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003193 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3194 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3195 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003196" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003197 if userid != ""
3198 let g:netrw_uid= userid
3199 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003200
Bram Moolenaaradc21822011-04-01 18:03:16 +02003201 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003202 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003203 call NetUserPass("ftp:".g:netrw_machine)
3204 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003205 " if there's a change in hostname, require password re-entry
3206 unlet s:netrw_passwd
3207 endif
3208 if exists("netrw_port")
3209 unlet netrw_port
3210 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003211 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003212
Bram Moolenaar446cb832008-06-24 21:56:24 +00003213 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003214 let b:netrw_method = 3
3215 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003216 let host= substitute(g:netrw_machine,'\..*$','','')
3217 if exists("s:netrw_hup[host]")
3218 call NetUserPass("ftp:".host)
3219
Nir Lichtman1e34b952024-05-08 19:19:34 +02003220 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003221" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3222" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003223 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003224 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003225" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003226 endif
3227 let b:netrw_method= 2
3228 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003229" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003230 let b:netrw_method= 2
3231 else
3232 if !exists("g:netrw_uid") || g:netrw_uid == ""
3233 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003234 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003235 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003236 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003237 endif
3238 let b:netrw_method= 3
3239 endif
3240 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003241
Bram Moolenaaradc21822011-04-01 18:03:16 +02003242 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003243 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003244" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003245 let b:netrw_method = 8
3246 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3247 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3248 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3249 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003250
Bram Moolenaaradc21822011-04-01 18:03:16 +02003251 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003252 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003253" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003255 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3256 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003257 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003258 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003259 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003260
Bram Moolenaaradc21822011-04-01 18:03:16 +02003261 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003262 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003263" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003264 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003265 let b:netrw_method = 3
3266 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3267 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003268
Bram Moolenaar9964e462007-05-05 17:54:07 +00003269 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003270 let b:netrw_method = 2
3271 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3272 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3273 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003274
Bram Moolenaaradc21822011-04-01 18:03:16 +02003275 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003276 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003277" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003278 let b:netrw_method = 9
3279 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3280 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003281
Bram Moolenaaradc21822011-04-01 18:03:16 +02003282 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003283 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003284" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003285 let b:netrw_method = 1
3286 let userid = substitute(a:choice,rcphf,'\2',"")
3287 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3288 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003289" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3290" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3291" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3292" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003293 if userid != ""
3294 let g:netrw_uid= userid
3295 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003296
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003297 " Method#10: file://user@hostname/...path-to-file {{{3
3298 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003299" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003300 let b:netrw_method = 10
3301 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003302" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003303
Bram Moolenaaradc21822011-04-01 18:03:16 +02003304 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003305 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003306 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003307 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003308 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003309 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003311 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003312
Bram Moolenaar81695252004-12-29 20:58:21 +00003313 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003314 " remove any leading [:#] from port number
3315 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3316 elseif exists("netrw_port")
3317 " retain port number as implicit for subsequent ftp operations
3318 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003319 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003320
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003321" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3322" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3323" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3324" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003325" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003326" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003327" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003328" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003329" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003330" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003331" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003332" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003334
Bram Moolenaar9964e462007-05-05 17:54:07 +00003335" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003336" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003337" Usage: :call NetUserPass() -- will prompt for userid and password
3338" :call NetUserPass("uid") -- will prompt for password
3339" :call NetUserPass("uid","password") -- sets global userid and password
3340" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3341" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342fun! NetUserPass(...)
3343
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003344" call Dfunc("NetUserPass() a:0=".a:0)
3345
3346 if !exists('s:netrw_hup')
3347 let s:netrw_hup= {}
3348 endif
3349
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003351 " case: no input arguments
3352
3353 " change host and username if not previously entered; get new password
3354 if !exists("g:netrw_machine")
3355 let g:netrw_machine= input('Enter hostname: ')
3356 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003358 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359 let g:netrw_uid= input('Enter username: ')
3360 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003361 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003362 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003363
3364 " set up hup database
3365 let host = substitute(g:netrw_machine,'\..*$','','')
3366 if !exists('s:netrw_hup[host]')
3367 let s:netrw_hup[host]= {}
3368 endif
3369 let s:netrw_hup[host].uid = g:netrw_uid
3370 let s:netrw_hup[host].passwd = s:netrw_passwd
3371
3372 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003373 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003374
3375 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003376 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003377 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003378" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003379 let host = substitute(a:1,'^ftp:','','')
3380 let host = substitute(host,'\..*','','')
3381 if exists("s:netrw_hup[host]")
3382 let g:netrw_uid = s:netrw_hup[host].uid
3383 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003384" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3385" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003386 else
3387 let g:netrw_uid = input("Enter UserId: ")
3388 let s:netrw_passwd = inputsecret("Enter Password: ")
3389 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003390
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003391 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003392 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003393" 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 +02003394 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003395 if g:netrw_machine =~ '[0-9.]\+'
3396 let host= g:netrw_machine
3397 else
3398 let host= substitute(g:netrw_machine,'\..*$','','')
3399 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003400 else
3401 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003402 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003403 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003404" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003405 if exists("g:netrw_passwd")
3406 " ask for password if one not previously entered
3407 let s:netrw_passwd= g:netrw_passwd
3408 else
3409 let s:netrw_passwd = inputsecret("Enter Password: ")
3410 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003411 endif
3412
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003413" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003414 if exists("host")
3415 if !exists('s:netrw_hup[host]')
3416 let s:netrw_hup[host]= {}
3417 endif
3418 let s:netrw_hup[host].uid = g:netrw_uid
3419 let s:netrw_hup[host].passwd = s:netrw_passwd
3420 endif
3421
3422 elseif a:0 == 2
3423 let g:netrw_uid = a:1
3424 let s:netrw_passwd = a:2
3425
3426 elseif a:0 == 3
3427 " enter hostname, user-id, and password into the hup dictionary
3428 let host = substitute(a:1,'^\a\+:','','')
3429 let host = substitute(host,'\..*$','','')
3430 if !exists('s:netrw_hup[host]')
3431 let s:netrw_hup[host]= {}
3432 endif
3433 let s:netrw_hup[host].uid = a:2
3434 let s:netrw_hup[host].passwd = a:3
3435 let g:netrw_uid = s:netrw_hup[host].uid
3436 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003437" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3438" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003439 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003440
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003441" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443
Bram Moolenaar85850f32019-07-19 22:05:51 +02003444" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003445" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003446" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003447
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003448" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003449" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3450fun! s:ExplorePatHls(pattern)
3451" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3452 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003453" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003454 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003455" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003456 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3457" call Dret("s:ExplorePatHls repat<".repat.">")
3458 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003459endfun
3460
3461" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003462" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003463" 0: (user: <mb>) bookmark current directory
3464" 1: (user: <gb>) change to the bookmarked directory
3465" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003466" 3: (browsing) records current directory history
3467" 4: (user: <u>) go up (previous) directory, using history
3468" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003469" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003470fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003471" 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 +02003472 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3473" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3474 return
3475 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003476
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003477 let ykeep = @@
3478 let curbufnr = bufnr("%")
3479
Bram Moolenaar9964e462007-05-05 17:54:07 +00003480 if a:chg == 0
3481 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003482" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003483 if exists("s:netrwmarkfilelist_{curbufnr}")
3484 call s:NetrwBookmark(0)
3485 echo "bookmarked marked files"
3486 else
3487 call s:MakeBookmark(a:curdir)
3488 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003489 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003490
KSR-Yasudaf4498252023-10-06 03:34:17 +09003491 try
3492 call s:NetrwBookHistSave()
3493 catch
3494 endtry
3495
Bram Moolenaar9964e462007-05-05 17:54:07 +00003496 elseif a:chg == 1
3497 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003498" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003499 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003500" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003501 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003502 else
3503 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3504 endif
3505
3506 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003507" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003508 let didwork= 0
3509 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003510" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003511 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003512" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003513 let cnt= 1
3514 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003515" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003516 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003517 let didwork = 1
3518 let cnt = cnt + 1
3519 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003520 endif
3521
3522 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003523 " Note: history is saved only when PerformListing is done;
3524 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3525 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003526 let first = 1
3527 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003528 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003529 while ( first || cnt != g:netrw_dirhistcnt )
3530" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003531 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003532" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003533 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003534 let didwork= 1
3535 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003536 let histcnt = histcnt + 1
3537 let first = 0
3538 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003539 if cnt < 0
3540 let cnt= cnt + g:netrw_dirhistmax
3541 endif
3542 endwhile
3543 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003544 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003545 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003546 if didwork
3547 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3548 endif
3549
3550 elseif a:chg == 3
3551 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003552" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553 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 +02003554 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3556 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003557 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003558" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003559 endif
3560
3561 elseif a:chg == 4
3562 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003563" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003564 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003565 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3566 if g:netrw_dirhistcnt < 0
3567 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003568 endif
3569 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003570 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003571 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003572 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3573" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003574 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003575 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003576" call Decho("setl ma noro",'~'.expand("<slnum>"))
3577 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003578 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003579" call Decho("setl nomod",'~'.expand("<slnum>"))
3580" 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 +00003581 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003582" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3583 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003584 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003585 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003586 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003587 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003588 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003589 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003590 echo "Sorry, no predecessor directory exists yet"
3591 endif
3592
3593 elseif a:chg == 5
3594 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003595" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003596 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003597 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3598 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3599" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003600 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003601" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003602 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003603 sil! NetrwKeepj %d _
3604" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3605" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003606 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003607" 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 +02003608 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003609" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3610 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003611 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003612 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3613 if g:netrw_dirhistcnt < 0
3614 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003615 endif
3616 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003617 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003618 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003619 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003620 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003621 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003622
3623 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003624" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003625 if exists("s:netrwmarkfilelist_{curbufnr}")
3626 call s:NetrwBookmark(1)
3627 echo "removed marked files from bookmarks"
3628 else
3629 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003630 let iremove = v:count
3631 let dremove = g:netrw_bookmarklist[iremove - 1]
3632" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003633 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003634" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3635 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3636 echo "removed ".dremove." from g:netrw_bookmarklist"
3637" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003638 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003639" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003640
3641 try
3642 call s:NetrwBookHistSave()
3643 catch
3644 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003645 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003646 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003647 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003648 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003649" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003650endfun
3651
3652" ---------------------------------------------------------------------
3653" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003654" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003655" Sister function: s:NetrwBookHistSave()
3656fun! s:NetrwBookHistRead()
3657" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003658 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003659" call Dret("s:NetrwBookHistRead - nothing read (suppressed due to dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a").")")
Bram Moolenaarff034192013-04-24 18:51:19 +02003660 return
3661 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003662 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003663
3664 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003665 if !exists("s:netrw_initbookhist")
3666 let home = s:NetrwHome()
3667 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003668 if filereadable(s:NetrwFile(savefile))
3669" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003670 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003671 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003672
3673 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003674 if g:netrw_dirhistmax > 0
3675 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003676 if filereadable(s:NetrwFile(savefile))
3677" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003678 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003679 endif
3680 let s:netrw_initbookhist= 1
3681 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003682 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003683 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003684
Bram Moolenaar97d62492012-11-15 21:28:22 +01003685 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003686" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3687" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003688" call Dret("s:NetrwBookHistRead")
3689endfun
3690
3691" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003693" Sister function: s:NetrwBookHistRead()
3694" I used to do this via viminfo but that appears to
3695" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003696" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3697" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003699fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003700" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003701 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003702" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003703 return
3704 endif
3705
Bram Moolenaar5c736222010-01-06 20:54:52 +01003706 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003707" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003708 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003709
3710 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003711 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003712" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003713 if g:netrw_use_noswf
3714 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3715 else
3716 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3717 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003718 setl nocin noai noci magic nospell nohid wig= noaw
3719 setl ma noro write
3720 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003721 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003722
Bram Moolenaar85850f32019-07-19 22:05:51 +02003723 " rename enew'd file: .netrwhist -- no attempt to merge
3724 " record dirhistmax and current dirhistcnt
3725 " save history
3726" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003727 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003728 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003729 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3730 if g:netrw_dirhistmax > 0
3731 let lastline = line("$")
3732 let cnt = g:netrw_dirhistcnt
3733 let first = 1
3734 while ( first || cnt != g:netrw_dirhistcnt )
3735 let lastline= lastline + 1
3736 if exists("g:netrw_dirhist_{cnt}")
3737 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3738" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3739 endif
3740 let first = 0
3741 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3742 if cnt < 0
3743 let cnt= cnt + g:netrw_dirhistmax
3744 endif
3745 endwhile
3746 exe "sil! w! ".savefile
3747" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3748 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003749
Bram Moolenaar85850f32019-07-19 22:05:51 +02003750 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003751 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003752 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003753" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003754 " merge and write .netrwbook
3755 let savefile= s:NetrwHome()."/.netrwbook"
3756
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003757 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003758 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003759 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003760 for bdm in booklist
3761 if index(g:netrw_bookmarklist,bdm) == -1
3762 call add(g:netrw_bookmarklist,bdm)
3763 endif
3764 endfor
3765 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003766 endif
3767
3768 " construct and save .netrwbook
3769 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003770 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003771" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003772 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003773
3774 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003775 let bgone= bufnr("%")
3776 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003777 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003778
3779" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003780endfun
3781
3782" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003783" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3784" list of the contents of a local or remote directory. It is assumed that the
3785" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3786" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003787" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003788fun! s:NetrwBrowse(islocal,dirname)
3789 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003790" call Dfunc("s:NetrwBrowse(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".w:netrw_liststyle." ".g:loaded_netrw." buf#".bufnr("%")."<".bufname("%")."> win#".winnr())
Bram Moolenaar85850f32019-07-19 22:05:51 +02003791" call Decho("fyi: modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
3792" call Decho("fyi: tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
3793" call Dredir("ls!","s:NetrwBrowse")
Bram Moolenaara6878372014-03-22 21:02:50 +01003794
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003795 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3796 " This is useful when one edits a local file, then :e ., then :Rex
3797 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3798 let w:netrw_rexfile= bufname("#")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003799" call Decho("setting w:netrw_rexfile<".w:netrw_rexfile."> win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003800 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003801
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003802 " s:NetrwBrowse : initialize history {{{3
3803 if !exists("s:netrw_initbookhist")
3804 NetrwKeepj call s:NetrwBookHistRead()
3805 endif
3806
3807 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003808 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003809 let dirname= simplify(a:dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003810" call Decho("simplified dirname<".dirname.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003811 else
3812 let dirname= a:dirname
3813 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814
Bram Moolenaar85850f32019-07-19 22:05:51 +02003815 " repoint t:netrw_lexbufnr if appropriate
3816 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
3817" call Decho("set repointlexbufnr to true!")
3818 let repointlexbufnr= 1
3819 endif
3820
3821 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003822 if exists("s:netrw_skipbrowse")
3823 unlet s:netrw_skipbrowse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003824" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." filename<".expand("%")."> win#".winnr()." ft<".&ft.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01003825" call Dret("s:NetrwBrowse : s:netrw_skipbrowse existed")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003826 return
3827 endif
3828 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003829 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003830" call Dret("s:NetrwBrowse : missing shellescape()")
3831 return
3832 endif
3833 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003834 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835" call Dret("s:NetrwBrowse : missing fnameescape()")
3836 return
3837 endif
3838
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003839 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003840 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003841
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003842 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003843 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3844 if exists("s:netrwmarkfilelist_{bufnr('%')}")
3845" call Decho("clearing marked files",'~'.expand("<slnum>"))
3846 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3847 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003848 endif
3849
3850 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003851 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852" call Decho("handle w:netrw_acdkeep:",'~'.expand("<slnum>"))
3853" call Decho("NetrwKeepj lcd ".fnameescape(dirname)." (due to w:netrw_acdkeep=".w:netrw_acdkeep." - acd=".&acd.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003854 if s:NetrwLcd(dirname)
3855" call Dret("s:NetrwBrowse : lcd failure")
3856 return
3857 endif
3858 " call s:NetrwOptionsSafe() " tst952 failed with this enabled.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003859" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003860
Bram Moolenaar5c736222010-01-06 20:54:52 +01003861 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003862 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003863" call Decho("handle remote regular file: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003864 if bufname(dirname) != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003865" call Decho("edit buf#".bufname(dirname)." in win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003866 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003867 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003868 " attempt transfer of remote regular file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003869" call Decho("attempt transfer as regular file<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003870
3871 " remove any filetype indicator from end of dirname, except for the
3872 " "this is a directory" indicator (/).
3873 " There shouldn't be one of those here, anyway.
3874 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003875" call Decho("new path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003876 call s:RemotePathAnalysis(dirname)
3877
3878 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3879 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003880 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003881 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003882" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003883 let b:netrw_curdir = dirname
3884 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003885 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003886 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3887 sil call netrw#NetRead(2,url)
3888 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003889" call Decho("url<".url.">",'~'.expand("<slnum>"))
3890" call Decho("s:path<".s:path.">",'~'.expand("<slnum>"))
3891" call Decho("s:fname<".s:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003892 if s:path =~ '.bz2'
3893 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3894 elseif s:path =~ '.gz'
3895 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3896 elseif s:path =~ '.gz'
3897 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3898 else
3899 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3900 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003901 endif
3902
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003903 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003904 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003905 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003906" call Decho("setl ma nomod",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003907 setl ma nomod noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003908" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003909
Bram Moolenaar446cb832008-06-24 21:56:24 +00003910" call Dret("s:NetrwBrowse : file<".s:fname.">")
3911 return
3912 endif
3913
Bram Moolenaaradc21822011-04-01 18:03:16 +02003914 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003915 call s:UseBufWinVars()
3916
3917 " set up some variables {{{3
3918 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003919 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003920 let s:last_sort_by = g:netrw_sort_by
3921
3922 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003923 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003924
Bram Moolenaar97d62492012-11-15 21:28:22 +01003925 " get/set-up buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003926" call Decho("saving position across a buffer refresh",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003927 let svpos = winsaveview()
3928" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003929 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003930
Bram Moolenaar446cb832008-06-24 21:56:24 +00003931 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003932 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3933 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
3934" " call Decho("bufnr(%)=".bufnr('%'),'~'.expand("<slnum>"))
3935" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
3936 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3937 else
3938" " call Decho("2match none",'~'.expand("<slnum>"))
3939 2match none
3940 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003941 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003942 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003943 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003944" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003945 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003946" call Decho("(set noma nomod nowrap) ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003947" call Dret("s:NetrwBrowse : re-using not-cleared buffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003948 return
3949 endif
3950
3951 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003952" call Decho("set b:netrw_curdir to the new directory name<".dirname."> (buf#".bufnr("%").")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003953 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003954 if b:netrw_curdir =~ '[/\\]$'
3955 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3956 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003957 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003958 let b:netrw_curdir= b:netrw_curdir."/"
3959 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003960 if b:netrw_curdir == ''
3961 if has("amiga")
3962 " On the Amiga, the empty string connotes the current directory
3963 let b:netrw_curdir= getcwd()
3964 else
3965 " under unix, when the root directory is encountered, the result
3966 " from the preceding substitute is an empty string.
3967 let b:netrw_curdir= '/'
3968 endif
3969 endif
3970 if !a:islocal && b:netrw_curdir !~ '/$'
3971 let b:netrw_curdir= b:netrw_curdir.'/'
3972 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003973" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974
3975 " ------------
3976 " (local only) {{{3
3977 " ------------
3978 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979" call Decho("local only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003980
3981 " Set up ShellCmdPost handling. Append current buffer to browselist
3982 call s:LocalFastBrowser()
3983
3984 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3985 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003986" call Decho("handle g:netrw_keepdir=".g:netrw_keepdir.": getcwd<".getcwd()."> acd=".&acd,'~'.expand("<slnum>"))
3987" call Decho("l:acd".(exists("&l:acd")? "=".&l:acd : " doesn't exist"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003988 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003989 if s:NetrwLcd(b:netrw_curdir)
3990" call Dret("s:NetrwBrowse : lcd failure")
3991 return
3992 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003993 endif
3994 endif
3995
3996 " --------------------------------
3997 " remote handling: {{{3
3998 " --------------------------------
3999 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004000" call Decho("remote only:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004001
Bram Moolenaar97d62492012-11-15 21:28:22 +01004002 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist")."> dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004004 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004005 let dirname= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004006" call Decho("(dirname was <NetrwTreeListing>) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004007 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
4008 let dirname= substitute(b:netrw_curdir,'\\','/','g')
4009 if dirname !~ '/$'
4010 let dirname= dirname.'/'
4011 endif
4012 let b:netrw_curdir = dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004013" call Decho("(liststyle is TREELIST) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004014 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01004015 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004016" call Decho("(normal) dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004017 endif
4018
4019 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
4020 if dirname !~ dirpat
4021 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004022 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004023 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004024 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004025" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004026 setl noma nomod nowrap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004027" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004028" call Dret("s:NetrwBrowse : badly formatted dirname<".dirname.">")
4029 return
4030 endif
4031 let b:netrw_curdir= dirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004032" call Decho("b:netrw_curdir<".b:netrw_curdir."> (remote)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004033 endif " (additional remote handling)
4034
Bram Moolenaar85850f32019-07-19 22:05:51 +02004035 " -------------------------------
4036 " Perform Directory Listing: {{{3
4037 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004038 NetrwKeepj call s:NetrwMaps(a:islocal)
4039 NetrwKeepj call s:NetrwCommands(a:islocal)
4040 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004041
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004042 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004043 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004044" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4045
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004046 " If there is a rexposn: restore position with rexposn
4047 " Otherwise : set rexposn
4048 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004049" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
4050 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
4051 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4052 NetrwKeepj exe w:netrw_bannercnt
4053 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004054 else
4055 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
4056 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02004057 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01004058 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004059" call Decho("set up balloon help: l:bexpr=".&l:bexpr,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004060 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02004061 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004062
Bram Moolenaar85850f32019-07-19 22:05:51 +02004063 " repoint t:netrw_lexbufnr if appropriate
4064 if exists("repointlexbufnr")
4065 let t:netrw_lexbufnr= bufnr("%")
4066" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4067 endif
4068
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004069 " restore position
4070 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004071" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4072 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004073 endif
4074
Bram Moolenaara6878372014-03-22 21:02:50 +01004075 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02004076 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
4077 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4079" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004080" call Dret("s:NetrwBrowse : did PerformListing ft<".&ft.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004081 return
4082endfun
4083
4084" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004085" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
4086" may not apply correctly; ie. netrw's idea of the current directory may
4087" differ from vim's. This function insures that netrw's idea of the current
4088" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004089" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004090fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004091" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
4092" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
4093" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
4094" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
4095" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004096
4097 " clean up any leading treedepthstring
4098 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4099 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02004100" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004101 else
4102 let fname= a:fname
4103 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004104
4105 if g:netrw_keepdir
4106 " vim's idea of the current directory possibly may differ from netrw's
4107 if !exists("b:netrw_curdir")
4108 let b:netrw_curdir= getcwd()
4109 endif
4110
Nir Lichtman1e34b952024-05-08 19:19:34 +02004111 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004112 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004113 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004114 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004115" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004116 else
4117 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004118 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004119" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004120 endif
4121
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004122 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004124 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004125" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004126 else
4127 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004128 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004129" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004130 endif
4131 else
4132 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004133 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02004134" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
4135" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
4136" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137 endif
4138
Bram Moolenaar85850f32019-07-19 22:05:51 +02004139" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004140 return ret
4141endfun
4142
4143" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004144" s:NetrwFileInfo: supports qf (query for file information) {{{2
4145fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01004146" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004147 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004148 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004149 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004150 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004151 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004152 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004153 let lsopt= "-lsadh --si"
4154 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004155" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004156 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004157
4158 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004159 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004160" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004161
Bram Moolenaara6878372014-03-22 21:02:50 +01004162 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004163 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004165
4166 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004167 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004169
Bram Moolenaar446cb832008-06-24 21:56:24 +00004170 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004171" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004172 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004173" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004174 endif
4175 else
4176 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004177" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
4178 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004179 let fname= substitute(a:fname,".$","","")
4180 else
4181 let fname= a:fname
4182 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004183 let t = getftime(s:NetrwFile(fname))
4184 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004185 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004186 let sz= s:NetrwHumanReadable(sz)
4187 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004188 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4189" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004190 endif
4191 else
4192 echo "sorry, \"qf\" not supported yet for remote files"
4193 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004194 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004195" call Dret("s:NetrwFileInfo")
4196endfun
4197
4198" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004199" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4200fun! s:NetrwFullPath(filename)
4201" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4202 let filename= a:filename
4203 if filename !~ '^/'
4204 let filename= resolve(getcwd().'/'.filename)
4205 endif
4206 if filename != "/" && filename =~ '/$'
4207 let filename= substitute(filename,'/$','','')
4208 endif
4209" " call Dret("s:NetrwFullPath <".filename.">")
4210 return filename
4211endfun
4212
4213" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004214" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004216" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004217" Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004218fun! s:NetrwGetBuffer(islocal,dirname)
4219" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004220" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." hid=".&hid,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004221" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4222" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004223 let dirname= a:dirname
4224
4225 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004226" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004227 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004228" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004229 let s:netrwbuf= {}
4230 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004231" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4232" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4233
4234 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4235 let bufnum = -1
4236
4237 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4238 if has_key(s:netrwbuf,"NetrwTreeListing")
4239 let bufnum= s:netrwbuf["NetrwTreeListing"]
4240 else
4241 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4242 endif
4243" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4244 if !bufexists(bufnum)
4245 call remove(s:netrwbuf,"NetrwTreeListing"])
4246 let bufnum= -1
4247 endif
4248 elseif bufnr("NetrwTreeListing") != -1
4249 let bufnum= bufnr("NetrwTreeListing")
4250" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4251 else
4252" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4253 let bufnum= -1
4254 endif
4255
4256 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004257 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004258" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004259 if !bufexists(bufnum)
4260 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4261 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004263
Bram Moolenaar446cb832008-06-24 21:56:24 +00004264 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004265" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004266 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004267 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004268" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4269
Bram Moolenaar71badf92023-04-22 22:40:14 +01004270 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004271 " IF the buffer already has the desired name
4272 " AND it is empty
4273 let curbuf = bufname("%")
4274 if curbuf == '.'
4275 let curbuf = getcwd()
4276 endif
4277" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004278" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004279" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4280" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4281" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4282" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4283 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004284" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4285 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004286 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004287" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004288 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004289 " Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems
Bram Moolenaar446cb832008-06-24 21:56:24 +00004290
4291 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004292 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004293" call Decho("--get enew buffer and name it (bufnum#".bufnum."<0 OR bufexists(".bufnum.")=".bufexists(bufnum)."==0)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004294 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004295" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296 " name the buffer
4297 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4298 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004299" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004300 let w:netrw_treebufnr = bufnr("%")
4301 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004302 if g:netrw_use_noswf
4303 setl nobl bt=nofile noswf
4304 else
4305 setl nobl bt=nofile
4306 endif
4307 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4308 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4309 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4310 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004311" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004313 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004314 " enter the new buffer into the s:netrwbuf dictionary
4315 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4316" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4317" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004318 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004319" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004320
4321 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004322" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004323 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004324 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004325 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004326
4327 if &ft == "netrw"
4328" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4329 exe "sil! NetrwKeepj noswapfile b ".bufnum
4330" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004332" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4333 call s:NetrwEditBuf(bufnum)
4334" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004336" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004337 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004338 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004339 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004340
4341 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004343
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004344 if line("$") <= 1 && getline(1) == ""
4345 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004346 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004347" 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>"))
4348" 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 +01004349" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4350 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004351
Bram Moolenaar97d62492012-11-15 21:28:22 +01004352 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004353" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004354 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004355 sil NetrwKeepj %d _
4356" 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>"))
4357" 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 +01004358" 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 +00004359 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004360
Bram Moolenaar446cb832008-06-24 21:56:24 +00004361 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004362" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4363" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004364 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004365 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004366 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004367" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4368" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004369" 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 +00004370 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004371
Bram Moolenaar446cb832008-06-24 21:56:24 +00004372 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004373" 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>"))
4374" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4375" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376 return 1
4377 endif
4378 endif
4379
4380 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4381 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4382 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4383 " med 1 D H
4384 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004385" 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 +00004386 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004387 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004388 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389
4390 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004391" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4392" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4393 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004395" 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>"))
4396" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4397" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004398 return 0
4399endfun
4400
4401" ---------------------------------------------------------------------
4402" s:NetrwGetcwd: get the current directory. {{{2
4403" Change backslashes to forward slashes, if any.
4404" If doesc is true, escape certain troublesome characters
4405fun! s:NetrwGetcwd(doesc)
4406" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4407 let curdir= substitute(getcwd(),'\\','/','ge')
4408 if curdir !~ '[\/]$'
4409 let curdir= curdir.'/'
4410 endif
4411 if a:doesc
4412 let curdir= fnameescape(curdir)
4413 endif
4414" call Dret("NetrwGetcwd <".curdir.">")
4415 return curdir
4416endfun
4417
4418" ---------------------------------------------------------------------
4419" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4420fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004421" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4422" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4423 let keepsol= &l:sol
4424 setl nosol
4425
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426 call s:UseBufWinVars()
4427
4428 " insure that w:netrw_liststyle is set up
4429 if !exists("w:netrw_liststyle")
4430 if exists("g:netrw_liststyle")
4431 let w:netrw_liststyle= g:netrw_liststyle
4432 else
4433 let w:netrw_liststyle= s:THINLIST
4434 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004435" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004436 endif
4437
4438 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4439 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004440" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004441 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004442 let dirname= "./"
4443 let curline= getline('.')
4444
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004445 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004446 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004447 let s:netrw_skipbrowse= 1
4448 echo 'Pressing "s" also works'
4449
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004450 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004451 let s:netrw_skipbrowse= 1
4452 echo 'Press "S" to edit sorting sequence'
4453
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004454 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004455 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004456 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004457
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004458 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004459 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004460 let s:netrw_skipbrowse= 1
4461 echo 'Pressing "a" also works'
4462
4463 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004464 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004465 endif
4466
4467 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004468" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004469 NetrwKeepj norm! 0
4470 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004471
4472 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004473" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004474 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004475 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4476
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004477 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004478" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004479 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004480 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004481
4482 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004484 let dirname= getline('.')
4485
4486 if !exists("b:netrw_cpf")
4487 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004488 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 +01004489 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004490" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004491 endif
4492
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004493" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004494 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004495" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4496" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004497 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004498 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499 else
4500 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004501 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004502 endif
Enno3146d632024-07-04 19:44:42 +02004503
4504 let dict={}
4505 " save the unnamed register and register 0-9 and a
4506 let dict.a=[getreg('a'), getregtype('a')]
4507 for i in range(0, 9)
4508 let dict[i] = [getreg(i), getregtype(i)]
4509 endfor
4510 let dict.unnamed = [getreg(''), getregtype('')]
4511
Bram Moolenaarc236c162008-07-13 17:41:49 +00004512 let eofname= filestart + b:netrw_cpf + 1
4513 if eofname <= col("$")
4514 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004515 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004516 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004517 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004518 endif
Enno3146d632024-07-04 19:44:42 +02004519
Bram Moolenaar446cb832008-06-24 21:56:24 +00004520 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004521 call s:RestoreRegister(dict)
4522
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004523" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004524 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004525" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004526 endif
4527
4528 " symlinks are indicated by a trailing "@". Remove it before further processing.
4529 let dirname= substitute(dirname,"@$","","")
4530
4531 " executables are indicated by a trailing "*". Remove it before further processing.
4532 let dirname= substitute(dirname,"\*$","","")
4533
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004534 let &l:sol= keepsol
4535
Bram Moolenaar446cb832008-06-24 21:56:24 +00004536" call Dret("s:NetrwGetWord <".dirname.">")
4537 return dirname
4538endfun
4539
4540" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004541" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4542" g:netrw_bufsettings will be used after the listing is produced.
4543" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544fun! s:NetrwListSettings(islocal)
4545" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004546" 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 +00004547 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004548" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4549 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4550 setl bt=nofile nobl ma nonu nowrap noro nornu
4551 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004552 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004553 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004554 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004555" call Dredir("ls!","s:NetrwListSettings")
4556" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004557 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004558 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004560 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004561 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004562 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004564" 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 +00004565" call Dret("s:NetrwListSettings")
4566endfun
4567
4568" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004569" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004570" islocal=0: remote browsing
4571" =1: local browsing
4572fun! s:NetrwListStyle(islocal)
4573" call Dfunc("NetrwListStyle(islocal=".a:islocal.") w:netrw_liststyle=".w:netrw_liststyle)
Bram Moolenaar13600302014-05-22 18:26:40 +02004574
Bram Moolenaar97d62492012-11-15 21:28:22 +01004575 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004576 let fname = s:NetrwGetWord()
4577 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004578 let svpos = winsaveview()
4579" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004580 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004581" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
4582" call Decho("chgd w:netrw_liststyle to ".w:netrw_liststyle,'~'.expand("<slnum>"))
4583" call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004584
Bram Moolenaar85850f32019-07-19 22:05:51 +02004585 " repoint t:netrw_lexbufnr if appropriate
4586 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
4587" call Decho("set repointlexbufnr to true!")
4588 let repointlexbufnr= 1
4589 endif
4590
Bram Moolenaar446cb832008-06-24 21:56:24 +00004591 if w:netrw_liststyle == s:THINLIST
4592 " use one column listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004593" call Decho("use one column list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004594 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4595
4596 elseif w:netrw_liststyle == s:LONGLIST
4597 " use long list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004598" call Decho("use long list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4600
4601 elseif w:netrw_liststyle == s:WIDELIST
4602 " give wide list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004603" call Decho("use wide list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004604 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4605
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004606 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004607" call Decho("use tree list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004608 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4609
4610 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004611 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004612 let g:netrw_liststyle = s:THINLIST
4613 let w:netrw_liststyle = g:netrw_liststyle
4614 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4615 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004616 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004617" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004618
4619 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004620" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4621 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004622 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004623" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004624 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004625" 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 +00004626
4627 " refresh the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004628" call Decho("refresh the listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004629 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004630 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004631
Bram Moolenaar85850f32019-07-19 22:05:51 +02004632 " repoint t:netrw_lexbufnr if appropriate
4633 if exists("repointlexbufnr")
4634 let t:netrw_lexbufnr= bufnr("%")
4635" call Decho("repoint t:netrw_lexbufnr to #".t:netrw_lexbufnr)
4636 endif
4637
Bram Moolenaar13600302014-05-22 18:26:40 +02004638 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004639" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4640 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004641 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004642
4643" call Dret("NetrwListStyle".(exists("w:netrw_liststyle")? ' : w:netrw_liststyle='.w:netrw_liststyle : ""))
4644endfun
4645
4646" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004647" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4648fun! s:NetrwBannerCtrl(islocal)
4649" call Dfunc("s:NetrwBannerCtrl(islocal=".a:islocal.") g:netrw_banner=".g:netrw_banner)
4650
Bram Moolenaar97d62492012-11-15 21:28:22 +01004651 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004652 " toggle the banner (enable/suppress)
4653 let g:netrw_banner= !g:netrw_banner
4654
4655 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004656 let svpos= winsaveview()
4657" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004658 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
4659
4660 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004661 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4662 let fname= s:NetrwGetWord()
4663 sil NetrwKeepj $
4664 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4665" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4666 if result <= 0 && exists("w:netrw_bannercnt")
4667 exe "NetrwKeepj ".w:netrw_bannercnt
4668 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004669 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004670 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004671" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4672endfun
4673
4674" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004675" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4676"
4677" No bang: enters files/directories into Netrw's bookmark system
4678" No argument and in netrw buffer:
4679" if there are marked files: bookmark marked files
4680" otherwise : bookmark file/directory under cursor
4681" No argument and not in netrw buffer: bookmarks current open file
4682" Has arguments: globs them individually and bookmarks them
4683"
4684" With bang: deletes files/directories from Netrw's bookmark system
4685fun! s:NetrwBookmark(del,...)
4686" call Dfunc("s:NetrwBookmark(del=".a:del.",...) a:0=".a:0)
4687 if a:0 == 0
4688 if &ft == "netrw"
4689 let curbufnr = bufnr("%")
4690
4691 if exists("s:netrwmarkfilelist_{curbufnr}")
4692 " for every filename in the marked list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004693" call Decho("bookmark every filename in marked list",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004694 let svpos = winsaveview()
4695" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004696 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004697 for fname in s:netrwmarkfilelist_{curbufnr}
4698 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4699 endfor
4700 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4701 call s:NetrwUnmarkList(curbufnr,curdir)
4702 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004703" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4704 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004705 else
4706 let fname= s:NetrwGetWord()
4707 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4708 endif
4709
4710 else
4711 " bookmark currently open file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004712" call Decho("bookmark currently open file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004713 let fname= expand("%")
4714 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4715 endif
4716
4717 else
4718 " bookmark specified files
4719 " attempts to infer if working remote or local
4720 " by deciding if the current file begins with an url
4721 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004722 let islocal= expand("%") !~ '^\a\{3,}://'
4723" call Decho("bookmark specified file".((a:0>1)? "s" : ""),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004724 let i = 1
4725 while i <= a:0
4726 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004727 if v:version > 704 || (v:version == 704 && has("patch656"))
4728 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004729 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004730 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004731 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004732 else
4733 let mbfiles= [a:{i}]
4734 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004735" call Decho("mbfiles".string(mbfiles),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004736 for mbfile in mbfiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004737" call Decho("mbfile<".mbfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004738 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4739 endfor
4740 let i= i + 1
4741 endwhile
4742 endif
4743
4744 " update the menu
4745 call s:NetrwBookmarkMenu()
4746
4747" call Dret("s:NetrwBookmark")
4748endfun
4749
4750" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004751" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4752" .2.[cnt] for bookmarks, and
4753" .3.[cnt] for history
4754" (see s:NetrwMenu())
4755fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004756 if !exists("s:netrw_menucnt")
4757 return
4758 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004759" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004760
4761 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004762 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004763 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004764" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004765 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4766 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004767 endif
4768 if !exists("s:netrw_initbookhist")
4769 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004770 endif
4771
4772 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004773 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004774 let cnt= 1
4775 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004776" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004777 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004778
4779 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004780 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004781
4782 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004783 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 +01004784 let cnt= cnt + 1
4785 endfor
4786
4787 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004788
4789 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004790 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004791 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004792 let first = 1
4793 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004794 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004795 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004796 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004797 if exists("g:netrw_dirhist_{cnt}")
4798 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004799" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004800 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4801 endif
4802 let first = 0
4803 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4804 if cnt < 0
4805 let cnt= cnt + g:netrw_dirhistmax
4806 endif
4807 endwhile
4808 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004809
Bram Moolenaar9964e462007-05-05 17:54:07 +00004810 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004811" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004812endfun
4813
4814" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4816" directory and a new directory name. Also, if the
4817" "new directory name" is actually a file,
4818" NetrwBrowseChgDir() edits the file.
4819fun! s:NetrwBrowseChgDir(islocal,newdir,...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004820" 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 +01004821" 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 +00004822
Bram Moolenaar97d62492012-11-15 21:28:22 +01004823 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004824 if !exists("b:netrw_curdir")
4825 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4826 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004827 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004828" call Decho("b:netrw_curdir doesn't exist!",'~'.expand("<slnum>"))
4829" call Decho("getcwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004830" call Dredir("ls!","s:NetrwBrowseChgDir")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004831" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004832 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004833 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004834" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004835
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004836 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004837" call Decho("saving options",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004838 call s:SavePosn(s:netrw_posn)
4839 NetrwKeepj call s:NetrwOptionsSave("s:")
4840 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Nir Lichtman1e34b952024-05-08 19:19:34 +02004841 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +01004842 let dirname = substitute(b:netrw_curdir,'\\','/','ge')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004843 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004844 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004845 endif
4846 let newdir = a:newdir
4847 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004848 let dorestore = 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004849" call Decho("win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004850" call Decho("dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004851" call Decho("newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004852
4853 " ignore <cr>s when done in the banner
Bram Moolenaar85850f32019-07-19 22:05:51 +02004854" 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 +01004855 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004856" 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 +01004857 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004858 if getline(".") =~# 'Quick Help'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004859" 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 +01004860 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004861" 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 +02004862 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004863 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004864 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004865 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866" 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 +01004867 endif
4868 endif
4869" else " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02004870" call Decho("g:netrw_banner=".g:netrw_banner." (no banner)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01004871 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004872
Bram Moolenaar446cb832008-06-24 21:56:24 +00004873 " set up o/s-dependent directory recognition pattern
4874 if has("amiga")
4875 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004876 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004877 let dirpat= '[\/]$'
4878 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004879" call Decho("set up o/s-dependent directory recognition pattern: dirname<".dirname."> dirpat<".dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004880
4881 if dirname !~ dirpat
4882 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004883 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004884 let dirname= dirname.'/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004885" call Decho("adjusting dirname<".dirname.'> (put trailing "/" back)','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004886 endif
4887
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004888" 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 +01004889 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004890 " ------------------------------
4891 " NetrwBrowseChgDir: edit a file {{{3
4892 " ------------------------------
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004893" call Decho('edit-a-file: case "handling a file": win#'.winnr().' newdir<'.newdir.'> !~ dirpat<'.dirpat.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004894
Bram Moolenaar97d62492012-11-15 21:28:22 +01004895 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004896 let s:rexposn_{bufnr("%")}= winsaveview()
4897" call Decho("edit-a-file: saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004898" call Decho("edit-a-file: win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
4899" 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 +01004900
Bram Moolenaar446cb832008-06-24 21:56:24 +00004901 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004902" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
4903" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004904" let newdir = s:NetrwTreePath(s:netrw_treetop)
4905" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004906 let dirname= s:NetrwTreeDir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004907 "COMBAK : not working for a symlink -- but what about a regular file? a directory?
4908" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
4909 " Feb 17, 2019: following if-else-endif restored -- wasn't editing a file in tree mode
Bram Moolenaar446cb832008-06-24 21:56:24 +00004910 if dirname =~ '/$'
4911 let dirname= dirname.newdir
4912 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004913 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004914 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004915" call Decho("edit-a-file: dirname<".dirname.">",'~'.expand("<slnum>"))
4916" call Decho("edit-a-file: tree listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004917 elseif newdir =~ '^\(/\|\a:\)'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004918" call Decho("edit-a-file: handle an url or path starting with /: <".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004919 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004920 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004921 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004922 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004923" call Decho("edit-a-file: handling a file: dirname<".dirname."> (a:0=".a:0.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004924 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004925 if a:0 < 1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004926" 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 +02004927 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004928 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004929 if !exists("s:didsplit")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004930" " 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 +01004931 if type(g:netrw_browse_split) == 3
4932 " open file in server
4933 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004934" call Decho("edit-a-file: open file in server",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004935 call s:NetrwServerEdit(a:islocal,dirname)
4936" call Dret("s:NetrwBrowseChgDir")
4937 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004938
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004939 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004940 " horizontally splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004941" call Decho("edit-a-file: horizontally splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004942 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4943 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").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 == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004950 " vertically splitting the window first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004951" call Decho("edit-a-file: vertically splitting window prior to edit",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004952 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4953 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004954 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004955 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004956 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004957 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004958
Bram Moolenaar446cb832008-06-24 21:56:24 +00004959 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004960 " open file in new tab
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004961" call Decho("edit-a-file: opening new tab prior to edit",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02004962 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004963 if !exists("b:netrw_curdir")
4964 let b:netrw_curdir= getcwd()
4965 endif
4966 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004967
Bram Moolenaar446cb832008-06-24 21:56:24 +00004968 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004969 " act like "P" (ie. open previous window)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004970" call Decho("edit-a-file: use previous window for edit",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004971 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004972 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004973" call Dret("s:NetrwBrowseChgDir")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004974 return
4975 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004976 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004977
Bram Moolenaar9964e462007-05-05 17:54:07 +00004978 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004979 " handling a file, didn't split, so remove menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004980" call Decho("edit-a-file: handling a file+didn't split, so remove menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004981 call s:NetrwMenu(0)
4982 " optional change to window
4983 if g:netrw_chgwin >= 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004984" 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 +02004985 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004986 " if g:netrw_chgwin is set to one more than the last window, then
4987 " vertically split the last window to make that window available.
4988 let curwin= winnr()
4989 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4990 vs
4991 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004992 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004993 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004994 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004995 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004996 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004997
Bram Moolenaar9964e462007-05-05 17:54:07 +00004998 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004999
Bram Moolenaar446cb832008-06-24 21:56:24 +00005000 " the point where netrw actually edits the (local) file
5001 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01005002 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005003 if !&mod
5004 " if e the new file would fail due to &mod, then don't change any of the flags
5005 let dolockout= 1
5006 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005007 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005008" call Decho("edit-a-file: edit local file: exe e! ".fnameescape(dirname),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005009 " some like c-^ to return to the last edited file
5010 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005011 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
5012 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01005013 call s:NetrwEditFile("e","",dirname)
5014" call Decho("edit-a-file: after e ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005015 " COMBAK -- cuc cul related
5016 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02005017 if &hidden || &bufhidden == "hide"
5018 " file came from vim's hidden storage. Don't "restore" options with it.
5019 let dorestore= 0
5020 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005021 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005022" call Decho("edit-a-file: remote file: NetrwBrowse will edit it",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00005023 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005024
5025 " handle g:Netrw_funcref -- call external-to-netrw functions
5026 " This code will handle g:Netrw_funcref as an individual function reference
5027 " or as a list of function references. It will ignore anything that's not
5028 " a function reference. See :help Funcref for information about function references.
5029 if exists("g:Netrw_funcref")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005030" call Decho("edit-a-file: handle optional Funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005031 if type(g:Netrw_funcref) == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005032" call Decho("edit-a-file: handling a g:Netrw_funcref",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005033 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005034 elseif type(g:Netrw_funcref) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005035" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005036 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005037 if type(Fncref) == 2
5038 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01005039 endif
5040 endfor
5041 endif
5042 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005043 endif
5044
5045 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005046 " ----------------------------------------------------
5047 " NetrwBrowseChgDir: just go to the new directory spec {{{3
5048 " ----------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005049" call Decho('goto-newdir: case "just go to new directory spec": newdir<'.newdir.'>','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005050 let dirname = newdir
5051 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005052 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005053 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005054
5055 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005056 " ---------------------------------------------
5057 " NetrwBrowseChgDir: refresh the directory list {{{3
5058 " ---------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005059" call Decho('(s:NetrwBrowseChgDir)refresh-dirlist: case "refresh directory listing": newdir == "./"','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005060 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005061 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005062
5063 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01005064 " --------------------------------------
5065 " NetrwBrowseChgDir: go up one directory {{{3
5066 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005067" call Decho('(s:NetrwBrowseChgDir)go-up: case "go up one directory": newdir == "../"','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005068
5069 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
5070 " force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005071" call Decho("go-up: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
5072" call Decho("go-up: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005073 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005074 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005075 endif
5076
5077 if has("amiga")
5078 " amiga
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005079" call Decho('go-up: case "go up one directory": newdir == "../" and amiga','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005080 if a:islocal
5081 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
5082 let dirname= substitute(dirname,'/$','','')
5083 else
5084 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
5085 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005086" call Decho("go-up: amiga: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005087
Nir Lichtman1e34b952024-05-08 19:19:34 +02005088 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005089 " windows
5090 if a:islocal
5091 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5092 if dirname == ""
5093 let dirname= '/'
5094 endif
5095 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005096 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01005097 endif
5098 if dirname =~ '^\a:$'
5099 let dirname= dirname.'/'
5100 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005101" call Decho("go-up: windows: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01005102
Bram Moolenaar446cb832008-06-24 21:56:24 +00005103 else
5104 " unix or cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +02005105" 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 +00005106 if a:islocal
5107 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
5108 if dirname == ""
5109 let dirname= '/'
5110 endif
5111 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005112 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005113 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005114" call Decho("go-up: unix: dirname<".dirname."> (go up one dir)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005115 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005116 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005117 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00005118
5119 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005120 " --------------------------------------
5121 " NetrwBrowseChgDir: Handle Tree Listing {{{3
5122 " --------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005123" call Decho('(s:NetrwBrowseChgDir)tree-list: case liststyle is TREELIST and w:netrw_treedict exists','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005124 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
5125" call Decho("tree-list: setl noro ma",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02005126 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00005127 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005128" call Decho("tree-list: clear buffer<".expand("%")."> with :%d (force refresh)",'~'.expand("<slnum>"))
5129 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005131 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005132" call Decho("tree-list: treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005133 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005134 let haskey = 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005135" call Decho("tree-list: w:netrw_treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005136
5137 " search treedict for tree dir as-is
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005138" call Decho("tree-list: search treedict for tree dir as-is",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005139 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005140" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005141 let haskey= 1
5142 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005143" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005144 endif
5145
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005146 " search treedict for treedir with a [/@] appended
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005147" call Decho("tree-list: search treedict for treedir with a [/@] appended",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005148 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005149 if has_key(w:netrw_treedict,treedir."/")
5150 let treedir= treedir."/"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005151" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005152 let haskey = 1
5153 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005154" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'/> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155 endif
5156 endif
5157
5158 " search treedict for treedir with any trailing / elided
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005159" call Decho("tree-list: search treedict for treedir with any trailing / elided",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 if !haskey && treedir =~ '/$'
5161 let treedir= substitute(treedir,'/$','','')
5162 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005163" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched.for treedir<'.treedir.'> found it!','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 let haskey = 1
5165 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005166" call Decho('(s:NetrwBrowseChgDir)tree-list: ....searched for treedir<'.treedir.'> : not found','~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167 endif
5168 endif
5169
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005170" call Decho("haskey=".haskey,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 if haskey
5172 " close tree listing for selected subdirectory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005173" call Decho("tree-list: closing selected subdirectory<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005174 call remove(w:netrw_treedict,treedir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005175" call Decho("tree-list: removed entry<".treedir."> from treedict",'~'.expand("<slnum>"))
5176" call Decho("tree-list: yielding treedict<".string(w:netrw_treedict).">",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005177 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00005178 else
5179 " go down one directory
5180 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005181" call Decho("tree-list: go down one dir: treedir<".treedir.">",'~'.expand("<slnum>"))
5182" call Decho("tree-list: ... : dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005183 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005184 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005185" call Decho("setting s:treeforceredraw to true",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005186 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005187
5188 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01005189 " ----------------------------------------
5190 " NetrwBrowseChgDir: Go down one directory {{{3
5191 " ----------------------------------------
5192 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005193" call Decho("go down one dir: dirname<".dirname."> newdir<".newdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005194 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005195 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00005196 endif
5197
Bram Moolenaar97d62492012-11-15 21:28:22 +01005198 " --------------------------------------
5199 " NetrwBrowseChgDir: Restore and Cleanup {{{3
5200 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02005201 if dorestore
5202 " dorestore is zero'd when a local file was hidden or bufhidden;
5203 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005204" call Decho("doing option restore (dorestore=".dorestore.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005205 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02005206" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005207" call Decho("skipping option restore (dorestore==0): hidden=".&hidden." bufhidden=".&bufhidden." mod=".&mod,'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005208 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02005209 if dolockout && dorestore
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005210" call Decho("restore: filewritable(dirname<".dirname.">)=".filewritable(dirname),'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02005211 if filewritable(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005212" call Decho("restore: doing modification lockout settings: ma nomod noro",'~'.expand("<slnum>"))
5213" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005214 setl ma noro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005215" 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 +02005216 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005217" call Decho("restore: doing modification lockout settings: ma nomod ro",'~'.expand("<slnum>"))
5218" call Decho("restore: setl ma nomod noro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02005219 setl ma ro nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005220" 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 +02005221 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005222 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005223 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005224 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005225
Bram Moolenaar446cb832008-06-24 21:56:24 +00005226" call Dret("s:NetrwBrowseChgDir <".dirname."> : curpos<".string(getpos(".")).">")
5227 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00005228endfun
5229
5230" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01005231" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
5232" for thin, long, and wide: cursor placed just after banner
5233" for tree, keeps cursor on current filename
5234fun! s:NetrwBrowseUpDir(islocal)
5235" call Dfunc("s:NetrwBrowseUpDir(islocal=".a:islocal.")")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005236 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
5237 " this test needed because occasionally this function seems to be incorrectly called
5238 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005239 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005240 " directories.
5241" call Dret("s:NetrwBrowseUpDir : cursor not in file area")
5242 return
5243 endif
5244
Bram Moolenaara6878372014-03-22 21:02:50 +01005245 norm! 0
5246 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005247" call Decho("case: treestyle",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01005248 let curline= getline(".")
5249 let swwline= winline() - 1
5250 if exists("w:netrw_treetop")
5251 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02005252 elseif exists("b:netrw_curdir")
5253 let w:netrw_treetop= b:netrw_curdir
5254 else
5255 let w:netrw_treetop= getcwd()
5256 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01005257 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005258 let curfile = getline(".")
5259 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01005260 if a:islocal
5261 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5262 else
5263 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5264 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005265" call Decho("looking for curfile<^".s:treedepthstring.curfile.">",'~'.expand("<slnum>"))
5266" call Decho("having curpath<".curpath.">",'~'.expand("<slnum>"))
5267 if w:netrw_treetop == '/'
5268 keepj call search('^\M'.curfile,"w")
5269 elseif curfile == '../'
5270 keepj call search('^\M'.curfile,"wb")
5271 else
5272" call Decho("search(^\\M".s:treedepthstring.curfile.") backwards"))
5273 while 1
5274 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
5275 let treepath= s:NetrwTreePath(w:netrw_treetop)
5276" call Decho("..current treepath<".treepath.">",'~'.expand("<slnum>"))
5277 if treepath == curpath
5278 break
5279 endif
5280 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01005281 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005282
Bram Moolenaara6878372014-03-22 21:02:50 +01005283 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005284" call Decho("case: not treestyle",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005285 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005286 if exists("b:netrw_curdir")
5287 let curdir= b:netrw_curdir
5288 else
5289 let curdir= expand(getcwd())
5290 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005291 if a:islocal
5292 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../'))
5293 else
5294 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../'))
5295 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005296 call s:RestorePosn(s:netrw_posn)
5297 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01005298 let curdir= '\<'. escape(curdir, '~'). '/'
5299 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01005300 endif
5301" call Dret("s:NetrwBrowseUpDir")
5302endfun
5303
5304" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005305" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005306" given filename; typically this means given their extension.
5307" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005308fun! netrw#BrowseX(fname,remote)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005309 let use_ctrlo= 1
Bram Moolenaar91359012019-11-30 17:57:03 +01005310" call Dfunc("netrw#BrowseX(fname<".a:fname."> remote=".a:remote.") implements x and gx maps")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005311
Bram Moolenaar91359012019-11-30 17:57:03 +01005312 if a:remote == 0 && isdirectory(a:fname)
5313 " if its really just a local directory, then do a "gf" instead
5314" 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 +01005315" call Decho("..appears to be a local directory; using e ".a:fname." instead",'~'.expand("<slnum>"))
5316 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005317" call Dret("netrw#BrowseX")
5318 return
5319 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5320 " remote directory, not a webpage access, looks like an attempt to do a directory listing
5321" call Decho("remote≡1 and a:fname<".a:fname.">",'~'.expand("<slnum>"))
5322" call Decho("..and fname ".((a:fname =~ '^https\=:')? 'matches' : 'does not match').'^https\=:','~'.expand("<slnum>"))
5323" call Decho("..and fname ".((a:fname =~ '/$')? 'matches' : 'does not match').' /$','~'.expand("<slnum>"))
5324" call Decho("..appears to be a remote directory listing request; using gf instead",'~'.expand("<slnum>"))
5325 norm! gf
5326" call Dret("netrw#BrowseX")
5327 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005328 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01005329" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005330
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005331 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5332 let remote = a:remote
5333 else
5334 let remote = 0
5335 endif
5336
Bram Moolenaar97d62492012-11-15 21:28:22 +01005337 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005338 let screenposn = winsaveview()
Bram Moolenaar46973992017-12-14 19:56:46 +01005339" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005340
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005341 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5342 let awkeep = &aw
5343 set noaw
5344
Bram Moolenaar5c736222010-01-06 20:54:52 +01005345 " special core dump handler
5346 if a:fname =~ '/core\(\.\d\+\)\=$'
5347 if exists("g:Netrw_corehandler")
5348 if type(g:Netrw_corehandler) == 2
5349 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005350" call Decho("g:Netrw_corehandler is a funcref",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005351 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005352 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005353 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar46973992017-12-14 19:56:46 +01005354" call Decho("g:Netrw_corehandler is a List",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005355 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005356 if type(Fncref) == 2
5357 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005358 endif
5359 endfor
5360 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005361" call Decho("restoring posn: screenposn<".string(screenposn).">,'~'.expand("<slnum>"))"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005362 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005363 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005364 let &aw= awkeep
5365" call Dret("netrw#BrowseX : coredump handler invoked")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005366 return
5367 endif
5368 endif
5369
Bram Moolenaar446cb832008-06-24 21:56:24 +00005370 " set up the filename
5371 " (lower case the extension, make a local copy of a remote file)
5372 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005373 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005374 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005375 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005376 if exten =~ "[\\/]"
5377 let exten= ""
5378 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005379" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005380
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005381 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005382 " create a local copy
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005383" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02005384 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005385 call netrw#NetRead(3,a:fname)
5386 " attempt to rename tempfile
5387 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005388 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar46973992017-12-14 19:56:46 +01005389" call Decho("basename<".basename.">",'~'.expand("<slnum>"))
5390" call Decho("newname <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005391 if s:netrw_tmpfile != newname && newname != ""
5392 if rename(s:netrw_tmpfile,newname) == 0
5393 " renaming succeeded
5394" call Decho("renaming succeeded (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5395 let fname= newname
5396 else
5397 " renaming failed
5398" call Decho("renaming failed (tmpfile<".s:netrw_tmpfile."> to <".newname.">)")
5399 let fname= s:netrw_tmpfile
5400 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005401 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005402 let fname= s:netrw_tmpfile
5403 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005404 else
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005405" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005406 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005407 " special ~ handler for local
5408 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005409" call Decho('invoking special ~ handler','~'.expand("<slnum>"))
5410 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005411 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005412 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005413" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
5414" call Decho("exten<".exten."> "."netrwFileHandlers#NFH_".exten."():exists=".exists("*netrwFileHandlers#NFH_".exten),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005415
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005416 " set up redirection (avoids browser messages)
5417 " by default, g:netrw_suppress_gx_mesg is true
5418 if g:netrw_suppress_gx_mesg
5419 if &srr =~ "%s"
Nir Lichtman1e34b952024-05-08 19:19:34 +02005420 if has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005421 let redir= substitute(&srr,"%s","nul","")
5422 else
5423 let redir= substitute(&srr,"%s","/dev/null","")
5424 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005425 elseif has("win32")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005426 let redir= &srr . "nul"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005427 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005428 let redir= &srr . "/dev/null"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005429 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005430 else
5431 let redir= ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005432 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005433" call Decho("set up redirection: redir{".redir."} srr{".&srr."}",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005434
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005435 " extract any viewing options. Assumes that they're set apart by spaces.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005436 if exists("g:netrw_browsex_viewer")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005437" call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005438 if g:netrw_browsex_viewer =~ '\s'
5439 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5440 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5441 let oviewer = ''
5442 let cnt = 1
5443 while !executable(viewer) && viewer != oviewer
5444 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5445 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5446 let cnt = cnt + 1
5447 let oviewer = viewer
Bram Moolenaar46973992017-12-14 19:56:46 +01005448" call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005449 endwhile
5450 else
5451 let viewer = g:netrw_browsex_viewer
5452 let viewopt = ""
5453 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005454" call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005455 endif
5456
5457 " execute the file handler
Bram Moolenaar46973992017-12-14 19:56:46 +01005458" call Decho("execute the file handler (if any)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005459 if exists("g:netrw_browsex_viewer") && g:netrw_browsex_viewer == '-'
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005460" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005461 let ret= netrwFileHandlers#Invoke(exten,fname)
5462
5463 elseif exists("g:netrw_browsex_viewer") && executable(viewer)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005464" call Decho("(netrw#BrowseX) g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005465 call s:NetrwExe("sil !".viewer." ".viewopt.s:ShellEscape(fname,1).redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005466 let ret= v:shell_error
5467
Nir Lichtman1e34b952024-05-08 19:19:34 +02005468 elseif has("win32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005469" call Decho("(netrw#BrowseX) win".(has("win32")? "32" : "64"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005470 if executable("start")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005471 call s:NetrwExe('sil! !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005472 elseif executable("rundll32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005473 call s:NetrwExe('sil! !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(fname,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005474 else
5475 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5476 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005477 let ret= v:shell_error
5478
Bram Moolenaar97d62492012-11-15 21:28:22 +01005479 elseif has("win32unix")
5480 let winfname= 'c:\cygwin'.substitute(fname,'/','\\','g')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005481" call Decho("(netrw#BrowseX) cygwin: winfname<".s:ShellEscape(winfname,1).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005482 if executable("start")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005483" call Decho("(netrw#BrowseX) win32unix+start",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005484 call s:NetrwExe('sil !start rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005485 elseif executable("rundll32")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005486" call Decho("(netrw#BrowseX) win32unix+rundll32",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005487 call s:NetrwExe('sil !rundll32 url.dll,FileProtocolHandler '.s:ShellEscape(winfname,1))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005488 elseif executable("cygstart")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005489" call Decho("(netrw#BrowseX) win32unix+cygstart",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005490 call s:NetrwExe('sil !cygstart '.s:ShellEscape(fname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005491 else
5492 call netrw#ErrorMsg(s:WARNING,"rundll32 not on path",74)
5493 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005494 let ret= v:shell_error
5495
Bram Moolenaar85850f32019-07-19 22:05:51 +02005496 elseif has("unix") && $DESKTOP_SESSION == "mate" && executable("atril")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005497" call Decho("(netrw#BrowseX) unix and atril",'~'.expand("<slnum>"))
5498 if a:fname =~ '^https\=://'
5499 " atril does not appear to understand how to handle html -- so use gvim to edit the document
5500 let use_ctrlo= 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005501" call Decho("fname<".fname.">")
5502" call Decho("a:fname<".a:fname.">")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005503 call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
5504
5505 else
5506 call s:NetrwExe("sil !atril ".s:ShellEscape(fname,1).redir)
5507 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005508 let ret= v:shell_error
5509
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005510 elseif has("unix") && executable("kfmclient") && s:CheckIfKde()
5511" call Decho("(netrw#BrowseX) unix and kfmclient",'~'.expand("<slnum>"))
5512 call s:NetrwExe("sil !kfmclient exec ".s:ShellEscape(fname,1)." ".redir)
5513 let ret= v:shell_error
5514
5515 elseif has("unix") && executable("exo-open") && executable("xdg-open") && executable("setsid")
5516" call Decho("(netrw#BrowseX) unix, exo-open, xdg-open",'~'.expand("<slnum>"))
5517 call s:NetrwExe("sil !setsid xdg-open ".s:ShellEscape(fname,1).redir.'&')
5518 let ret= v:shell_error
5519
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005520 elseif has("unix") && executable("xdg-open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005521" call Decho("(netrw#BrowseX) unix and xdg-open",'~'.expand("<slnum>"))
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005522 call s:NetrwExe("sil !xdg-open ".s:ShellEscape(fname,1).redir.'&')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005523 let ret= v:shell_error
5524
5525 elseif has("macunix") && executable("open")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005526" call Decho("(netrw#BrowseX) macunix and open",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005527 call s:NetrwExe("sil !open ".s:ShellEscape(fname,1)." ".redir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005528 let ret= v:shell_error
5529
5530 else
5531 " netrwFileHandlers#Invoke() always returns 0
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005532" call Decho("(netrw#BrowseX) use netrwFileHandlers",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005533 let ret= netrwFileHandlers#Invoke(exten,fname)
5534 endif
5535
5536 " if unsuccessful, attempt netrwFileHandlers#Invoke()
5537 if ret
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005538" call Decho("(netrw#BrowseX) ret=".ret," indicates unsuccessful thus far",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005539 let ret= netrwFileHandlers#Invoke(exten,fname)
5540 endif
5541
Bram Moolenaarc236c162008-07-13 17:41:49 +00005542 " restoring redraw! after external file handlers
5543 redraw!
Bram Moolenaar446cb832008-06-24 21:56:24 +00005544
5545 " cleanup: remove temporary file,
5546 " delete current buffer if success with handler,
5547 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005548 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005549 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005550" if remote == 1 && fname != a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005551"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00005552" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553" endif
5554
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005555 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005556 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005557 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005558 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005559 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005560 if use_ctrlo
5561 exe "sil! NetrwKeepj norm! \<c-o>"
5562 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005563 endif
Bram Moolenaar46973992017-12-14 19:56:46 +01005564" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005565 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005566 let @@ = ykeep
5567 let &aw= awkeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005568
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005569" call Dret("netrw#BrowseX")
5570endfun
5571
5572" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005573" netrw#GX: gets word under cursor for gx support {{{2
5574" See also: netrw#BrowseXVis
5575" netrw#BrowseX
5576fun! netrw#GX()
5577" call Dfunc("netrw#GX()")
5578 if &ft == "netrw"
5579 let fname= s:NetrwGetWord()
5580 else
5581 let fname= expand((exists("g:netrw_gx")? g:netrw_gx : '<cfile>'))
5582 endif
5583" call Dret("netrw#GX <".fname.">")
5584 return fname
5585endfun
5586
5587" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005588" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5589fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005590 let dict={}
5591 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005592 norm! gv"ay
5593 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005594 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005595 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005596endfun
5597
5598" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005599" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5600" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5601" to become an unlisted buffer, so in that case don't bwipe it.
5602fun! s:NetrwBufRename(newname)
5603" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5604" call Dredir("ls!","s:NetrwBufRename (before rename)")
5605 let oldbufname= bufname(bufnr("%"))
5606" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5607
5608 if oldbufname != a:newname
5609" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5610 let b:junk= 1
5611" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5612 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005613" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005614 let oldbufnr= bufnr(oldbufname)
5615" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5616" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5617 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5618" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5619 exe "bwipe! ".oldbufnr
5620" else " Decho
5621" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005622" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5623" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5624" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005625 endif
5626" call Dredir("ls!","s:NetrwBufRename (after rename)")
5627" else " Decho
5628" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5629 endif
5630
5631" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5632endfun
5633
5634" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005635" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005636fun! netrw#CheckIfRemote(...)
5637" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5638 if a:0 > 0
5639 let curfile= a:1
5640 else
5641 let curfile= expand("%")
5642 endif
5643" call Decho("curfile<".curfile.">")
5644 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005645" call Dret("netrw#CheckIfRemote 1")
5646 return 1
5647 else
5648" call Dret("netrw#CheckIfRemote 0")
5649 return 0
5650 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005651endfun
5652
5653" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005654" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5655fun! s:NetrwChgPerm(islocal,curdir)
5656" call Dfunc("s:NetrwChgPerm(islocal=".a:islocal." curdir<".a:curdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005657 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005658 call inputsave()
5659 let newperm= input("Enter new permission: ")
5660 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005661 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5662 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
5663" call Decho("chgperm<".chgperm.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005664 call system(chgperm)
5665 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005666 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005667 endif
5668 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005669 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005670 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005671 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005672" call Dret("s:NetrwChgPerm")
5673endfun
5674
5675" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005676" s:CheckIfKde: checks if kdeinit is running {{{2
5677" Returns 0: kdeinit not running
5678" 1: kdeinit is running
5679fun! s:CheckIfKde()
5680" call Dfunc("s:CheckIfKde()")
5681 " seems kde systems often have gnome-open due to dependencies, even though
5682 " gnome-open's subsidiary display tools are largely absent. Kde systems
5683 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5684 if !exists("s:haskdeinit")
5685 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005686 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005687 if v:shell_error
5688 let s:haskdeinit = 0
5689 endif
5690 else
5691 let s:haskdeinit= 0
5692 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005693" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005694 endif
5695
5696" call Dret("s:CheckIfKde ".s:haskdeinit)
5697 return s:haskdeinit
5698endfun
5699
5700" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005701" s:NetrwClearExplore: clear explore variables (if any) {{{2
5702fun! s:NetrwClearExplore()
5703" call Dfunc("s:NetrwClearExplore()")
5704 2match none
5705 if exists("s:explore_match") |unlet s:explore_match |endif
5706 if exists("s:explore_indx") |unlet s:explore_indx |endif
5707 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5708 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5709 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5710 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5711 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5712 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5713 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5714" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005715" call Dret("s:NetrwClearExplore")
5716endfun
5717
5718" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005719" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5720fun! s:NetrwEditBuf(bufnum)
5721" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5722 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5723" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5724 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5725 else
5726" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005727 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005728 endif
5729" call Dret("s:NetrwEditBuf")
5730endfun
5731
5732" ---------------------------------------------------------------------
5733" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5734" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5735fun! s:NetrwEditFile(cmd,opt,fname)
5736" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5737 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5738" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5739 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5740 else
5741" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005742 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5743 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5744 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005745 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5746 endif
5747" call Dret("s:NetrwEditFile")
5748endfun
5749
5750" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005751" s:NetrwExploreListUniq: {{{2
5752fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar15146672011-10-20 22:22:38 +02005753" call Dfunc("s:NetrwExploreListUniq(explist<".string(a:explist).">)")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005754
5755 " this assumes that the list is already sorted
5756 let newexplist= []
5757 for member in a:explist
5758 if !exists("uniqmember") || member != uniqmember
5759 let uniqmember = member
5760 let newexplist = newexplist + [ member ]
5761 endif
5762 endfor
5763
Bram Moolenaar15146672011-10-20 22:22:38 +02005764" call Dret("s:NetrwExploreListUniq newexplist<".string(newexplist).">")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005765 return newexplist
5766endfun
5767
5768" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005769" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5770fun! s:NetrwForceChgDir(islocal,newdir)
5771" call Dfunc("s:NetrwForceChgDir(islocal=".a:islocal." newdir<".a:newdir.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005772 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005773 if a:newdir !~ '/$'
5774 " ok, looks like force is needed to get directory-style treatment
5775 if a:newdir =~ '@$'
5776 let newdir= substitute(a:newdir,'@$','/','')
5777 elseif a:newdir =~ '[*=|\\]$'
5778 let newdir= substitute(a:newdir,'.$','/','')
5779 else
5780 let newdir= a:newdir.'/'
5781 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005782" call Decho("adjusting newdir<".newdir."> due to gd",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02005783 else
5784 " should already be getting treatment as a directory
5785 let newdir= a:newdir
5786 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005787 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005788 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005789 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005790" call Dret("s:NetrwForceChgDir")
5791endfun
5792
5793" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005794" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005795" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5796" expr : this is the expression to follow the directory. Will use s:ComposePath()
5797" pare =1: remove the current directory from the resulting glob() filelist
5798" =0: leave the current directory in the resulting glob() filelist
5799fun! s:NetrwGlob(direntry,expr,pare)
5800" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005801 if netrw#CheckIfRemote()
5802 keepalt 1sp
5803 keepalt enew
5804 let keep_liststyle = w:netrw_liststyle
5805 let w:netrw_liststyle = s:THINLIST
5806 if s:NetrwRemoteListing() == 0
5807 keepj keepalt %s@/@@
5808 let filelist= getline(1,$)
5809 q!
5810 else
5811 " remote listing error -- leave treedict unchanged
5812 let filelist= w:netrw_treedict[a:direntry]
5813 endif
5814 let w:netrw_liststyle= keep_liststyle
5815 else
Christian Brabandt14879472024-06-13 21:25:35 +02005816 let path= s:ComposePath(fnameescape(a:direntry),a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005817 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005818 " escape [ so it is not detected as wildcard character, see :h wildcard
5819 let path= substitute(path, '[', '[[]', 'g')
5820 endif
5821 if v:version > 704 || (v:version == 704 && has("patch656"))
5822 let filelist= glob(path,0,1,1)
5823 else
5824 let filelist= glob(path,0,1)
5825 endif
5826 if a:pare
5827 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5828 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005829 endif
5830" call Dret("s:NetrwGlob ".string(filelist))
5831 return filelist
5832endfun
5833
5834" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005835" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5836fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaarff034192013-04-24 18:51:19 +02005837" call Dfunc("s:NetrwForceFile(islocal=".a:islocal." newdir<".a:newfile.">)")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005838 if a:newfile =~ '[/@*=|\\]$'
5839 let newfile= substitute(a:newfile,'.$','','')
5840 else
5841 let newfile= a:newfile
5842 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005843 if a:islocal
5844 call s:NetrwBrowseChgDir(a:islocal,newfile)
5845 else
5846 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile))
5847 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005848" call Dret("s:NetrwForceFile")
5849endfun
5850
5851" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005852" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5853" and switches the hiding mode. The actual hiding is done by
5854" s:NetrwListHide().
5855" g:netrw_hide= 0: show all
5856" 1: show not-hidden files
5857" 2: show hidden files only
5858fun! s:NetrwHide(islocal)
5859" call Dfunc("NetrwHide(islocal=".a:islocal.") g:netrw_hide=".g:netrw_hide)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005860 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005861 let svpos= winsaveview()
5862" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005863
5864 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005865" call Decho("((g:netrw_hide == 1)? "unhide" : "hide")." files in markfilelist<".string(s:netrwmarkfilelist_{bufnr("%")}).">",'~'.expand("<slnum>"))
5866" call Decho("g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005867
5868 " hide the files in the markfile list
5869 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005870" 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 +00005871 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5872 " remove fname from hiding list
5873 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5874 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5875 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005876" call Decho("unhide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005877 else
5878 " append fname to hiding list
5879 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5880 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5881 else
5882 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5883 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005884" call Decho("hide: g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885 endif
5886 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005887 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005888 let g:netrw_hide= 1
5889
5890 else
5891
5892 " switch between show-all/show-not-hidden/show-hidden
5893 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005894 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005895 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005896 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005897 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898" call Dret("NetrwHide")
5899 return
5900 endif
5901 endif
5902
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005903 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005904" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5905 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005906 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005907" call Dret("NetrwHide")
Bram Moolenaar9964e462007-05-05 17:54:07 +00005908endfun
5909
5910" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005911" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5912fun! s:NetrwHideEdit(islocal)
5913" call Dfunc("NetrwHideEdit(islocal=".a:islocal.")")
5914
5915 let ykeep= @@
5916 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005917 let svpos= winsaveview()
5918" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005919
5920 " get new hiding list from user
5921 call inputsave()
5922 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5923 call inputrestore()
5924 let g:netrw_list_hide= newhide
5925" call Decho("new g:netrw_list_hide<".g:netrw_list_hide.">",'~'.expand("<slnum>"))
5926
5927 " refresh the listing
5928 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./"))
5929
5930 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005931" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5932 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005933 let @@= ykeep
5934
5935" call Dret("NetrwHideEdit")
5936endfun
5937
5938" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005939" s:NetrwHidden: invoked by "gh" {{{2
5940fun! s:NetrwHidden(islocal)
5941" call Dfunc("s:NetrwHidden()")
Bram Moolenaar97d62492012-11-15 21:28:22 +01005942 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005943 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005944 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005945" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005946
5947 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005948 " remove .file pattern from hiding list
5949" call Decho("remove .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005950 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005951 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005952" call Decho("add .file pattern from hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5954 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005955" call Decho("set .file pattern as hiding list",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005956 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5957 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005958 if g:netrw_list_hide =~ '^,'
5959 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5960 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005961
5962 " refresh screen and return to saved position
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005963 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005964" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
5965 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005966 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967" call Dret("s:NetrwHidden")
5968endfun
5969
5970" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005971" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5972fun! s:NetrwHome()
5973 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005974 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005975 else
5976 " go to vim plugin home
5977 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005978 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005979 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005980 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005981 let home= basehome."/.vim"
5982 break
5983 endif
5984 endfor
5985 if home == ""
5986 " just pick the first directory
5987 let home= substitute(&rtp,',.*$','','')
5988 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005989 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005990 let home= substitute(home,'/','\\','g')
5991 endif
5992 endif
5993 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005994 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005995" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005996 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005997" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005998 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005999 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006000" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01006001 call mkdir(home)
6002 endif
6003 endif
6004 let g:netrw_home= home
6005 return home
6006endfun
6007
6008" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006009" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
6010fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006011 if exists("s:netrwdrag")
6012 return
6013 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006014 if &ft != "netrw"
6015 return
6016 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006017" call Dfunc("s:NetrwLeftmouse(islocal=".a:islocal.")")
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006018
Bram Moolenaar97d62492012-11-15 21:28:22 +01006019 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006020 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02006021 while getchar(0) != 0
6022 "clear the input stream
6023 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006024 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02006025 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006026 let mouse_lnum = v:mouse_lnum
6027 let wlastline = line('w$')
6028 let lastline = line('$')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006029" call Decho("v:mouse_lnum=".mouse_lnum." line(w$)=".wlastline." line($)=".lastline." v:mouse_win=".v:mouse_win." winnr#".winnr(),'~'.expand("<slnum>"))
6030" call Decho("v:mouse_col =".v:mouse_col." col=".col(".")." wincol =".wincol()." winwidth =".winwidth(0),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006031 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
6032 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01006033 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006034" call Dret("s:NetrwLeftmouse : detected a status bar leftmouse click")
6035 return
6036 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006037 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01006038 " 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 +01006039 " without this test when its disabled.
6040 " 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 +01006041" 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 +01006042 if v:mouse_col > virtcol('.')
6043 let @@= ykeep
6044" call Dret("s:NetrwLeftmouse : detected a vertical separator bar leftmouse click")
6045 return
6046 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02006047
Bram Moolenaar446cb832008-06-24 21:56:24 +00006048 if a:islocal
6049 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006050 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006051 endif
6052 else
6053 if exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006054 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006055 endif
6056 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006057 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00006058" call Dret("s:NetrwLeftmouse")
6059endfun
6060
6061" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006062" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
6063fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006064 if &ft != "netrw"
6065 return
6066 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006067" call Dfunc("s:NetrwCLeftmouse(islocal=".a:islocal.")")
6068 call s:NetrwMarkFileTgt(a:islocal)
6069" call Dret("s:NetrwCLeftmouse")
6070endfun
6071
6072" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006073" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
6074" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02006075" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006076" a:islocal=2 : <c-r> used, remote
6077" a:islocal=3 : <c-r> used, local
6078fun! s:NetrwServerEdit(islocal,fname)
6079" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
6080 let islocal = a:islocal%2 " =0: remote =1: local
6081 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006082" call Decho("islocal=".islocal." ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006083
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006084 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006085 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006086 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006087" call Decho("handling directory in client window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006088 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006089 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006090 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6091 unlet s:netrw_browse_split_{winnr()}
6092 endif
6093 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6094" call Dret("s:NetrwServerEdit")
6095 return
6096 endif
6097
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006098" call Decho("handling file in server window",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006099 if has("clientserver") && executable("gvim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006100" call Decho("has clientserver and gvim",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006101
6102 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006103" call Decho("g:netrw_browse_split=".string(g:netrw_browse_split),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006104 let srvrname = g:netrw_browse_split[0]
6105 let tabnum = g:netrw_browse_split[1]
6106 let winnum = g:netrw_browse_split[2]
6107
6108 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006109" call Decho("server not available; ctrlr=".ctrlr,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006110
6111 if !ctrlr
6112 " user must have closed the server window and the user did not use <c-r>, but
6113 " used something like <cr>.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006114" call Decho("user must have closed server AND did not use ctrl-r",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006115 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006116 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006117 endif
6118 let g:netrw_browse_split= 0
6119 if exists("s:netrw_browse_split_".winnr())
6120 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
6121 endif
6122 call s:NetrwBrowseChgDir(islocal,a:fname)
6123" call Dret("s:NetrwServerEdit")
6124 return
6125
6126 elseif has("win32") && executable("start")
6127 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006128" call Decho("starting up gvim server<".srvrname."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006129 call system("start gvim --servername ".srvrname)
6130
6131 else
6132 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006133" call Decho("starting up gvim server<".srvrname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006134 call system("gvim --servername ".srvrname)
6135 endif
6136 endif
6137
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006138" call Decho("srvrname<".srvrname."> tabnum=".tabnum." winnum=".winnum." server-editing<".a:fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006139 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
6140 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006141 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006142
6143 else
6144
6145 if serverlist() !~ '\<'.g:netrw_servername.'\>'
6146
6147 if !ctrlr
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148" call Decho("server<".g:netrw_servername."> not available and ctrl-r not used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006149 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09006150 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006151 endif
6152 let g:netrw_browse_split= 0
6153 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname))
6154" call Dret("s:NetrwServerEdit")
6155 return
6156
6157 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006158" call Decho("server<".g:netrw_servername."> not available but ctrl-r used",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006159 if has("win32") && executable("start")
6160 " start up remote netrw server under windows
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006161" call Decho("starting up gvim server<".g:netrw_servername."> for windows",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006162 call system("start gvim --servername ".g:netrw_servername)
6163 else
6164 " start up remote netrw server under linux
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006165" call Decho("starting up gvim server<".g:netrw_servername.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006166 call system("gvim --servername ".g:netrw_servername)
6167 endif
6168 endif
6169 endif
6170
6171 while 1
6172 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006173" call Decho("remote-send: e ".a:fname,'~'.expand("<slnum>"))
6174 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006175 break
6176 catch /^Vim\%((\a\+)\)\=:E241/
6177 sleep 200m
6178 endtry
6179 endwhile
6180
6181 if exists("g:netrw_browse_split")
6182 if type(g:netrw_browse_split) != 3
6183 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
6184 endif
6185 unlet g:netrw_browse_split
6186 endif
6187 let g:netrw_browse_split= [g:netrw_servername,1,1]
6188 endif
6189
6190 else
6191 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
6192 endif
6193
6194" call Dret("s:NetrwServerEdit")
6195endfun
6196
6197" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006198" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
6199fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006200 if &ft != "netrw"
6201 return
6202 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006203" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006204
Bram Moolenaar8d043172014-01-23 14:24:41 +01006205 let s:ngw= s:NetrwGetWord()
6206 call s:NetrwMarkFile(a:islocal,s:ngw)
6207
6208" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02006209endfun
6210
6211" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01006212" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
6213" Used to mark multiple files.
6214fun! s:NetrwSLeftdrag(islocal)
6215" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
6216 if !exists("s:netrwdrag")
6217 let s:netrwdrag = winnr()
6218 if a:islocal
6219 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006220 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01006221 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02006222 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006223 endif
6224 let ngw = s:NetrwGetWord()
6225 if !exists("s:ngw") || s:ngw != ngw
6226 call s:NetrwMarkFile(a:islocal,ngw)
6227 endif
6228 let s:ngw= ngw
6229" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6230endfun
6231
6232" ---------------------------------------------------------------------
6233" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
6234fun! s:NetrwSLeftrelease(islocal)
6235" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
6236 if exists("s:netrwdrag")
6237 nunmap <s-leftrelease>
6238 let ngw = s:NetrwGetWord()
6239 if !exists("s:ngw") || s:ngw != ngw
6240 call s:NetrwMarkFile(a:islocal,ngw)
6241 endif
6242 if exists("s:ngw")
6243 unlet s:ngw
6244 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006245 unlet s:netrwdrag
6246 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01006247" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02006248endfun
6249
6250" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01006251" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
6252" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00006253fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006254" 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 +02006255" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006256 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006257
6258 " 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 +02006259 " How-it-works: take the hiding command, convert it into a range.
6260 " Duplicate characters don't matter.
6261 " Remove all such characters from the '/~@#...890' string.
6262 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006263" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006264 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01006265 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006266" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006267
6268 while listhide != ""
6269 if listhide =~ ','
6270 let hide = substitute(listhide,',.*$','','e')
6271 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
6272 else
6273 let hide = listhide
6274 let listhide = ""
6275 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006276" 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 +01006277 if g:netrw_sort_by =~ '^[ts]'
6278 if hide =~ '^\^'
6279" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
6280 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
6281 elseif hide =~ '^\\(\^'
6282 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
6283 endif
6284" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
6285 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006286
6287 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02006288" 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 +00006289 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006290" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006291 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006292 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02006293" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006294 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00006295 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006296" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006297 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02006298
Bram Moolenaar446cb832008-06-24 21:56:24 +00006299 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006300 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006301" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006302 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02006303" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006304 endif
6305
Bram Moolenaaradc21822011-04-01 18:03:16 +02006306 " remove any blank lines that have somehow remained.
6307 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006308 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02006309
Bram Moolenaar97d62492012-11-15 21:28:22 +01006310 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006311" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006312endfun
6313
6314" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006315" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006316" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00006317fun! s:NetrwMakeDir(usrhost)
Bram Moolenaara6878372014-03-22 21:02:50 +01006318" call Dfunc("s:NetrwMakeDir(usrhost<".a:usrhost.">)")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006319
Bram Moolenaar97d62492012-11-15 21:28:22 +01006320 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006321 " get name of new directory from user. A bare <CR> will skip.
6322 " if its currently a directory, also request will be skipped, but with
6323 " a message.
6324 call inputsave()
6325 let newdirname= input("Please give directory name: ")
6326 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006327" call Decho("newdirname<".newdirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006328
6329 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01006330 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006331" call Dret("s:NetrwMakeDir : user aborted with bare <cr>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006332 return
6333 endif
6334
6335 if a:usrhost == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006336" call Decho("local mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006337
6338 " Local mkdir:
6339 " sanity checks
6340 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006341" call Decho("fullnewdir<".fullnewdir.">",'~'.expand("<slnum>"))
6342 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006343 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006344 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006345 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006346 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006347" call Dret("s:NetrwMakeDir : directory<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006348 return
6349 endif
6350 if s:FileReadable(fullnewdir)
6351 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006352 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006353 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006354 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006355" call Dret("s:NetrwMakeDir : file<".newdirname."> exists previously")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006356 return
6357 endif
6358
6359 " requested new local directory is neither a pre-existing file or
6360 " directory, so make it!
6361 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01006362 if has("unix")
6363 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
6364 else
6365 call mkdir(fullnewdir,"p")
6366 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006367 else
6368 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006369 if s:NetrwLcd(b:netrw_curdir)
6370" call Dret("s:NetrwMakeDir : lcd failure")
6371 return
6372 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006373" call Decho("netrw_origdir<".netrw_origdir.">: lcd b:netrw_curdir<".fnameescape(b:netrw_curdir).">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006374 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006375 if v:shell_error != 0
6376 let @@= ykeep
6377 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 +01006378" call Dret("s:NetrwMakeDir : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006379 return
6380 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006381 if !g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006382" call Decho("restoring netrw_origdir since g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006383 if s:NetrwLcd(netrw_origdir)
6384" call Dret("s:NetrwBrowse : lcd failure")
6385 return
6386 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006387 endif
6388 endif
6389
6390 if v:shell_error == 0
6391 " refresh listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006392" call Decho("refresh listing",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006393 let svpos= winsaveview()
6394" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006395 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006396" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6397 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006398 elseif !exists("g:netrw_quiet")
6399 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
6400 endif
6401" redraw!
6402
6403 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01006404 " Remote mkdir: using ssh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006405" call Decho("remote mkdir",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006406 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
6407 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006408 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 if v:shell_error == 0
6410 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006411 let svpos= winsaveview()
6412" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006413 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006414" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6415 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006416 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006417 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006418 endif
6419" redraw!
6420
6421 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006422 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006423 let svpos= winsaveview()
6424" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006425" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006426 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006427" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006428 let remotepath= b:netrw_fname
6429 else
6430 let remotepath= ""
6431 endif
6432 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006433 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006434" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6435 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006436
Bram Moolenaar446cb832008-06-24 21:56:24 +00006437 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006438 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006439 let svpos= winsaveview()
6440" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006441" call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006442 if exists("b:netrw_fname")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006443" call Decho("b:netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006444 let remotepath= b:netrw_fname
6445 else
6446 let remotepath= ""
6447 endif
6448 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006449 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006450" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6451 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006452 endif
6453
Bram Moolenaar97d62492012-11-15 21:28:22 +01006454 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006455" call Dret("s:NetrwMakeDir")
6456endfun
6457
6458" ---------------------------------------------------------------------
6459" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6460fun! s:TreeSqueezeDir(islocal)
6461" call Dfunc("s:TreeSqueezeDir(islocal=".a:islocal.")")
6462 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6463 " its a tree-listing style
6464 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006465 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006466 let depth = strchars(substitute(curdepth,' ','','g'))
6467 let srch = -1
6468" call Decho("curdepth<".curdepth.'>','~'.expand("<slnum>"))
6469" call Decho("depth =".depth,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006470" call Decho("stopline#".stopline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006471" call Decho("curline#".line(".")."<".getline('.').'>','~'.expand("<slnum>"))
6472 if depth >= 2
6473 NetrwKeepj norm! 0
6474 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6475 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
6476" call Decho("curdepthm1<".curdepthm1.'>','~'.expand("<slnum>"))
6477" call Decho("case depth>=2: srch<".srch.'>','~'.expand("<slnum>"))
6478 elseif depth == 1
6479 NetrwKeepj norm! 0
6480 let treedepthchr= substitute(s:treedepthstring,' ','','')
6481 let srch = search('^[^'.treedepthchr.']','bW',stopline)
6482" call Decho("case depth==1: srch<".srch.'>','~'.expand("<slnum>"))
6483 endif
6484 if srch > 0
6485" call Decho("squeezing at line#".line(".").": ".getline('.'),'~'.expand("<slnum>"))
6486 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord()))
6487 exe srch
6488 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006489 endif
6490" call Dret("s:TreeSqueezeDir")
6491endfun
6492
6493" ---------------------------------------------------------------------
6494" s:NetrwMaps: {{{2
6495fun! s:NetrwMaps(islocal)
6496" call Dfunc("s:NetrwMaps(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6497
Bram Moolenaar85850f32019-07-19 22:05:51 +02006498 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006499 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006500" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006501 if !hasmapto("<Plug>NetrwReturn")
6502 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006503" call Decho("making map for 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006504 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6505 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006506" call Decho("making map for c-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006507 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6508 endif
6509 endif
6510 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006511" call Decho("made <Plug>NetrwReturn map",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006512 endif
6513
Bram Moolenaar85850f32019-07-19 22:05:51 +02006514 " generate default <Plug> maps {{{3
6515 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006516 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006517 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6518 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6519 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6520 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6521 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6522 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6523 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6524 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6525 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6526 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
6527" ---------------------------------------------------------------------
6528" if !hasmapto('<Plug>NetrwForceChgDir') |nmap <buffer> <silent> <nowait> gd <Plug>NetrwForceChgDir|endif
6529" if !hasmapto('<Plug>NetrwForceFile') |nmap <buffer> <silent> <nowait> gf <Plug>NetrwForceFile|endif
6530" if !hasmapto('<Plug>NetrwHidden') |nmap <buffer> <silent> <nowait> gh <Plug>NetrwHidden|endif
6531" if !hasmapto('<Plug>NetrwSetTreetop') |nmap <buffer> <silent> <nowait> gn <Plug>NetrwSetTreetop|endif
6532" if !hasmapto('<Plug>NetrwChgPerm') |nmap <buffer> <silent> <nowait> gp <Plug>NetrwChgPerm|endif
6533" if !hasmapto('<Plug>NetrwBannerCtrl') |nmap <buffer> <silent> <nowait> I <Plug>NetrwBannerCtrl|endif
6534" if !hasmapto('<Plug>NetrwListStyle') |nmap <buffer> <silent> <nowait> i <Plug>NetrwListStyle|endif
6535" if !hasmapto('<Plug>NetrwMarkMoveMF2Arglist')|nmap <buffer> <silent> <nowait> ma <Plug>NetrwMarkMoveMF2Arglist|endif
6536" if !hasmapto('<Plug>NetrwMarkMoveArglist2MF')|nmap <buffer> <silent> <nowait> mA <Plug>NetrwMarkMoveArglist2MF|endif
6537" if !hasmapto('<Plug>NetrwBookHistHandler_mA')|nmap <buffer> <silent> <nowait> mb <Plug>NetrwBookHistHandler_mA|endif
6538" if !hasmapto('<Plug>NetrwBookHistHandler_mB')|nmap <buffer> <silent> <nowait> mB <Plug>NetrwBookHistHandler_mB|endif
6539" if !hasmapto('<Plug>NetrwMarkFileCopy') |nmap <buffer> <silent> <nowait> mc <Plug>NetrwMarkFileCopy|endif
6540" if !hasmapto('<Plug>NetrwMarkFileDiff') |nmap <buffer> <silent> <nowait> md <Plug>NetrwMarkFileDiff|endif
6541" if !hasmapto('<Plug>NetrwMarkFileEdit') |nmap <buffer> <silent> <nowait> me <Plug>NetrwMarkFileEdit|endif
6542" if !hasmapto('<Plug>NetrwMarkFile') |nmap <buffer> <silent> <nowait> mf <Plug>NetrwMarkFile|endif
6543" if !hasmapto('<Plug>NetrwUnmarkList') |nmap <buffer> <silent> <nowait> mF <Plug>NetrwUnmarkList|endif
6544" if !hasmapto('<Plug>NetrwMarkFileGrep') |nmap <buffer> <silent> <nowait> mg <Plug>NetrwMarkFileGrep|endif
6545" if !hasmapto('<Plug>NetrwMarkHideSfx') |nmap <buffer> <silent> <nowait> mh <Plug>NetrwMarkHideSfx|endif
6546" if !hasmapto('<Plug>NetrwMarkFileMove') |nmap <buffer> <silent> <nowait> mm <Plug>NetrwMarkFileMove|endif
6547" if !hasmapto('<Plug>NetrwMarkFilePrint') |nmap <buffer> <silent> <nowait> mp <Plug>NetrwMarkFilePrint|endif
6548" if !hasmapto('<Plug>NetrwMarkFileRegexp') |nmap <buffer> <silent> <nowait> mr <Plug>NetrwMarkFileRegexp|endif
6549" if !hasmapto('<Plug>NetrwMarkFileSource') |nmap <buffer> <silent> <nowait> ms <Plug>NetrwMarkFileSource|endif
6550" if !hasmapto('<Plug>NetrwMarkFileTag') |nmap <buffer> <silent> <nowait> mT <Plug>NetrwMarkFileTag|endif
6551" if !hasmapto('<Plug>NetrwMarkFileTgt') |nmap <buffer> <silent> <nowait> mt <Plug>NetrwMarkFileTgt|endif
6552" if !hasmapto('<Plug>NetrwUnMarkFile') |nmap <buffer> <silent> <nowait> mu <Plug>NetrwUnMarkFile|endif
6553" if !hasmapto('<Plug>NetrwMarkFileVimCmd') |nmap <buffer> <silent> <nowait> mv <Plug>NetrwMarkFileVimCmd|endif
6554" if !hasmapto('<Plug>NetrwMarkFileExe_mx') |nmap <buffer> <silent> <nowait> mx <Plug>NetrwMarkFileExe_mx|endif
6555" if !hasmapto('<Plug>NetrwMarkFileExe_mX') |nmap <buffer> <silent> <nowait> mX <Plug>NetrwMarkFileExe_mX|endif
6556" if !hasmapto('<Plug>NetrwMarkFileCompress') |nmap <buffer> <silent> <nowait> mz <Plug>NetrwMarkFileCompress|endif
6557" if !hasmapto('<Plug>NetrwObtain') |nmap <buffer> <silent> <nowait> O <Plug>NetrwObtain|endif
6558" if !hasmapto('<Plug>NetrwSplit_o') |nmap <buffer> <silent> <nowait> o <Plug>NetrwSplit_o|endif
6559" if !hasmapto('<Plug>NetrwPreview') |nmap <buffer> <silent> <nowait> p <Plug>NetrwPreview|endif
6560" if !hasmapto('<Plug>NetrwPrevWinOpen') |nmap <buffer> <silent> <nowait> P <Plug>NetrwPrevWinOpen|endif
6561" if !hasmapto('<Plug>NetrwBookHistHandler_qb')|nmap <buffer> <silent> <nowait> qb <Plug>NetrwBookHistHandler_qb|endif
6562" if !hasmapto('<Plug>NetrwFileInfo') |nmap <buffer> <silent> <nowait> qf <Plug>NetrwFileInfo|endif
6563" if !hasmapto('<Plug>NetrwMarkFileQFEL_qF') |nmap <buffer> <silent> <nowait> qF <Plug>NetrwMarkFileQFEL_qF|endif
6564" if !hasmapto('<Plug>NetrwMarkFileQFEL_qL') |nmap <buffer> <silent> <nowait> qL <Plug>NetrwMarkFileQFEL_qL|endif
6565" if !hasmapto('<Plug>NetrwSortStyle') |nmap <buffer> <silent> <nowait> s <Plug>NetrwSortStyle|endif
6566" if !hasmapto('<Plug>NetSortSequence') |nmap <buffer> <silent> <nowait> S <Plug>NetSortSequence|endif
6567" if !hasmapto('<Plug>NetrwSetTgt_Tb') |nmap <buffer> <silent> <nowait> Tb <Plug>NetrwSetTgt_Tb|endif
6568" if !hasmapto('<Plug>NetrwSetTgt_Th') |nmap <buffer> <silent> <nowait> Th <Plug>NetrwSetTgt_Th|endif
6569" if !hasmapto('<Plug>NetrwSplit_t') |nmap <buffer> <silent> <nowait> t <Plug>NetrwSplit_t|endif
6570" if !hasmapto('<Plug>NetrwBookHistHandler_u') |nmap <buffer> <silent> <nowait> u <Plug>NetrwBookHistHandler_u|endif
6571" if !hasmapto('<Plug>NetrwBookHistHandler_U') |nmap <buffer> <silent> <nowait> U <Plug>NetrwBookHistHandler_U|endif
6572" if !hasmapto('<Plug>NetrwSplit_v') |nmap <buffer> <silent> <nowait> v <Plug>NetrwSplit_v|endif
6573" if !hasmapto('<Plug>NetrwBrowseX') |nmap <buffer> <silent> <nowait> x <Plug>NetrwBrowseX|endif
6574" if !hasmapto('<Plug>NetrwLocalExecute') |nmap <buffer> <silent> <nowait> X <Plug>NetrwLocalExecute|endif
6575
Bram Moolenaara6878372014-03-22 21:02:50 +01006576 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006577" call Decho("make local maps",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006578 " local normal-mode maps {{{3
6579 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6580 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6581 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6582 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6583 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6584 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6585 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6586 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord()))<cr>
6587 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6588 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6589 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6590" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006591 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6592 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6593 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006594 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006595 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006596 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6597 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6598 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6599 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006600 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6601 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6602 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6603 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6604 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6605 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6606 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6607 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6608 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6609 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6610 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6611 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6612 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006613 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006614 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006615 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6616 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6617 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6618 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6619 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006620 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006621 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006622 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6623 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006624 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6625 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6626 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006627 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006628 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006629 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6630 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006631 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006632 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006633 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6634 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6635 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006636 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),0),0)"<cr>
6637 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006638
6639 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 +01006640 if !hasmapto('<Plug>NetrwHideEdit')
6641 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006642 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006643 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006644 if !hasmapto('<Plug>NetrwRefresh')
6645 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006646 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02006647 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 +01006648 if s:didstarstar || !mapcheck("<s-down>","n")
6649 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006650 endif
6651 if s:didstarstar || !mapcheck("<s-up>","n")
6652 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006653 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006654 if !hasmapto('<Plug>NetrwTreeSqueeze')
6655 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006656 endif
6657 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006658 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6659 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006660 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6661 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6662 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6663 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6664 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6665 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6666 imap <buffer> <leftmouse> <Plug>ILeftmouse
6667 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006668 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6669 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6670 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6671 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6672 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006673 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006674 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6675 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006676 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006677 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6678 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6679 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6680 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6681 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6682 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6683 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006684 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6685
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006686 " support user-specified maps
6687 call netrw#UserMaps(1)
6688
Bram Moolenaar85850f32019-07-19 22:05:51 +02006689 else
6690 " remote normal-mode maps {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006691" call Decho("make remote maps",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006692 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006693 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6694 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6695 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6696 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6697 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6698 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6699 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
6700 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6701 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()))<cr>
6702 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6703 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6704" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006705 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6706 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6707 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6708 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6709 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6710 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6711 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6712 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006713 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006714 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006715 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6716 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6717 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6718 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6719 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6720 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6721 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6722 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6723 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6724 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6725 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006726 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006727 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006728 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6729 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6730 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6731 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6732 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006733 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6734 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
6735 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
6736 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006737 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006738 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6739 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006740 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006741 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 +01006742 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6743 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6744 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6745 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6746 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6747 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6748 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6749 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
6750 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord()),1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006751 if !hasmapto('<Plug>NetrwHideEdit')
6752 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006753 endif
6754 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6755 if !hasmapto('<Plug>NetrwRefresh')
6756 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006757 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006758 if !hasmapto('<Plug>NetrwTreeSqueeze')
6759 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006760 endif
6761 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006762
6763 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006764 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006765
6766 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./'))<cr>
6767 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006768 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006769 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006770 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006771 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006772 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006773 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006774 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006775 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006776 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006777 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006778 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6779 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6780 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006781 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006782 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006783 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6784 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006785 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006786 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6787 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6788 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6789 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6790 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6791 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6792 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006793 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006794
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006795 " support user-specified maps
6796 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006797 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006798
6799" call Dret("s:NetrwMaps")
6800endfun
6801
6802" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006803" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006804" If -buffer, the command is only available from within netrw buffers
6805" Otherwise, the command is available from any window, so long as netrw
6806" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006807fun! s:NetrwCommands(islocal)
6808" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6809
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006810 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6811 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006812 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 +01006813 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006814 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006815 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006816 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006817 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006818 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006819
6820" call Dret("s:NetrwCommands")
6821endfun
6822
6823" ---------------------------------------------------------------------
6824" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6825" glob()ing only works with local files
6826fun! s:NetrwMarkFiles(islocal,...)
6827" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006828 let curdir = s:NetrwGetCurdir(a:islocal)
6829 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006830 while i <= a:0
6831 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006832 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006833 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006834 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006835 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006836 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006837 else
6838 let mffiles= [a:{i}]
6839 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006840" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006841 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006842" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006843 call s:NetrwMarkFile(a:islocal,mffile)
6844 endfor
6845 let i= i + 1
6846 endwhile
6847" call Dret("s:NetrwMarkFiles")
6848endfun
6849
6850" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006851" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006852fun! s:NetrwMarkTarget(...)
6853" call Dfunc("s:NetrwMarkTarget() a:0=".a:0)
6854 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006855 let curdir = s:NetrwGetCurdir(1)
6856 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006857 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006858 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6859 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006860 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006861" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006862 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006863 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6864 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006865 let svpos = winsaveview()
6866" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006867 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006868" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
6869 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006870" call Dret("s:NetrwMarkTarget")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006871endfun
6872
6873" ---------------------------------------------------------------------
6874" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6875" mark and unmark files. If a markfile list exists,
6876" then the rename and delete functions will use it instead
6877" of whatever may happen to be under the cursor at that
6878" moment. When the mouse and gui are available,
6879" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006880"
6881" Creates two lists
6882" s:netrwmarkfilelist -- holds complete paths to all marked files
6883" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6884"
6885" Creates a marked file match string
6886" s:netrwmarfilemtch_# -- used with 2match to display marked files
6887"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006888" Creates a buffer version of islocal
6889" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006890fun! s:NetrwMarkFile(islocal,fname)
6891" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006892" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006893
6894 " sanity check
6895 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006896" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006897 return
6898 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006899 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006900
Bram Moolenaar97d62492012-11-15 21:28:22 +01006901 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006902 let curbufnr= bufnr("%")
Bram Moolenaara6878372014-03-22 21:02:50 +01006903 if a:fname =~ '^\a'
6904 let leader= '\<'
6905 else
6906 let leader= ''
6907 endif
6908 if a:fname =~ '\a$'
6909 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6910 else
6911 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6912 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006913
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006914 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006915 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006916" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6917" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6918" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006919 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006920
6921 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006922 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006923" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006924 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006925 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006926
6927 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006928 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006929" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006930 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6931 if s:netrwmarkfilelist_{curbufnr} == []
6932 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006933" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006934 call s:NetrwUnmarkList(curbufnr,curdir)
6935 else
6936 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006937" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006938 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006939 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006940 for fname in s:netrwmarkfilelist_{curbufnr}
6941 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006942 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006943 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006944 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006945 endif
6946 let first= 0
6947 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006948" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006949 endif
6950 endif
6951
6952 else
6953 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006954" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006955
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006956" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006957 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006958 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6959" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006960
6961 " build initial markfile matching pattern
6962 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006963 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006964 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006965 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006966 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006967" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006968 endif
6969
6970 " handle global markfilelist
6971 if exists("s:netrwmarkfilelist")
6972 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6973 if index(s:netrwmarkfilelist,dname) == -1
6974 " append new filename to global markfilelist
6975 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006976" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006977 else
6978 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006979" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6980" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006981 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006982" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006983 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006984" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006985 unlet s:netrwmarkfilelist
6986 endif
6987 endif
6988 else
6989 " initialize new global-directory markfilelist
6990 let s:netrwmarkfilelist= []
6991 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006992" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006993 endif
6994
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006995 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006996 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6997 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6998" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6999 if exists("g:did_drchip_netrwlist_syntax")
7000 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
7001 endif
7002 else
7003" " call Decho("2match none",'~'.expand("<slnum>"))
7004 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01007005 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007006 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007007 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007008" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
7009" 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 +00007010endfun
7011
7012" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007013" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
7014" mA: move the argument list to marked file list (tomflist=1)
7015" Uses the global marked file list
7016fun! s:NetrwMarkFileArgList(islocal,tomflist)
7017" call Dfunc("s:NetrwMarkFileArgList(islocal=".a:islocal.",tomflist=".a:tomflist.")")
7018
7019 let svpos = winsaveview()
7020" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7021 let curdir = s:NetrwGetCurdir(a:islocal)
7022 let curbufnr = bufnr("%")
7023
7024 if a:tomflist
7025 " mA: move argument list to marked file list
7026 while argc()
7027 let fname= argv(0)
7028" call Decho("exe argdel ".fname,'~'.expand("<slnum>"))
7029 exe "argdel ".fnameescape(fname)
7030 call s:NetrwMarkFile(a:islocal,fname)
7031 endwhile
7032
7033 else
7034 " ma: move marked file list to argument list
7035 if exists("s:netrwmarkfilelist")
7036
7037 " for every filename in the marked list
7038 for fname in s:netrwmarkfilelist
7039" call Decho("exe argadd ".fname,'~'.expand("<slnum>"))
7040 exe "argadd ".fnameescape(fname)
7041 endfor " for every file in the marked list
7042
7043 " unmark list and refresh
7044 call s:NetrwUnmarkList(curbufnr,curdir)
7045 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
7046" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7047 NetrwKeepj call winrestview(svpos)
7048 endif
7049 endif
7050
7051" call Dret("s:NetrwMarkFileArgList")
7052endfun
7053
7054" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007055" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
7056" compress/decompress files using the programs
7057" in g:netrw_compress and g:netrw_uncompress,
7058" using g:netrw_compress_suffix to know which to
7059" do. By default:
7060" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02007061" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007062fun! s:NetrwMarkFileCompress(islocal)
7063" call Dfunc("s:NetrwMarkFileCompress(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007064 let svpos = winsaveview()
7065" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007066 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007067 let curbufnr = bufnr("%")
7068
Bram Moolenaarff034192013-04-24 18:51:19 +02007069 " sanity check
7070 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007071 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007072" call Dret("s:NetrwMarkFileCompress")
7073 return
7074 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007075" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007076
Bram Moolenaar446cb832008-06-24 21:56:24 +00007077 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02007078
7079 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00007080 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02007081 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007082" call Decho("extracted sfx<".sfx.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007083 if exists("g:netrw_decompress['".sfx."']")
7084 " fname has a suffix indicating that its compressed; apply associated decompression routine
7085 let exe= g:netrw_decompress[sfx]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007086" call Decho("fname<".fname."> is compressed so decompress with <".exe.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007087 let exe= netrw#WinPath(exe)
7088 if a:islocal
7089 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007090 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007091 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007092 call system(exe." ".fname)
7093 if v:shell_error
7094 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01007095 endif
7096 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007097 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
7098 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01007099 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007100
Bram Moolenaarff034192013-04-24 18:51:19 +02007101 endif
7102 unlet sfx
7103
Bram Moolenaar446cb832008-06-24 21:56:24 +00007104 if exists("exe")
7105 unlet exe
7106 elseif a:islocal
7107 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007108 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007109 if v:shell_error
7110 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
7111 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007112 else
7113 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007114 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007115 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007116 endfor " for every file in the marked list
7117
Bram Moolenaar446cb832008-06-24 21:56:24 +00007118 call s:NetrwUnmarkList(curbufnr,curdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007119 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007120" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7121 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007122 endif
7123" call Dret("s:NetrwMarkFileCompress")
7124endfun
7125
7126" ---------------------------------------------------------------------
7127" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
7128" If no marked files, then set up directory as the
7129" target. Currently does not support copying entire
7130" directories. Uses the local-buffer marked file list.
7131" Returns 1=success (used by NetrwMarkFileMove())
7132" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007133fun! s:NetrwMarkFileCopy(islocal,...)
7134" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
7135
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007136 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02007137 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007138 if b:netrw_curdir !~ '/$'
7139 if !exists("b:netrw_curdir")
7140 let b:netrw_curdir= curdir
7141 endif
7142 let b:netrw_curdir= b:netrw_curdir."/"
7143 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007144
Bram Moolenaarff034192013-04-24 18:51:19 +02007145 " sanity check
7146 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007147 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007148" call Dret("s:NetrwMarkFileCopy")
7149 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007150 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007151" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007152
Bram Moolenaar446cb832008-06-24 21:56:24 +00007153 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007154 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007155" call Dret("s:NetrwMarkFileCopy 0")
7156 return 0
7157 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007158" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007159
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007160 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00007161 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007162" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007163 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007164 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
7165" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
7166 return
7167 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007168
7169 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02007170 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007171 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
7172 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007173" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007174 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007175 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
7176 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007177" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007178 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007179 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007180 let oldname = a:1
7181 else
7182 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007183" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007184 let s:recursive= 1
7185 for oldname in s:netrwmarkfilelist_{bufnr("%")}
7186 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
7187 if ret == 0
7188 break
7189 endif
7190 endfor
7191 unlet s:recursive
7192 call s:NetrwUnmarkList(curbufnr,curdir)
7193" call Dret("s:NetrwMarkFileCopy ".ret)
7194 return ret
7195 endif
7196
7197 call inputsave()
7198 let newname= input("Copy ".oldname." to : ",oldname,"file")
7199 call inputrestore()
7200 if newname == ""
7201" call Dret("s:NetrwMarkFileCopy 0")
7202 return 0
7203 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204 let args= s:ShellEscape(oldname)
7205 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007206 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007207 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
7208 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007209 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007210 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007211 let args= substitute(args,'/','\\','g')
7212 let tgt = substitute(tgt, '/','\\','g')
7213 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007214 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
7215 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
7216 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
7217 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
7218" call Decho("args <".args.">",'~'.expand("<slnum>"))
7219" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007220 if isdirectory(s:NetrwFile(args))
7221" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007222 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007223" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007224 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007225 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
7226 " contents to a target. One must append the source directory name to the target to get xcopy to
7227 " do the right thing.
7228 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007229" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007230 endif
7231 else
7232 let copycmd= g:netrw_localcopycmd
7233 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007234 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007235 let copycmd = substitute(copycmd,'\s.*$','','')
7236 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02007237 let copycmd = netrw#WinPath(copycmd).copycmdargs
7238 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007239 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02007240 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007241" call Decho("args <".args.">",'~'.expand("<slnum>"))
7242" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
7243" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
7244" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007245 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007246 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02007247 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007248 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 +01007249 else
7250 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
7251 endif
7252" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007253 return 0
7254 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007255
7256 elseif a:islocal && !s:netrwmftgt_islocal
7257 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007258" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007259 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007260
7261 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007262 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007263" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007264 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007265
7266 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007267 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007268" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007269 let curdir = getcwd()
7270 let tmpdir = s:GetTempfile("")
7271 if tmpdir !~ '/'
7272 let tmpdir= curdir."/".tmpdir
7273 endif
7274 if exists("*mkdir")
7275 call mkdir(tmpdir)
7276 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007277 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01007278 if v:shell_error != 0
7279 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 +01007280" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01007281 return
7282 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007283 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007284 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007285 if s:NetrwLcd(tmpdir)
7286" call Dret("s:NetrwMarkFileCopy : lcd failure")
7287 return
7288 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007289 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007290 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007291 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 if getcwd() == tmpdir
7293 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007294 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007295 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02007296 if s:NetrwLcd(curdir)
7297" call Dret("s:NetrwMarkFileCopy : lcd failure")
7298 return
7299 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01007300 if delete(tmpdir,"d")
7301 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007302 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007303 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007304 if s:NetrwLcd(curdir)
7305" call Dret("s:NetrwMarkFileCopy : lcd failure")
7306 return
7307 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007308 endif
7309 endif
7310 endif
7311
7312 " -------
7313 " cleanup
7314 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007315" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007316 " remove markings from local buffer
7317 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007318" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
7319" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
7320" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
7321" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
7322" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
7323" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
7324 if exists("s:recursive")
7325" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
7326 else
7327" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02007328 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007329 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01007330 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007331 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007332 else
7333 " refresh local and targets for fast browsing
7334 if !exists("s:recursive")
7335 " remove markings from local buffer
7336" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
7337 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
7338 endif
7339
7340 " refresh buffers
7341 if s:netrwmftgt_islocal
7342" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
7343 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
7344 endif
7345 if a:islocal && s:netrwmftgt != curdir
7346" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
7347 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
7348 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007349 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007350
Bram Moolenaar446cb832008-06-24 21:56:24 +00007351" call Dret("s:NetrwMarkFileCopy 1")
7352 return 1
7353endfun
7354
7355" ---------------------------------------------------------------------
7356" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
7357" invoke vim's diff mode on the marked files.
7358" Either two or three files can be so handled.
7359" Uses the global marked file list.
7360fun! s:NetrwMarkFileDiff(islocal)
7361" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
7362 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007363
Bram Moolenaarff034192013-04-24 18:51:19 +02007364 " sanity check
7365 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007366 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007367" call Dret("s:NetrwMarkFileDiff")
7368 return
7369 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007370 let curdir= s:NetrwGetCurdir(a:islocal)
7371" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007372
Bram Moolenaara6878372014-03-22 21:02:50 +01007373 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007374 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00007375 for fname in s:netrwmarkfilelist
7376 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00007377 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007378" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007379 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007380 diffthis
7381 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09007382 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007383" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007384 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007385 diffthis
7386 else
7387 break
7388 endif
7389 endfor
7390 call s:NetrwUnmarkList(curbufnr,curdir)
7391 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007392
Bram Moolenaar446cb832008-06-24 21:56:24 +00007393" call Dret("s:NetrwMarkFileDiff")
7394endfun
7395
7396" ---------------------------------------------------------------------
7397" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
7398" Uses global markfilelist
7399fun! s:NetrwMarkFileEdit(islocal)
7400" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
7401
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007402 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007403 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007404
7405 " sanity check
7406 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007407 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007408" call Dret("s:NetrwMarkFileEdit")
7409 return
7410 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007411" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007412
Bram Moolenaar446cb832008-06-24 21:56:24 +00007413 if exists("s:netrwmarkfilelist_{curbufnr}")
7414 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007415 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007416 " unmark markedfile list
7417" call s:NetrwUnmarkList(curbufnr,curdir)
7418 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007419" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02007420 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007421 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007422 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007423
Bram Moolenaar446cb832008-06-24 21:56:24 +00007424" call Dret("s:NetrwMarkFileEdit")
7425endfun
7426
7427" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007428" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02007429fun! s:NetrwMarkFileQFEL(islocal,qfel)
7430" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
7431 call s:NetrwUnmarkAll()
7432 let curbufnr= bufnr("%")
7433
7434 if !empty(a:qfel)
7435 for entry in a:qfel
7436 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007437" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007438 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007439" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007440 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7441 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
7442 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
7443 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007444" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007445 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
7446 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007447" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007448 endif
7449 endfor
7450 echo "(use me to edit marked files)"
7451 else
7452 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
7453 endif
7454
7455" call Dret("s:NetrwMarkFileQFEL")
7456endfun
7457
7458" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007459" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
7460" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
7461" mX enbloc=1: Uses the global marked-file list, applies command to entire list
7462fun! s:NetrwMarkFileExe(islocal,enbloc)
7463" call Dfunc("s:NetrwMarkFileExe(islocal=".a:islocal.",enbloc=".a:enbloc.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007464 let svpos = winsaveview()
7465" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007466 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007467 let curbufnr = bufnr("%")
7468
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007469 if a:enbloc == 0
7470 " individually apply command to files, one at a time
7471 " sanity check
7472 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
7473 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
7474" call Dret("s:NetrwMarkFileExe")
7475 return
7476 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007477" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007478
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007479 if exists("s:netrwmarkfilelist_{curbufnr}")
7480 " get the command
7481 call inputsave()
7482 let cmd= input("Enter command: ","","file")
7483 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007484" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007485 if cmd == ""
7486" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7487 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007488 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007489
7490 " apply command to marked files, individually. Substitute: filename -> %
7491 " If no %, then append a space and the filename to the command
7492 for fname in s:netrwmarkfilelist_{curbufnr}
7493 if a:islocal
7494 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09007495 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007496 endif
7497 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007498 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007499 endif
7500 if cmd =~ '%'
7501 let xcmd= substitute(cmd,'%',fname,'g')
7502 else
7503 let xcmd= cmd.' '.fname
7504 endif
7505 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007506" call Decho("local: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007507 let ret= system(xcmd)
7508 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007509" call Decho("remote: xcmd<".xcmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007510 let ret= s:RemoteSystem(xcmd)
7511 endif
7512 if v:shell_error < 0
7513 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7514 break
7515 else
7516 echo ret
7517 endif
7518 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007519
7520 " unmark marked file list
7521 call s:NetrwUnmarkList(curbufnr,curdir)
7522
7523 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007524 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007525" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7526 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007527 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007528 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007529 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530
7531 else " apply command to global list of files, en bloc
7532
7533 call inputsave()
7534 let cmd= input("Enter command: ","","file")
7535 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007536" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007537 if cmd == ""
7538" call Dret("s:NetrwMarkFileExe : early exit, empty command")
7539 return
7540 endif
7541 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007542 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007543 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007544 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007545 endif
7546 if a:islocal
7547 call system(cmd)
7548 if v:shell_error < 0
7549 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7550 endif
7551 else
7552 let ret= s:RemoteSystem(cmd)
7553 endif
7554 call s:NetrwUnmarkAll()
7555
7556 " refresh the listing
7557 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007558" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7559 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007560
7561 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007562
Bram Moolenaar446cb832008-06-24 21:56:24 +00007563" call Dret("s:NetrwMarkFileExe")
7564endfun
7565
7566" ---------------------------------------------------------------------
7567" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7568" as the marked file(s) (toggles suffix presence)
7569" Uses the local marked file list.
7570fun! s:NetrwMarkHideSfx(islocal)
7571" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007572 let svpos = winsaveview()
7573" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007574 let curbufnr = bufnr("%")
7575
7576 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7577 if exists("s:netrwmarkfilelist_{curbufnr}")
7578
7579 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007580" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007581 " construct suffix pattern
7582 if fname =~ '\.'
7583 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7584 else
7585 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7586 endif
7587 " determine if its in the hiding list or not
7588 let inhidelist= 0
7589 if g:netrw_list_hide != ""
7590 let itemnum = 0
7591 let hidelist= split(g:netrw_list_hide,',')
7592 for hidepat in hidelist
7593 if sfxpat == hidepat
7594 let inhidelist= 1
7595 break
7596 endif
7597 let itemnum= itemnum + 1
7598 endfor
7599 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007600" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007601 if inhidelist
7602 " remove sfxpat from list
7603 call remove(hidelist,itemnum)
7604 let g:netrw_list_hide= join(hidelist,",")
7605 elseif g:netrw_list_hide != ""
7606 " append sfxpat to non-empty list
7607 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7608 else
7609 " set hiding list to sfxpat
7610 let g:netrw_list_hide= sfxpat
7611 endif
7612 endfor
7613
7614 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007615 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007616" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7617 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007618 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007619 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007620 endif
7621
7622" call Dret("s:NetrwMarkHideSfx")
7623endfun
7624
7625" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007626" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007627" Uses the local marked-file list.
7628fun! s:NetrwMarkFileVimCmd(islocal)
7629" call Dfunc("s:NetrwMarkFileVimCmd(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007630 let svpos = winsaveview()
7631" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007632 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007633 let curbufnr = bufnr("%")
7634
Bram Moolenaarff034192013-04-24 18:51:19 +02007635 " sanity check
7636 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007637 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007638" call Dret("s:NetrwMarkFileVimCmd")
7639 return
7640 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007641" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007642
Bram Moolenaar15146672011-10-20 22:22:38 +02007643 if exists("s:netrwmarkfilelist_{curbufnr}")
7644 " get the command
7645 call inputsave()
7646 let cmd= input("Enter vim command: ","","file")
7647 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648" call Decho("cmd<".cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007649 if cmd == ""
7650" " call Dret("s:NetrwMarkFileVimCmd : early exit, empty command")
7651 return
7652 endif
7653
7654 " apply command to marked files. Substitute: filename -> %
7655 " If no %, then append a space and the filename to the command
7656 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007657" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007658 if a:islocal
7659 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007660 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007661" call Decho("local<".fname.">: exe ".cmd,'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007662 exe cmd
7663 exe "sil! keepalt wq!"
7664 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007665" call Decho("remote<".fname.">: exe ".cmd." : NOT SUPPORTED YET",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007666 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007667 endif
7668 endfor
7669
7670 " unmark marked file list
7671 call s:NetrwUnmarkList(curbufnr,curdir)
7672
7673 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007674 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007675" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7676 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007677 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007678 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007679 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007680
Bram Moolenaar15146672011-10-20 22:22:38 +02007681" call Dret("s:NetrwMarkFileVimCmd")
7682endfun
7683
7684" ---------------------------------------------------------------------
7685" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7686" as the marked file(s) (toggles suffix presence)
7687" Uses the local marked file list.
7688fun! s:NetrwMarkHideSfx(islocal)
7689" call Dfunc("s:NetrwMarkHideSfx(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007690 let svpos = winsaveview()
7691" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007692 let curbufnr = bufnr("%")
7693
7694 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7695 if exists("s:netrwmarkfilelist_{curbufnr}")
7696
7697 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007698" call Decho("s:NetrwMarkFileCopy: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007699 " construct suffix pattern
7700 if fname =~ '\.'
7701 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7702 else
7703 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7704 endif
7705 " determine if its in the hiding list or not
7706 let inhidelist= 0
7707 if g:netrw_list_hide != ""
7708 let itemnum = 0
7709 let hidelist= split(g:netrw_list_hide,',')
7710 for hidepat in hidelist
7711 if sfxpat == hidepat
7712 let inhidelist= 1
7713 break
7714 endif
7715 let itemnum= itemnum + 1
7716 endfor
7717 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007718" call Decho("fname<".fname."> inhidelist=".inhidelist." sfxpat<".sfxpat.">",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02007719 if inhidelist
7720 " remove sfxpat from list
7721 call remove(hidelist,itemnum)
7722 let g:netrw_list_hide= join(hidelist,",")
7723 elseif g:netrw_list_hide != ""
7724 " append sfxpat to non-empty list
7725 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7726 else
7727 " set hiding list to sfxpat
7728 let g:netrw_list_hide= sfxpat
7729 endif
7730 endfor
7731
7732 " refresh the listing
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007733 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007734" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7735 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007736 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007737 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007738 endif
7739
7740" call Dret("s:NetrwMarkHideSfx")
7741endfun
7742
7743" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007744" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7745" Uses the global markfilelist
7746fun! s:NetrwMarkFileGrep(islocal)
7747" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007748 let svpos = winsaveview()
7749" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007750 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007751 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007752
7753 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007754" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007755 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007756" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007757 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007758 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007759" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007760 let netrwmarkfilelist= "*"
7761 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007762
Bram Moolenaarff034192013-04-24 18:51:19 +02007763 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007764" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007765 call inputsave()
7766 let pat= input("Enter pattern: ","")
7767 call inputrestore()
7768 let patbang = ""
7769 if pat =~ '^!'
7770 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007771 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007772 endif
7773 if pat =~ '^\i'
7774 let pat = escape(pat,'/')
7775 let pat = '/'.pat.'/'
7776 else
7777 let nonisi = pat[0]
7778 endif
7779
7780 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007781" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007782 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007783 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007784 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007785 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007786" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7787 return
7788 endtry
7789 echo "(use :cn, :cp to navigate, :Rex to return)"
7790
7791 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007792" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7793 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007794
7795 if exists("nonisi")
7796 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007797" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007798 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007799 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007800 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007801 endif
7802
7803" call Dret("s:NetrwMarkFileGrep")
7804endfun
7805
7806" ---------------------------------------------------------------------
7807" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7808" uses the global marked file list
7809" s:netrwmfloc= 0: target directory is remote
7810" = 1: target directory is local
7811fun! s:NetrwMarkFileMove(islocal)
7812" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007813 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007814 let curbufnr = bufnr("%")
7815
7816 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007817 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007818 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007819" call Dret("s:NetrwMarkFileMove")
7820 return
7821 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007822" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007823
Bram Moolenaar446cb832008-06-24 21:56:24 +00007824 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007825 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007826" call Dret("s:NetrwMarkFileCopy 0")
7827 return 0
7828 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007829" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007830
7831 if a:islocal && s:netrwmftgt_islocal
7832 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007833" call Decho("move from local to local",'~'.expand("<slnum>"))
7834" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007835 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007836 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7837" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7838 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007839 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007840 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007841" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007842 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007843 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007844" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007845 if g:netrw_localmovecmd =~ '\s'
7846 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7847 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7848 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007849" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007850 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007851 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007852" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007853 endif
7854 else
7855 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007856" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007857 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007858 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007859 if g:netrw_keepdir
7860 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7861 let fname= b:netrw_curdir."/".fname
7862 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007863 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007864 let fname= substitute(fname,'/','\\','g')
7865 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007866" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007867 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007868 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007869 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007870 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 +01007871 else
7872 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7873 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007874 break
7875 endif
7876 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007877
7878 elseif a:islocal && !s:netrwmftgt_islocal
7879 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007880" call Decho("move from local to remote",'~'.expand("<slnum>"))
7881" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007883 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007885 for fname in mflist
7886 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7887 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7888 endfor
7889 unlet mflist
7890
7891 elseif !a:islocal && s:netrwmftgt_islocal
7892 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007893" call Decho("move from remote to local",'~'.expand("<slnum>"))
7894" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007895 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007896 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007897" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007898 for fname in mflist
7899 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7900 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7901 endfor
7902 unlet mflist
7903
7904 elseif !a:islocal && !s:netrwmftgt_islocal
7905 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007906" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7907" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007908 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007909 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007910" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007911 for fname in mflist
7912 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7913 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7914 endfor
7915 unlet mflist
7916 endif
7917
7918 " -------
7919 " cleanup
7920 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007921" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007922
7923 " remove markings from local buffer
7924 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7925
7926 " refresh buffers
7927 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007928" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007929 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007930 endif
7931 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007932" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007933 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007934 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007935 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007936" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007937 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007938 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007939
Bram Moolenaar446cb832008-06-24 21:56:24 +00007940" call Dret("s:NetrwMarkFileMove")
7941endfun
7942
7943" ---------------------------------------------------------------------
7944" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7945" using the hardcopy command. Local marked-file list only.
7946fun! s:NetrwMarkFilePrint(islocal)
7947" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7948 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007949
7950 " sanity check
7951 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007952 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007953" call Dret("s:NetrwMarkFilePrint")
7954 return
7955 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007956" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7957 let curdir= s:NetrwGetCurdir(a:islocal)
7958
Bram Moolenaar446cb832008-06-24 21:56:24 +00007959 if exists("s:netrwmarkfilelist_{curbufnr}")
7960 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007961 call s:NetrwUnmarkList(curbufnr,curdir)
7962 for fname in netrwmarkfilelist
7963 if a:islocal
7964 if g:netrw_keepdir
7965 let fname= s:ComposePath(curdir,fname)
7966 endif
7967 else
7968 let fname= curdir.fname
7969 endif
7970 1split
7971 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007972" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007973 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007974" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007975 hardcopy
7976 q
7977 endfor
7978 2match none
7979 endif
7980" call Dret("s:NetrwMarkFilePrint")
7981endfun
7982
7983" ---------------------------------------------------------------------
7984" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7985" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007986" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007987fun! s:NetrwMarkFileRegexp(islocal)
7988" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7989
7990 " get the regular expression
7991 call inputsave()
7992 let regexp= input("Enter regexp: ","","file")
7993 call inputrestore()
7994
7995 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007996 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007997" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007998 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007999" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008000 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008001 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008002 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008003 else
8004 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008005 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008006 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008007" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008008
8009 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01008010 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02008011 if fname =~ '^'.fnameescape(curdir)
8012" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
8013 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
8014 else
8015" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
8016 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
8017 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008018 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008019
8020 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008021" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022
8023 " convert displayed listing into a filelist
8024 let eikeep = &ei
8025 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008026 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01008027 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008028" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008029 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008030 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02008031 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008032 sil NetrwKeepj norm! "ap
8033 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008034 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008035 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01008036 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00008037 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008038 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01008039 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008041 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01008042 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008043 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008044 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
8045 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008046 call histdel("/",-1)
8047 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008048 endif
8049 " convert regexp into the more usual glob-style format
8050 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008051" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008052 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01008053 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008054 let filelist= getline(1,line("$"))
8055 q!
8056 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008057 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008058 endfor
8059 unlet filelist
8060 let @a = areg
8061 let &ei = eikeep
8062 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008063 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064
8065" call Dret("s:NetrwMarkFileRegexp")
8066endfun
8067
8068" ---------------------------------------------------------------------
8069" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
8070" Uses the local marked file list.
8071fun! s:NetrwMarkFileSource(islocal)
8072" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
8073 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008074
8075 " sanity check
8076 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008077 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008078" call Dret("s:NetrwMarkFileSource")
8079 return
8080 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008081" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
8082 let curdir= s:NetrwGetCurdir(a:islocal)
8083
Bram Moolenaar446cb832008-06-24 21:56:24 +00008084 if exists("s:netrwmarkfilelist_{curbufnr}")
8085 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00008086 call s:NetrwUnmarkList(curbufnr,curdir)
8087 for fname in netrwmarkfilelist
8088 if a:islocal
8089 if g:netrw_keepdir
8090 let fname= s:ComposePath(curdir,fname)
8091 endif
8092 else
8093 let fname= curdir.fname
8094 endif
8095 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008096" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008097 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008098 endfor
8099 2match none
8100 endif
8101" call Dret("s:NetrwMarkFileSource")
8102endfun
8103
8104" ---------------------------------------------------------------------
8105" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
8106" Uses the global markfilelist
8107fun! s:NetrwMarkFileTag(islocal)
8108" call Dfunc("s:NetrwMarkFileTag(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008109 let svpos = winsaveview()
8110" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008111 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 let curbufnr = bufnr("%")
8113
Bram Moolenaarff034192013-04-24 18:51:19 +02008114 " sanity check
8115 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008116 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02008117" call Dret("s:NetrwMarkFileTag")
8118 return
8119 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008120" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008121
Bram Moolenaar446cb832008-06-24 21:56:24 +00008122 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008123" call Decho("s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
8124 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008125 call s:NetrwUnmarkAll()
8126
8127 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02008128
8129" call Decho("call system(".g:netrw_ctags." ".netrwmarkfilelist.")",'~'.expand("<slnum>"))
8130 call system(g:netrw_ctags." ".netrwmarkfilelist)
8131 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00008132 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
8133 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008134
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00008136 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01008137 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 let curdir= b:netrw_curdir
8139 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008140 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00008141 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008142" call Decho("curdir<".curdir."> path<".path.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008143 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008144 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008145 wq!
8146 endif
8147 2match none
8148 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008149" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8150 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008151 endif
8152
8153" call Dret("s:NetrwMarkFileTag")
8154endfun
8155
8156" ---------------------------------------------------------------------
8157" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008158" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02008159" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00008160" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02008161" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00008162fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008163" call Dfunc("s:NetrwMarkFileTgt(islocal=".a:islocal.")")
8164 let svpos = winsaveview()
8165" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008166 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008167 let hadtgt = exists("s:netrwmftgt")
8168 if !exists("w:netrw_bannercnt")
8169 let w:netrw_bannercnt= b:netrw_bannercnt
8170 endif
8171
8172 " set up target
8173 if line(".") < w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008174" call Decho("set up target: line(.) < w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008175 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
8176 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008177" call Decho("cursor in banner region, and target already is <".b:netrw_curdir.">: removing target",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008178 unlet s:netrwmftgt s:netrwmftgt_islocal
8179 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01008180 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02008181 endif
8182 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008183" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8184 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02008185" call Dret("s:NetrwMarkFileTgt : removed target")
8186 return
8187 else
8188 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008189" call Decho("inbanner: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008190 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008191
8192 else
8193 " get word under cursor.
8194 " * If directory, use it for the target.
8195 " * If file, use b:netrw_curdir for the target
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008196" call Decho("get word under cursor",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008197 let curword= s:NetrwGetWord()
8198 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008199 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008200 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008201" call Decho("local isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008202 elseif !a:islocal && tgtdir =~ '/$'
8203 let s:netrwmftgt = tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008204" call Decho("remote isdir: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008205 else
8206 let s:netrwmftgt = curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008207" call Decho("isfile: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008208 endif
8209 endif
8210 if a:islocal
8211 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
8212 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008213" call Decho("simplify: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008214 endif
8215 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008216 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008217 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
8218 endif
8219 let s:netrwmftgt_islocal= a:islocal
8220
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008221 " need to do refresh so that the banner will be updated
8222 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01008223 if g:netrw_fastbrowse <= 1
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008224" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse.", so refreshing all local netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008225 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008226 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008227" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008228 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008229 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop))
8230 else
8231 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
8232 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008233" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8234 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008235 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008236 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00008237 endif
8238
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008239" call Decho("getmatches=".string(getmatches()),'~'.expand("<slnum>"))
8240" call Decho("s:netrwmarkfilelist=".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008241" call Dret("s:NetrwMarkFileTgt : netrwmftgt<".(exists("s:netrwmftgt")? s:netrwmftgt : "").">")
8242endfun
8243
8244" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008245" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
8246fun! s:NetrwGetCurdir(islocal)
8247" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
8248
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008249 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008250 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
8251" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
8252 elseif !exists("b:netrw_curdir")
8253 let b:netrw_curdir= getcwd()
8254" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
8255 endif
8256
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008257" 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 +01008258 if b:netrw_curdir !~ '\<\a\{3,}://'
8259 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008260" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008261 if g:netrw_keepdir == 0
8262 call s:NetrwLcd(curdir)
8263 endif
8264 endif
8265
8266" call Dret("s:NetrwGetCurdir <".curdir.">")
8267 return b:netrw_curdir
8268endfun
8269
8270" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00008271" s:NetrwOpenFile: query user for a filename and open it {{{2
8272fun! s:NetrwOpenFile(islocal)
8273" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008274 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00008275 call inputsave()
8276 let fname= input("Enter filename: ")
8277 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008278" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
8279
8280 " determine if Lexplore is in use
8281 if exists("t:netrw_lexbufnr")
8282 " check if t:netrw_lexbufnr refers to a netrw window
8283" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
8284 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
8285 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
8286" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
8287 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
8288 exe "NetrwKeepj e ".fnameescape(fname)
8289 let @@= ykeep
8290" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
8291 endif
8292 endif
8293
8294 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00008295 if fname !~ '[/\\]'
8296 if exists("b:netrw_curdir")
8297 if exists("g:netrw_quiet")
8298 let netrw_quiet_keep = g:netrw_quiet
8299 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008300 let g:netrw_quiet = 1
8301 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008302 let s:rexposn_{bufnr("%")}= winsaveview()
8303" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008304 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008305 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008306 else
8307 exe "e ".fnameescape(b:netrw_curdir."/".fname)
8308 endif
8309 if exists("netrw_quiet_keep")
8310 let g:netrw_quiet= netrw_quiet_keep
8311 else
8312 unlet g:netrw_quiet
8313 endif
8314 endif
8315 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008316 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00008317 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008318 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00008319" call Dret("s:NetrwOpenFile")
8320endfun
8321
8322" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008323" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
8324" For the mapping to this function be made via
8325" netrwPlugin, you'll need to have had
8326" g:netrw_usetab set to non-zero.
8327fun! netrw#Shrink()
8328" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
8329 let curwin = winnr()
8330 let wiwkeep = &wiw
8331 set wiw=1
8332
8333 if &ft == "netrw"
8334 if winwidth(0) > g:netrw_wiw
8335 let t:netrw_winwidth= winwidth(0)
8336 exe "vert resize ".g:netrw_wiw
8337 wincmd l
8338 if winnr() == curwin
8339 wincmd h
8340 endif
8341" call Decho("vert resize 0",'~'.expand("<slnum>"))
8342 else
8343 exe "vert resize ".t:netrw_winwidth
8344" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8345 endif
8346
8347 elseif exists("t:netrw_lexbufnr")
8348 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
8349 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
8350 let t:netrw_winwidth= winwidth(0)
8351 exe "vert resize ".g:netrw_wiw
8352 wincmd l
8353 if winnr() == curwin
8354 wincmd h
8355 endif
8356" call Decho("vert resize 0",'~'.expand("<slnum>"))
8357 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
8358 exe "vert resize ".t:netrw_winwidth
8359" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
8360 else
8361 call netrw#Lexplore(0,0)
8362 endif
8363
8364 else
8365 call netrw#Lexplore(0,0)
8366 endif
8367 let wiw= wiwkeep
8368
8369" call Dret("netrw#Shrink")
8370endfun
8371
8372" ---------------------------------------------------------------------
8373" s:NetSortSequence: allows user to edit the sorting sequence {{{2
8374fun! s:NetSortSequence(islocal)
8375" call Dfunc("NetSortSequence(islocal=".a:islocal.")")
8376
8377 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008378 let svpos= winsaveview()
8379" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008380 call inputsave()
8381 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
8382 call inputrestore()
8383
8384 " refresh the listing
8385 let g:netrw_sort_sequence= newsortseq
8386 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008387" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8388 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008389 let @@= ykeep
8390
8391" call Dret("NetSortSequence")
8392endfun
8393
8394" ---------------------------------------------------------------------
8395" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
8396" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02008397" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00008398fun! s:NetrwUnmarkList(curbufnr,curdir)
8399" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
8400
8401 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008402 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008403 for mfile in s:netrwmarkfilelist_{a:curbufnr}
8404 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
8405 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
8406 call remove(s:netrwmarkfilelist,idx) " remove from global list
8407 endfor
8408 if s:netrwmarkfilelist == []
8409 unlet s:netrwmarkfilelist
8410 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008411
Bram Moolenaar446cb832008-06-24 21:56:24 +00008412 " getting rid of the local marked-file lists is easy
8413 unlet s:netrwmarkfilelist_{a:curbufnr}
8414 endif
8415 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
8416 unlet s:netrwmarkfilemtch_{a:curbufnr}
8417 endif
8418 2match none
8419" call Dret("s:NetrwUnmarkList")
8420endfun
8421
8422" ---------------------------------------------------------------------
8423" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
8424fun! s:NetrwUnmarkAll()
8425" call Dfunc("s:NetrwUnmarkAll()")
8426 if exists("s:netrwmarkfilelist")
8427 unlet s:netrwmarkfilelist
8428 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02008429 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008430 2match none
8431" call Dret("s:NetrwUnmarkAll")
8432endfun
8433
8434" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008435" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008436fun! s:NetrwUnmarkAll2()
8437" call Dfunc("s:NetrwUnmarkAll2()")
8438 redir => netrwmarkfilelist_let
8439 let
8440 redir END
8441 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008442 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00008443 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
8444 for flist in netrwmarkfilelist_list
8445 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
8446 unlet s:netrwmarkfilelist_{curbufnr}
8447 unlet s:netrwmarkfilemtch_{curbufnr}
8448 endfor
8449" call Dret("s:NetrwUnmarkAll2")
8450endfun
8451
8452" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008453" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
8454"
8455" Marked files are in two types of lists:
8456" s:netrwmarkfilelist -- holds complete paths to all marked files
8457" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
8458"
8459" Marked files suitable for use with 2match are in:
8460" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00008461fun! s:NetrwUnMarkFile(islocal)
8462" call Dfunc("s:NetrwUnMarkFile(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008463 let svpos = winsaveview()
8464" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008465 let curbufnr = bufnr("%")
8466
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008467 " unmark marked file list
8468 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
8469 if exists("s:netrwmarkfilelist")
8470" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008471 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00008472 endif
8473
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008474 let ibuf= 1
8475 while ibuf < bufnr("$")
8476 if exists("s:netrwmarkfilelist_".ibuf)
8477 unlet s:netrwmarkfilelist_{ibuf}
8478 unlet s:netrwmarkfilemtch_{ibuf}
8479 endif
8480 let ibuf = ibuf + 1
8481 endwhile
8482 2match none
8483
Bram Moolenaar446cb832008-06-24 21:56:24 +00008484" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008485"call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
8486call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008487" call Dret("s:NetrwUnMarkFile")
8488endfun
8489
8490" ---------------------------------------------------------------------
8491" s:NetrwMenu: generates the menu for gvim and netrw {{{2
8492fun! s:NetrwMenu(domenu)
8493
8494 if !exists("g:NetrwMenuPriority")
8495 let g:NetrwMenuPriority= 80
8496 endif
8497
Bram Moolenaaradc21822011-04-01 18:03:16 +02008498 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00008499" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
8500
8501 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008502" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008503 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02008504 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
8505 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
8506 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
8507 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
8508 if g:netrw_dirhistmax > 0
8509 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
8510 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
8511 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
8512 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
8513 else
8514 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
8515 endif
8516 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
8517 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
8518 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
8519 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
8520 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
8521 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
8522 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
8523 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
8524 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
8525 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
8526 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
8527 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
8528 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
8529 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
8530 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 +01008531 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 +02008532 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
8533 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
8534 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
8535 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
8536 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
8537 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
8538 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
8539 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
8540 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
8541 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
8542 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
8543 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
8544 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
8545 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
8546 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
8547 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
8548 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
8549 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
8550 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
8551 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
8552 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
8553 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
8554 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
8555 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
8556 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
8557 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
8558 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
8559 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
8560 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
8561 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>'
8562 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>'
8563 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>'
8564 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
8565 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>'
8566 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>'
8567 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 +01008568 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 +02008569 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
8570 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008571 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02008572 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
8573 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574
8575 elseif !a:domenu
8576 let s:netrwcnt = 0
8577 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008578 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008579 exe curwin."wincmd w"
8580
8581 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008582" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008583 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008584" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008585 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008586 endif
8587 endif
8588" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008589 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008590 endif
8591
8592endfun
8593
8594" ---------------------------------------------------------------------
8595" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8596" Used by the O maps (as <SID>NetrwObtain())
8597fun! s:NetrwObtain(islocal)
8598" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8599
Bram Moolenaar97d62492012-11-15 21:28:22 +01008600 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008601 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008602 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008603 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008604 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8605 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008606 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008608 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008609
8610" call Dret("NetrwObtain")
8611endfun
8612
8613" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008614" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8615" If there's only one window, then the window will first be split.
8616" Returns:
8617" choice = 0 : didn't have to choose
8618" choice = 1 : saved modified file in window first
8619" choice = 2 : didn't save modified file, opened window
8620" choice = 3 : cancel open
8621fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008622" call Dfunc("s:NetrwPrevWinOpen(islocal=".a:islocal.") win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623
Bram Moolenaar97d62492012-11-15 21:28:22 +01008624 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008625 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008626 let curdir = b:netrw_curdir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008627" call Decho("COMBAK#1: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008628
8629 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008630 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008631 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008632" call Decho("origwin#".origwin." lastwinnr#".lastwinnr)
8633" call Decho("COMBAK#2: mod=".&mod." win#".winnr())
8634 let curword = s:NetrwGetWord()
8635 let choice = 0
8636 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
8637" call Decho("COMBAK#3: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008638 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaar71badf92023-04-22 22:40:14 +01008639" call Decho("COMBAK#4: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008640 let curdir = s:treedir
Bram Moolenaar71badf92023-04-22 22:40:14 +01008641" call Decho("COMBAK#5: mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008642" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008643" call Decho("COMBAK#6: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008644
Bram Moolenaar8d043172014-01-23 14:24:41 +01008645 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008646 if lastwinnr == 1
8647 " if only one window, open a new one first
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008648" 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 +02008649 " g:netrw_preview=0: preview window shown in a horizontally split window
8650 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008652 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008653 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008654" call Decho("exe ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008655 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008656 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008657 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008658 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008659" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +02008660 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008661 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008662 let didsplit = 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008663" call Decho("did split",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664
8665 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01008666" call Decho("COMBAK#7: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008667 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar71badf92023-04-22 22:40:14 +01008668" call Decho("COMBAK#8: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008669 let eikeep= &ei
Bram Moolenaar71badf92023-04-22 22:40:14 +01008670" call Decho("COMBAK#9: mod=".&mod." win#".winnr())
Bram Moolenaara6878372014-03-22 21:02:50 +01008671 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01008672" call Decho("COMBAK#10: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008673 wincmd p
Bram Moolenaar71badf92023-04-22 22:40:14 +01008674" call Decho("COMBAK#11: mod=".&mod)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008675" call Decho("wincmd p (now in win#".winnr().") curdir<".curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008676" call Decho("COMBAK#12: mod=".&mod)
8677
8678 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8679 " whoops -- user trying to open file in the Lexplore window.
8680 " Use Lexplore's opening-file window instead.
8681" call Decho("whoops -- user trying to open file in Lexplore Window. Use win#".g:netrw_chgwin." instead")
8682" exe g:netrw_chgwin."wincmd w"
8683 wincmd p
8684 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
8685 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008686
8687 " prevwinnr: the window number of the "prev" window
8688 " prevbufnr: the buffer number of the buffer in the "prev" window
8689 " bnrcnt : the qty of windows open on the "prev" buffer
8690 let prevwinnr = winnr()
8691 let prevbufnr = bufnr("%")
8692 let prevbufname = bufname("%")
8693 let prevmod = &mod
8694 let bnrcnt = 0
Bram Moolenaar71badf92023-04-22 22:40:14 +01008695" call Decho("COMBAK#13: mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008696 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008697" 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 +01008698" call Decho("COMBAK#14: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008699
8700 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701 " and it doesn't appear in any other extant window, then ask the
8702 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008703 if prevmod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008704" call Decho("detected that prev window's buffer has been modified: prevbufnr=".prevbufnr." winnr()#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008705 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008706" call Decho("prevbufnr=".prevbufnr." bnrcnt=".bnrcnt." buftype=".&bt." winnr()=".winnr()." prevwinnr#".prevwinnr,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008707 exe prevwinnr."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01008708" call Decho("COMBAK#15: mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01008709
8710 if bnrcnt == 1 && &hidden == 0
8711 " only one copy of the modified buffer in a window, and
8712 " hidden not set, so overwriting will lose the modified file. Ask first...
8713 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008714" call Decho("prevbufname<".prevbufname."> choice=".choice." current-winnr#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008715 let &ei= eikeep
Bram Moolenaar71badf92023-04-22 22:40:14 +01008716" call Decho("COMBAK#16: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008717
8718 if choice == 1
8719 " Yes -- write file & then browse
8720 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008721 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008722 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008723 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008724 exe origwin."wincmd w"
8725 let &ei = eikeep
8726 let @@ = ykeep
8727" call Dret("s:NetrwPrevWinOpen ".choice." : unable to write <".prevbufname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008728 return choice
8729 endif
8730
8731 elseif choice == 2
8732 " No -- don't worry about changed file, just browse anyway
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008733" call Decho("don't worry about chgd file, just browse anyway (winnr($)#".winnr("$").")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008734 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008735
8736 else
8737 " Cancel -- don't do this
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008738" call Decho("cancel, don't browse, switch to win#".origwin,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008739 exe origwin."wincmd w"
8740 let &ei= eikeep
8741 let @@ = ykeep
8742" call Dret("s:NetrwPrevWinOpen ".choice." : cancelled")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008743 return choice
8744 endif
8745 endif
8746 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008747 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008748 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01008749" call Decho("COMBAK#17: mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008750
8751 " restore b:netrw_curdir (window split/enew may have lost it)
8752 let b:netrw_curdir= curdir
8753 if a:islocal < 2
8754 if a:islocal
8755 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword))
8756 else
8757 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword))
8758 endif
8759 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008760 let @@= ykeep
Bram Moolenaar8d043172014-01-23 14:24:41 +01008761" call Dret("s:NetrwPrevWinOpen ".choice)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008762 return choice
8763endfun
8764
8765" ---------------------------------------------------------------------
8766" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8767" Always assumed to be local -> remote
8768" call s:NetrwUpload(filename, target)
8769" call s:NetrwUpload(filename, target, fromdirectory)
8770fun! s:NetrwUpload(fname,tgt,...)
8771" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8772
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008773 if a:tgt =~ '^\a\{3,}://'
8774 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008775 else
8776 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8777 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008778" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008779
8780 if a:0 > 0
8781 let fromdir= a:1
8782 else
8783 let fromdir= getcwd()
8784 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008785" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008786
8787 if type(a:fname) == 1
8788 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008789" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008790 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008791" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8792 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8793" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008794 if a:tgt =~ '/$'
8795 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008796" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008797 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008798 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008799" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008800 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008801" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008802 endif
8803 q!
8804
8805 elseif type(a:fname) == 3
8806 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008807" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008808 let curdir= getcwd()
8809 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008810 if s:NetrwLcd(fromdir)
8811" call Dret("s:NetrwUpload : lcd failure")
8812 return
8813 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008814 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008815 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008816 if exists("g:netrw_port") && g:netrw_port != ""
8817 let useport= " ".g:netrw_scpport." ".g:netrw_port
8818 else
8819 let useport= ""
8820 endif
8821 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8822 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008823 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 +02008824 if s:NetrwLcd(curdir)
8825" call Dret("s:NetrwUpload : lcd failure")
8826 return
8827 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008828
8829 elseif a:tgt =~ '^ftp:'
8830 call s:NetrwMethod(a:tgt)
8831
8832 if b:netrw_method == 2
8833 " handle uploading a list of files via ftp+.netrc
8834 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008835 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008836" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008837
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008838 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008839" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008840
8841 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008842 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008843" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008844 endif
8845
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008846 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008847" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008848
Bram Moolenaaradc21822011-04-01 18:03:16 +02008849 if tgtdir == ""
8850 let tgtdir= '/'
8851 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008852 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008853" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854
8855 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008856 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8857" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 endfor
8859
8860 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008861 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 +00008862 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008863" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8864 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008865 endif
8866 " 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 +01008867 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008868 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008869 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8870 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8871 else
8872 bw!|q
8873 endif
8874
8875 elseif b:netrw_method == 3
8876 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8877 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008878 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008879 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008880 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008881
8882 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008883 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008884" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008885 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008886 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008887" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008888 endif
8889
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008890 if exists("g:netrw_uid") && g:netrw_uid != ""
8891 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008892 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008893" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008894 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008895 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008896 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008897" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008898 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008899 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008900" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008901 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 endif
8903
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008904 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008905" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008906
8907 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008908 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008909" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008910 endif
8911
8912 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008913 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008914" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 endif
8916
8917 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008918 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008919" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008920 endfor
8921
8922 " perform ftp:
8923 " -i : turns off interactive prompting from ftp
8924 " -n unix : DON'T use <.netrc>, even though it exists
8925 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008926 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008927 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008928 " 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 +01008929 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008930 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008931 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8932 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008933 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008934 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8935 let &debug = debugkeep
8936 let mod = 1
8937 else
8938 bw!|q
8939 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008940 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008941" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008942 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008943 endif
8944 else
8945 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8946 endif
8947 endif
8948
8949" call Dret("s:NetrwUpload")
8950endfun
8951
8952" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008953" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008954fun! s:NetrwPreview(path) range
8955" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008956" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8957" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008958 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008959 NetrwKeepj call s:NetrwOptionsSave("s:")
8960 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8961 NetrwKeepj call s:NetrwOptionsSafe(1)
8962 else
8963 NetrwKeepj call s:NetrwOptionsSafe(0)
8964 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008965 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008966" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008967 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008968" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8969 if g:netrw_preview
8970 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008971 let pvhkeep = &pvh
8972 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8973 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008974" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8975 else
8976 " horizontal split
8977 let pvhkeep = &pvh
8978 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8979 let &pvh = winheight(0) - winsz
8980" 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 +02008981 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008982 " g:netrw_preview g:netrw_alto
8983 " 1 : vert 1: top -- preview window is vertically split off and on the left
8984 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8985 " 0 : 1: top -- preview window is horizontally split off and on the top
8986 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8987 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008988 " 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 +02008989 " the BufEnter event set up in netrwPlugin.vim
8990" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8991 let eikeep = &ei
8992 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008993 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008994 let &ei= eikeep
8995" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008996 if exists("pvhkeep")
8997 let &pvh= pvhkeep
8998 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008999 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009000 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009001 endif
9002 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009003 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 +00009004 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009005 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01009006 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009007" call Dret("NetrwPreview")
9008endfun
9009
9010" ---------------------------------------------------------------------
9011" s:NetrwRefresh: {{{2
9012fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009013" 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 +00009014 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02009015 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009016" call Decho("setl ma noro",'~'.expand("<slnum>"))
9017" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009018 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02009019 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
9020 if !exists("w:netrw_treetop")
9021 if exists("b:netrw_curdir")
9022 let w:netrw_treetop= b:netrw_curdir
9023 else
9024 let w:netrw_treetop= getcwd()
9025 endif
9026 endif
9027 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
9028 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009029
9030 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009031 let screenposn = winsaveview()
9032" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009033
9034" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
9035" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
9036 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009037 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009038 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009039 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009040 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009041 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02009042
9043 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009044" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
9045 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009046
9047 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02009048 if has("syntax") && exists("g:syntax_on") && g:syntax_on
9049 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
9050" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
9051 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
9052 else
9053" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
9054 2match none
9055 endif
9056 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009057
Bram Moolenaar97d62492012-11-15 21:28:22 +01009058" restore
9059 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009060" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009061endfun
9062
9063" ---------------------------------------------------------------------
9064" s:NetrwRefreshDir: refreshes a directory by name {{{2
9065" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01009066" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009067fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009068" call Dfunc("s:NetrwRefreshDir(islocal=".a:islocal." dirname<".a:dirname.">) g:netrw_fastbrowse=".g:netrw_fastbrowse)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009069 if g:netrw_fastbrowse == 0
9070 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009071" call Decho("slowest mode: keep buffers refreshed, local or remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009073" call Decho("tgtwin= bufwinnr(".a:dirname.")=".tgtwin,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074
9075 if tgtwin > 0
9076 " tgtwin is being displayed, so refresh it
9077 let curwin= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009078" call Decho("refresh tgtwin#".tgtwin." (curwin#".curwin.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009079 exe tgtwin."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009080 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081 exe curwin."wincmd w"
9082
9083 elseif bufnr(a:dirname) > 0
9084 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009085" call Decho("bd bufnr(".a:dirname.")=".bn,'~'.expand("<slnum>"))
9086 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00009087 endif
9088
9089 elseif g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009090" call Decho("medium-speed mode: refresh local buffers only",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009091 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009092 endif
9093" call Dret("s:NetrwRefreshDir")
9094endfun
9095
9096" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02009097" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
9098" window number to do its editing in.
9099" Supports [count]C where the count, if present, is used to specify
9100" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009101fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02009102" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009103 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009104" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009105 if a:1 == "" " :NetrwC win#
9106 let g:netrw_chgwin= winnr()
9107 else " :NetrwC
9108 let g:netrw_chgwin= a:1
9109 endif
9110 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02009111 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009112 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02009113 let g:netrw_chgwin= winnr()
9114 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009115 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009116" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02009117endfun
9118
9119" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009120" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
9121" What this function does is to compute a priority for the patterns
9122" in the g:netrw_sort_sequence. It applies a substitute to any
9123" "files" that satisfy each pattern, putting the priority / in
9124" front. An "*" pattern handles the default priority.
9125fun! s:NetrwSetSort()
9126" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009127 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009128 if w:netrw_liststyle == s:LONGLIST
9129 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
9130 else
9131 let seqlist = g:netrw_sort_sequence
9132 endif
9133 " sanity check -- insure that * appears somewhere
9134 if seqlist == ""
9135 let seqlist= '*'
9136 elseif seqlist !~ '\*'
9137 let seqlist= seqlist.',*'
9138 endif
9139 let priority = 1
9140 while seqlist != ""
9141 if seqlist =~ ','
9142 let seq = substitute(seqlist,',.*$','','e')
9143 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
9144 else
9145 let seq = seqlist
9146 let seqlist = ""
9147 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009148 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01009149 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009150 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01009151 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009152 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01009153 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009154 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009155" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009156
9157 " sanity check
9158 if w:netrw_bannercnt > line("$")
9159 " apparently no files were left after a Hiding pattern was used
9160" call Dret("SetSort : no files left after hiding")
9161 return
9162 endif
9163 if seq == '*'
9164 let starpriority= spriority
9165 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009166 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01009167 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009168 " sometimes multiple sorting patterns will match the same file or directory.
9169 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009170 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
9171 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009172 endif
9173 let priority = priority + 1
9174 endwhile
9175 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009176 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
9177 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009178 endif
9179
9180 " Following line associated with priority -- items that satisfy a priority
9181 " pattern get prefixed by ###/ which permits easy sorting by priority.
9182 " Sometimes files can satisfy multiple priority patterns -- only the latest
9183 " priority pattern needs to be retained. So, at this point, these excess
9184 " priority prefixes need to be removed, but not directories that happen to
9185 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009186 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
9187 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01009188 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009189
9190" call Dret("SetSort")
9191endfun
9192
Bram Moolenaarff034192013-04-24 18:51:19 +02009193" ---------------------------------------------------------------------
9194" s:NetrwSetTgt: sets the target to the specified choice index {{{2
9195" Implements [count]Tb (bookhist<b>)
9196" [count]Th (bookhist<h>)
9197" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009198fun! s:NetrwSetTgt(islocal,bookhist,choice)
9199" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02009200
9201 if a:bookhist == 'b'
9202 " supports choosing a bookmark as a target using a qb-generated list
9203 let choice= a:choice - 1
9204 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01009205 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02009206 else
9207 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
9208 endif
9209
9210 elseif a:bookhist == 'h'
9211 " supports choosing a history stack entry as a target using a qb-generated list
9212 let choice= (a:choice % g:netrw_dirhistmax) + 1
9213 if exists("g:netrw_dirhist_".choice)
9214 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01009215 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02009216 else
9217 echomsg "Sorry, history#".a:choice." not available!"
9218 endif
9219 endif
9220
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009221 " refresh the display
9222 if !exists("b:netrw_curdir")
9223 let b:netrw_curdir= getcwd()
9224 endif
9225 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
9226
Bram Moolenaarff034192013-04-24 18:51:19 +02009227" call Dret("s:NetrwSetTgt")
9228endfun
9229
Bram Moolenaar446cb832008-06-24 21:56:24 +00009230" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02009231" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00009232fun! s:NetrwSortStyle(islocal)
9233" call Dfunc("s:NetrwSortStyle(islocal=".a:islocal.") netrw_sort_by<".g:netrw_sort_by.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009234 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009235 let svpos= winsaveview()
9236" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009237
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009238 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 +01009239 NetrwKeepj norm! 0
9240 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009241" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
9242 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009243
9244" call Dret("s:NetrwSortStyle : netrw_sort_by<".g:netrw_sort_by.">")
9245endfun
9246
9247" ---------------------------------------------------------------------
9248" s:NetrwSplit: mode {{{2
9249" =0 : net and o
9250" =1 : net and t
9251" =2 : net and v
9252" =3 : local and o
9253" =4 : local and t
9254" =5 : local and v
9255fun! s:NetrwSplit(mode)
9256" call Dfunc("s:NetrwSplit(mode=".a:mode.") alto=".g:netrw_alto." altv=".g:netrw_altv)
9257
Bram Moolenaar97d62492012-11-15 21:28:22 +01009258 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00009259 call s:SaveWinVars()
9260
9261 if a:mode == 0
9262 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009263 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009264 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009265" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009266 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009267 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009268 NetrwKeepj call s:RestoreWinVars()
9269 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009270 unlet s:didsplit
9271
9272 elseif a:mode == 1
9273 " remote and t
Bram Moolenaar5c736222010-01-06 20:54:52 +01009274 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009275" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009276 tabnew
9277 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009278 NetrwKeepj call s:RestoreWinVars()
9279 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009280 unlet s:didsplit
9281
9282 elseif a:mode == 2
9283 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009284 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009285 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009286" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009287 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009288 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009289 NetrwKeepj call s:RestoreWinVars()
9290 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009291 unlet s:didsplit
9292
9293 elseif a:mode == 3
9294 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02009295 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009296 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009297" call Decho("exe ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009298 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009299 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009300 NetrwKeepj call s:RestoreWinVars()
9301 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009302 unlet s:didsplit
9303
9304 elseif a:mode == 4
9305 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00009306 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01009307 let eikeep = &ei
9308 let netrw_winnr = winnr()
9309 let netrw_line = line(".")
9310 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009311 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01009312 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01009313 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009314 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9315 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009316 let &ei = eikeep
9317 let netrw_curdir = s:NetrwTreeDir(0)
9318" call Decho("tabnew",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009319 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01009320 let b:netrw_curdir = netrw_curdir
9321 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009322 NetrwKeepj call s:RestoreWinVars()
9323 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009324 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01009325 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009326 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
9327 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01009328 let &ei= eikeep
9329 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009330 unlet s:didsplit
9331
9332 elseif a:mode == 5
9333 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02009334 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02009335 if winsz == 0|let winsz= ""|endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009336" call Decho("exe ".(g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v",'~'.expand("<slnum>"))
Bram Moolenaar251e1912011-06-19 05:09:16 +02009337 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009338 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009339 NetrwKeepj call s:RestoreWinVars()
9340 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord()))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009341 unlet s:didsplit
9342
9343 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009344 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009345 endif
9346
Bram Moolenaar97d62492012-11-15 21:28:22 +01009347 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00009348" call Dret("s:NetrwSplit")
9349endfun
9350
9351" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02009352" s:NetrwTgtMenu: {{{2
9353fun! s:NetrwTgtMenu()
9354 if !exists("s:netrw_menucnt")
9355 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009356 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02009357" call Dfunc("s:NetrwTgtMenu()")
9358
9359 " the following test assures that gvim is running, has menus available, and has menus enabled.
9360 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
9361 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009362" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009363 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
9364 endif
9365 if !exists("s:netrw_initbookhist")
9366 call s:NetrwBookHistRead()
9367 endif
9368
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009369 " try to cull duplicate entries
9370 let tgtdict={}
9371
Bram Moolenaarff034192013-04-24 18:51:19 +02009372 " target bookmarked places
9373 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009374" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009375 let cnt= 1
9376 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009377 if has_key(tgtdict,bmd)
9378 let cnt= cnt + 1
9379 continue
9380 endif
9381 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009382 let ebmd= escape(bmd,g:netrw_menu_escape)
9383 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009384" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009385 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 +02009386 let cnt= cnt + 1
9387 endfor
9388 endif
9389
9390 " target directory browsing history
9391 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009392" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02009393 let histcnt = 1
9394 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02009395 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02009396 if exists("g:netrw_dirhist_{histcnt}")
9397 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009398 if has_key(tgtdict,histentry)
9399 let histcnt = histcnt + 1
9400 continue
9401 endif
9402 let tgtdict[histentry] = histcnt
9403 let ehistentry = escape(histentry,g:netrw_menu_escape)
9404" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009405 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 +02009406 endif
9407 let histcnt = histcnt + 1
9408 endwhile
9409 endif
9410 endif
9411" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009412endfun
9413
9414" ---------------------------------------------------------------------
9415" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
9416" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009417fun! s:NetrwTreeDir(islocal)
9418" 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 +02009419" call Decho("Determine tree directory given current cursor position")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009420" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
9421" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
9422" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009423" call Decho("current line<".getline(".").">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009424
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009425 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009426 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009427" 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 +01009428 let treedir= s:treedir
9429 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009430 unlet s:prevwinopen
9431" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009432 return treedir
9433 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009434 if exists("s:prevwinopen")
9435 unlet s:prevwinopen
9436 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009437" call Decho("COMBAK#18 : mod=".&mod." win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009438
Bram Moolenaar8d043172014-01-23 14:24:41 +01009439 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
9440 let b:netrw_curdir= getcwd()
9441 endif
9442 let treedir = b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009443" call Decho("set initial treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009444" call Decho("COMBAK#19 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009445
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009446 let s:treecurpos= winsaveview()
9447" call Decho("saving posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009448" call Decho("COMBAK#20 : mod=".&mod." win#".winnr())
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009449
9450 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009451" call Decho("w:netrw_liststyle is TREELIST:",'~'.expand("<slnum>"))
9452" call Decho("line#".line(".")." getline(.)<".getline('.')."> treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009453" call Decho("COMBAK#21 : mod=".&mod." win#".winnr())
Bram Moolenaar5c736222010-01-06 20:54:52 +01009454
9455 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009456 let curline= substitute(getline('.'),"\t -->.*$",'','')
9457 if curline =~ '/$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009458" call Decho("extract tree subdirectory from current line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009459 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009460" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9461 elseif curline =~ '@$'
9462" call Decho("handle symbolic link from current line",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009463 let potentialdir= resolve(substitute(substitute(getline('.'),'@.*$','','e'),'^|*\s*','','e'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009464" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009465 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009466" call Decho("do not extract tree subdirectory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009467 let treedir= ""
9468 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009469" call Decho("COMBAK#22 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009470
9471 " detect user attempting to close treeroot
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009472" call Decho("check if user is attempting to close treeroot",'~'.expand("<slnum>"))
9473" call Decho(".win#".winnr()." buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009474" call Decho(".getline(".line(".").")<".getline('.').'> '.((getline('.') =~# '^'.s:treedepthstring)? '=~#' : '!~').' ^'.s:treedepthstring,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009475 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009476" call Decho(".user may have attempted to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009477 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009478" call Decho(".force refresh: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9479 sil! NetrwKeepj %d _
9480" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009481 return b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01009482" else " Decho
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009483" call Decho(".user not attempting to close treeroot",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009484 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009485" call Decho("COMBAK#23 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009486
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009487" call Decho("islocal=".a:islocal." curline<".curline.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009488" call Decho("potentialdir<".potentialdir."> isdir=".isdirectory(potentialdir),'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009489" call Decho("COMBAK#24 : mod=".&mod." win#".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009490
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009491 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
9492" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
9493" let newdir = w:netrw_treetop.'/'.potentialdir
9494" " call Decho("apply NetrwTreePath to newdir<".newdir.">",'~'.expand("<slnum>"))
9495" let treedir = s:NetrwTreePath(newdir)
9496" let w:netrw_treetop = newdir
9497" " call Decho("newdir <".newdir.">",'~'.expand("<slnum>"))
9498" else
9499" call Decho("apply NetrwTreePath to treetop<".w:netrw_treetop.">",'~'.expand("<slnum>"))
Christian Brabandt56b7da32024-02-29 17:48:14 +01009500 if a:islocal && curline =~ '@$'
9501 if isdirectory(s:NetrwFile(potentialdir))
9502 let treedir = w:netrw_treetop.'/'.potentialdir.'/'
9503 let w:netrw_treetop = treedir
9504 endif
9505 else
9506 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
9507 let treedir = s:NetrwTreePath(w:netrw_treetop)
9508 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009509 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01009510" call Decho("COMBAK#25 : mod=".&mod." win#".winnr())
Bram Moolenaar8d043172014-01-23 14:24:41 +01009511
9512 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00009513 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009514" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01009515" call Decho("COMBAK#26 : mod=".&mod." win#".winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +00009516
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009517" call Dret("s:NetrwTreeDir <".treedir."> : (side effect) s:treecurpos<".(exists("s:treecurpos")? string(s:treecurpos) : 'n/a').">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00009518 return treedir
9519endfun
9520
9521" ---------------------------------------------------------------------
9522" s:NetrwTreeDisplay: recursive tree display {{{2
9523fun! s:NetrwTreeDisplay(dir,depth)
9524" call Dfunc("NetrwTreeDisplay(dir<".a:dir."> depth<".a:depth.">)")
9525
9526 " insure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02009527 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00009528
9529 " install ../ and shortdir
9530 if a:depth == ""
9531 call setline(line("$")+1,'../')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009532" call Decho("setline#".line("$")." ../ (depth is zero)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009533 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009534 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009535 if a:dir == w:netrw_treetop
9536 let shortdir= a:dir
9537 else
9538 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
9539 endif
9540 call setline(line("$")+1,a:depth.shortdir)
9541 else
9542 let shortdir= substitute(a:dir,'^.*/','','e')
9543 call setline(line("$")+1,a:depth.shortdir.'/')
9544 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009545" call Decho("setline#".line("$")." shortdir<".a:depth.shortdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009546 " append a / to dir if its missing one
9547 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00009548
9549 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01009550 let depth= s:treedepthstring.a:depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009551" call Decho("display subtrees with depth<".depth."> and current leaves",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009552
Bram Moolenaar85850f32019-07-19 22:05:51 +02009553 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
9554 if g:netrw_hide == 1
9555 " hide given patterns
9556 let listhide= split(g:netrw_list_hide,',')
9557" call Decho("listhide=".string(listhide))
9558 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009559 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009560 endfor
9561
9562 elseif g:netrw_hide == 2
9563 " show given patterns (only)
9564 let listhide= split(g:netrw_list_hide,',')
9565" call Decho("listhide=".string(listhide))
9566 let entries=[]
9567 for entry in w:netrw_treedict[dir]
9568 for pat in listhide
9569 if entry =~ pat
9570 call add(entries,entry)
9571 break
9572 endif
9573 endfor
9574 endfor
9575 let w:netrw_treedict[dir]= entries
9576 endif
9577 if depth != ""
9578 " always remove "." and ".." entries when there's depth
9579 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
9580 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
9581 endif
9582
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009583" call Decho("for every entry in w:netrw_treedict[".dir."]=".string(w:netrw_treedict[dir]),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009584 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009585 if dir =~ '/$'
9586 let direntry= substitute(dir.entry,'[@/]$','','e')
9587 else
9588 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
9589 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009590" call Decho("dir<".dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009591 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009592" call Decho("<".direntry."> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009593 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009594 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009595" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9596 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
9597 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9598" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009599 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009600 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009601" call Decho("<".entry."> is not a key in treedict (no subtree)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009602 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009603 endif
9604 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02009605" call Decho("displaying: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009606
Bram Moolenaar446cb832008-06-24 21:56:24 +00009607" call Dret("NetrwTreeDisplay")
9608endfun
9609
9610" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009611" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
9612fun! s:NetrwRefreshTreeDict(dir)
9613" call Dfunc("s:NetrwRefreshTreeDict(dir<".a:dir.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02009614 if !exists("w:netrw_treedict")
9615" call Dret("s:NetrwRefreshTreeDict : w:netrw_treedict doesn't exist")
9616 return
9617 endif
9618
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009619 for entry in w:netrw_treedict[a:dir]
9620 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
9621" call Decho("a:dir<".a:dir."> entry<".entry."> direntry<".direntry.">",'~'.expand("<slnum>"))
9622
9623 if 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 let w:netrw_treedict[direntry]= liststar + listdotstar
9637" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9638
9639 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
9640" call Decho("<".direntry."/> is a key in treedict - display subtree for it",'~'.expand("<slnum>"))
9641 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009642 let liststar = s:NetrwGlob(direntry.'/','*',1)
9643 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009644" call Decho("updating w:netrw_treedict[".direntry.']='.string(w:netrw_treedict[direntry]),'~'.expand("<slnum>"))
9645
9646 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02009647" call Decho('not updating w:netrw_treedict['.string(direntry).'] with entry<'.string(entry).'> (no subtree)','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009648 endif
9649 endfor
9650" call Dret("s:NetrwRefreshTreeDict")
9651endfun
9652
9653" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009654" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009655" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009657 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009658" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009659" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
9660" 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>"))
9661" 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 +00009662
9663 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00009664 if !exists("w:netrw_treetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009665" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009666 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009667 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009668" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009669 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 +02009670" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009671 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009672 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009673" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009674 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009675 if exists("w:netrw_treetop")
9676 let s:netrw_treetop= w:netrw_treetop
9677 else
9678 let w:netrw_treetop= getcwd()
9679 let s:netrw_treetop= w:netrw_treetop
9680 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009681
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009683 " insure that we have a treedict, albeit empty
9684" call Decho("initializing w:netrw_treedict to empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009685 let w:netrw_treedict= {}
9686 endif
9687
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009688 " update the dictionary for the current directory
9689" call Decho("updating: w:netrw_treedict[".a:dirname.'] -> [directory listing]','~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009690" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009691 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009692 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009693" call Decho("w:treedict[".a:dirname."]= ".string(w:netrw_treedict[a:dirname]),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009694 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009695
9696 " if past banner, record word
9697 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
9698 let fname= expand("<cword>")
9699 else
9700 let fname= ""
9701 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009702" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
9703" 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 +00009704
9705 " display from treetop on down
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009706" call Decho("(s:NetrwTreeListing) w:netrw_treetop<".w:netrw_treetop.">")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009707 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009708" call Decho("s:NetrwTreeDisplay) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009709
9710 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
9711 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009712" call Decho("deleting blank line",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009713 1d
9714 endwhile
9715
Bram Moolenaar13600302014-05-22 18:26:40 +02009716 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00009717
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009718" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009719 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00009720 endif
9721endfun
9722
9723" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02009724" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01009725" Normally, treetop is w:netrw_treetop, but a
9726" user of the function ( netrw#SetTreetop() )
9727" wipes that out prior to calling this function
9728fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009729" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
9730 if line(".") < w:netrw_bannercnt + 2
9731 let treedir= a:treetop
9732 if treedir !~ '/$'
9733 let treedir= treedir.'/'
9734 endif
9735" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9736 return treedir
9737 endif
9738
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009739 let svpos = winsaveview()
9740" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009741 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009742" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009743 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009744" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9745 let curline= getline('.')
9746" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9747 if curline =~ '/$'
9748" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9749 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9750" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9751 elseif curline =~ '@\s\+-->'
9752" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9753 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9754 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9755" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009756 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009757" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009758 let treedir= ""
9759 endif
9760 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009761" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9762" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009763 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9764 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9765 let treedir= dirname.treedir
9766 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009767" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009768 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009769" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009770 if a:treetop =~ '/$'
9771 let treedir= a:treetop.treedir
9772 else
9773 let treedir= a:treetop.'/'.treedir
9774 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009775" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009776 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009777" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009778" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9779 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009780" call Dret("s:NetrwTreePath <".treedir.">")
9781 return treedir
9782endfun
9783
9784" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009785" s:NetrwWideListing: {{{2
9786fun! s:NetrwWideListing()
9787
9788 if w:netrw_liststyle == s:WIDELIST
9789" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9790 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009791 " cpf: characters per filename
9792 " fpl: filenames per line
9793 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009794 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009795 let dict={}
9796 " save the unnamed register and register 0-9 and a
9797 let dict.a=[getreg('a'), getregtype('a')]
9798 for i in range(0, 9)
9799 let dict[i] = [getreg(i), getregtype(i)]
9800 endfor
9801 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009802" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009803 let b:netrw_cpf= 0
9804 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009805 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009806 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9807 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009809 " restore stored registers
9810 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009811" call Dret("NetrwWideListing")
9812 return
9813 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009814 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009815 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009816" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009817
9818 " determine qty files per line (fpl)
9819 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9820 if w:netrw_fpl <= 0
9821 let w:netrw_fpl= 1
9822 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009823" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009824
9825 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009826 " fpc: files per column of wide listing
9827 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009828 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009829 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9830 let newcolstart = w:netrw_bannercnt + fpc
9831 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009832" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009833 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009834" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009835 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009836 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009837 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009838 while line("$") >= newcolstart
9839 if newcolend > line("$") | let newcolend= line("$") | endif
9840 let newcolqty= newcolend - newcolstart
9841 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009842 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009843 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009844 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009846 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009847 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009848 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009849 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009850 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009851 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009852" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009853 if @* != keepregstar | sil! let @* = keepregstar | endif
9854 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009855 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009856 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9857 NetrwKeepj call histdel("/",-1)
9858 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9859 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009860" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009861 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009862 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009863" 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 +00009864" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009865 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009866 else
9867 if hasmapto("w","n")
9868 sil! nunmap <buffer> w
9869 endif
9870 if hasmapto("b","n")
9871 sil! nunmap <buffer> b
9872 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009873 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009874endfun
9875
9876" ---------------------------------------------------------------------
9877" s:PerformListing: {{{2
9878fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009879" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9880" 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 +02009881" 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>"))
9882 sil! NetrwKeepj %d _
9883" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009884
Bram Moolenaar15146672011-10-20 22:22:38 +02009885 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009886" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009887 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009888
Bram Moolenaar85850f32019-07-19 22:05:51 +02009889 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009890 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009891" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009892
9893" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009894" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009895" endif " Decho
9896
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9899 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009900" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9901 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009902 endif
9903
9904 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009905 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009906
9907 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009908 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009909" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009910 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009911 if exists("g:netrw_pchk")
9912 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9913 " failure detections.
9914 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009915 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9917 endif
9918 if exists("g:netrw_pchk")
9919 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9920 else
9921 let curdir= b:netrw_curdir
9922 endif
9923 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9924 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9925 else
9926 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009927 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009928 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009929 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009930 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009931" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009932 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009933 let w:netrw_bannercnt= 1
9934 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9936" 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 +00009937
Bram Moolenaar85850f32019-07-19 22:05:51 +02009938 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009939 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009940 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009941 let sortby= sortby." reversed"
9942 endif
9943
9944 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009945 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009946" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009947 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009949 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009950 NetrwKeepj put ='\" Sorted by '.sortby
9951 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009952 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9953 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009955 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009956 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009957 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9958 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009959 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009960" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009961" 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 +00009962 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009963
Bram Moolenaar85850f32019-07-19 22:05:51 +02009964 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009965 if g:netrw_banner
9966 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009967" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009968 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009969 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009970 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009971 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009972 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009973 endif
9974 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009975 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009976" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009977 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009978 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009979 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009980
9981 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009982 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009983" 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 +01009984 if g:netrw_list_hide != "" && g:netrw_hide
9985 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009986 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009987 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009988 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009989 endif
9990 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009991 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009992 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009993
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009994" 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 +01009995 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009997 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009998" 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 +01009999 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +010010000 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +010010001" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010002" 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 +000010003 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010004
10005 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +010010006 if g:netrw_banner
10007 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010008 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010009" 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 +010010010" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010011" 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 +010010012 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013
Bram Moolenaar446cb832008-06-24 21:56:24 +000010014 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010015" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010016 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010017 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010019 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +010010020 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021" 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 +010010022" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
10023 return
10024 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010025 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010026
10027 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010028 if !exists("w:netrw_bannercnt")
10029 let w:netrw_bannercnt= 0
10030 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010031" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
10032" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
10033" 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 +010010034
Bram Moolenaar5c736222010-01-06 20:54:52 +010010035 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020010036" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010037" 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 +000010038 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010039 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010040 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010010041 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010042" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010043
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010044 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010045 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +020010046" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010047 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010048
Bram Moolenaar5c736222010-01-06 20:54:52 +010010049 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010050" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010051 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +020010052 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010053 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010054 else
10055 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010056 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010057 endif
10058 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010059
Bram Moolenaar446cb832008-06-24 21:56:24 +000010060 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010061" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010062 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
10063 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010064
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010065 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +020010066 " exten: sort by extension
10067 " The histdel(...,-1) calls remove the last search from the search history
10068" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010069 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
10070 NetrwKeepj call histdel("/",-1)
10071 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
10072 NetrwKeepj call histdel("/",-1)
10073 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
10074 NetrwKeepj call histdel("/",-1)
10075 if !g:netrw_banner || w:netrw_bannercnt < line("$")
10076" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010077 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010078 " normal direction sorting
10079 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
10080 else
10081 " reverse direction sorting
10082 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
10083 endif
10084 endif
10085 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
10086 NetrwKeepj call histdel("/",-1)
10087
Bram Moolenaar446cb832008-06-24 21:56:24 +000010088 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +010010089 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010090" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010091 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010092" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010093 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010094 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010095" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010096 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +000010097 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010098" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010099 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
10100 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010101 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010102 endif
10103
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010104 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010105" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010106 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010107 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +010010108 call histdel("/",-1)
10109 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010110 endif
10111 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010112" 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 +000010113
10114 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
10116" 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 +010010117 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010118" 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 +010010119 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" 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 +000010121
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010122 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010123 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010125 sil! g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010126 endif
10127
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010128 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010129 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010130" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
10131 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010132 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010133" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
10134 else
10135" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
10136" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
10137" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
10138" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010139 endif
10140
10141 " record previous current directory
10142 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010143" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010144
10145 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010146" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
10147" 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 +010010148 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149" 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 +020010150 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010151" 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 +000010152
10153 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010154" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010155 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010156" 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 +010010157 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010158" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010159 exe "setl ts=".(g:netrw_maxfilenamelen+1)
10160 endif
Bram Moolenaar91359012019-11-30 17:57:03 +010010161" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020010162" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010163
Bram Moolenaar8d043172014-01-23 14:24:41 +010010164 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010165" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
10166" 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 +010010167" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
10168 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010169 unlet s:treecurpos
10170 endif
10171
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010172" 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>"))
10173" 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 +000010174" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
10175endfun
10176
10177" ---------------------------------------------------------------------
10178" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000010179fun! s:SetupNetrwStatusLine(statline)
10180" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
10181
10182 if !exists("s:netrw_setup_statline")
10183 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010184" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010185
10186 if !exists("s:netrw_users_stl")
10187 let s:netrw_users_stl= &stl
10188 endif
10189 if !exists("s:netrw_users_ls")
10190 let s:netrw_users_ls= &laststatus
10191 endif
10192
10193 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +020010194 let dict={}
10195 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +000010196 redir @a
10197 try
10198 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010199 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +000010200 if &bg == "dark"
10201 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
10202 else
10203 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
10204 endif
10205 endtry
10206 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +020010207 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010208 endif
10209
10210 " set up status line (may use User9 highlighting)
10211 " insure that windows have a statusline
10212 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +090010213 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +020010214 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010215" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010216 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +000010217
10218" call Dret("SetupNetrwStatusLine : stl=".&stl)
10219endfun
10220
Bram Moolenaar85850f32019-07-19 22:05:51 +020010221" =========================================
10222" Remote Directory Browsing Support: {{{1
10223" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010224
10225" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010226" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
10227" This function assumes that a long listing will be received. Size, time,
10228" and reverse sorts will be requested of the server but not otherwise
10229" enforced here.
10230fun! s:NetrwRemoteFtpCmd(path,listcmd)
10231" 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 +010010232" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010233 " sanity check: {{{3
10234 if !exists("w:netrw_method")
10235 if exists("b:netrw_method")
10236 let w:netrw_method= b:netrw_method
10237 else
10238 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
10239" call Dret("NetrwRemoteFtpCmd")
10240 return
10241 endif
10242 endif
10243
10244 " WinXX ftp uses unix style input, so set ff to unix " {{{3
10245 let ffkeep= &ff
10246 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010247" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010248
10249 " clear off any older non-banner lines " {{{3
10250 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010251" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
10252 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010253
10254 ".........................................
10255 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
10256 " ftp + <.netrc>: Method #2
10257 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010258 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010259 endif
10260 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010261 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010262" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010263 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010264 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010265" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010267" 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>"))
10268 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 +010010269 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010270" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
10271 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 +010010272 endif
10273
10274 ".........................................
10275 elseif w:netrw_method == 3 " {{{3
10276 " ftp + machine,id,passwd,filename: Method #3
10277 setl ff=unix
10278 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010279 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +010010280 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010281 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +010010282 endif
10283
10284 " handle userid and password
10285 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010286" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010287 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
10288 call NetUserPass("ftp:".host)
10289 endif
10290 if exists("g:netrw_uid") && g:netrw_uid != ""
10291 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010292 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +010010293 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010294 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 endif
10296 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010297 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010298 endif
10299 endif
10300
10301 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010302 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +010010303 endif
10304 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010305 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010306" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010307 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010308 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +010010309
10310 " perform ftp:
10311 " -i : turns off interactive prompting from ftp
10312 " -n unix : DON'T use <.netrc>, even though it exists
10313 " -n win32: quit being obnoxious about password
10314 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010315" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010316 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +010010317" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010318" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
10319" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010320 endif
10321
10322 ".........................................
10323 elseif w:netrw_method == 9 " {{{3
10324 " sftp username@machine: Method #9
10325 " s:netrw_sftp_cmd
10326 setl ff=unix
10327
10328 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +090010329 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010330" call Dret("NetrwRemoteFtpCmd")
10331 return
10332
10333 ".........................................
10334 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010335 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +010010336 endif
10337
10338 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +020010339 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010340 sil! NetrwKeepj %s/\r$//e
10341 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010342 endif
10343 if a:listcmd == "dir"
10344 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010345 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
10346 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
10347 NetrwKeepj call histdel("/",-1)
10348 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010349 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 +010010350 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
10351 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010352 endif
10353 endif
10354
10355 " ftp's listing doesn't seem to include ./ or ../ " {{{3
10356 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010357 exe 'NetrwKeepj '.w:netrw_bannercnt
10358 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +010010359 endif
10360 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010361 exe 'NetrwKeepj '.w:netrw_bannercnt
10362 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +010010363 endif
10364
10365 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +090010366 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +010010367" call Dret("NetrwRemoteFtpCmd")
10368endfun
10369
10370" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010371" s:NetrwRemoteListing: {{{2
10372fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010373" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +000010374
Bram Moolenaara6878372014-03-22 21:02:50 +010010375 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
10376 let w:netrw_bannercnt= s:bannercnt
10377 endif
10378 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010379 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +010010380 endif
10381
Bram Moolenaar446cb832008-06-24 21:56:24 +000010382 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010383
Bram Moolenaar446cb832008-06-24 21:56:24 +000010384 " sanity check:
10385 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010386" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010387 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010388" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010389 if !exists("g:netrw_quiet")
10390 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
10391 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010392 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010393" call Dret("s:NetrwRemoteListing -1")
10394 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +000010395 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010396
Bram Moolenaar8d043172014-01-23 14:24:41 +010010397 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010398" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010399 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +010010400 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010401 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 +000010402 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010403 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 +000010404 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010405 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010406
Bram Moolenaar85850f32019-07-19 22:05:51 +020010407 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010408" call Dret("s:NetrwRemoteListing -1")
10409 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +000010410 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010411" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010412
Bram Moolenaar446cb832008-06-24 21:56:24 +000010413 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010414" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010415 let w:netrw_method= b:netrw_method
10416 endif
10417
Bram Moolenaar13600302014-05-22 18:26:40 +020010418 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +020010419 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010420" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010010421 let s:method = "ftp"
10422 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010423 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010424 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010425 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010426 let listcmd= g:netrw_ftp_sizelist_cmd
10427 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010428" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010429 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010430" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010431
Bram Moolenaara6878372014-03-22 21:02:50 +010010432 " report on missing file or directory messages
10433 if search('[Nn]o such file or directory\|Failed to change directory')
10434 let mesg= getline(".")
10435 if exists("w:netrw_bannercnt")
10436 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010437 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +010010438 setl noma
10439 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010440 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +010010441 call netrw#ErrorMsg(s:WARNING,mesg,96)
10442" call Dret("s:NetrwRemoteListing : -1")
10443 return -1
10444 endif
10445
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010446 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 +000010447 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010448" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010449 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +000010450
10451 " cleanup
10452 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010453 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
10454 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010455 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010456 sil! NetrwKeepj %s/\r$//e
10457 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010458
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010459 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010460 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010461 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +010010462 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010463" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010464 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010465" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010466 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010467 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010468 exe "sil! NetrwKeepj ".line1
10469 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010470
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010471" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010472 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010473" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010474 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
10475 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010476 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010477" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010478 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
10479 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
10480 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
10481 NetrwKeepj call histdel("/",-1)
10482 NetrwKeepj call histdel("/",-1)
10483 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010484 endif
10485 endif
10486
Bram Moolenaar13600302014-05-22 18:26:40 +020010487 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010488 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010489" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010490 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010491" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010492 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010493" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
10494 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010495 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010496 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
10497 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
10498 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
10499 NetrwKeepj call histdel("/",-1)
10500 NetrwKeepj call histdel("/",-1)
10501 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010502 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010503 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
10504 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010505 endif
10506 else
10507 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010508" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010509 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +000010510 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010511" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
10512 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
10513" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010514 endif
10515 endif
10516
10517 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +010010518 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010519" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010520 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
10521 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010522 endif
10523 endif
10524
10525 if w:netrw_liststyle == s:LONGLIST
10526 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010527" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010528
10529 if s:method == "ftp"
10530 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010531 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010532 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010533 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +000010534 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010535 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010537 sil! NetrwKeepj 1
10538 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010539 let line2= line(".")
10540 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010541 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010542 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010543 endif
10544 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010545 exe "sil! NetrwKeepj ".line1
10546 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +000010547 endif
10548
10549 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010550" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010551 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 +000010552 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010553" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010554 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010555 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010556 exe 'sil NetrwKeepj '.w:netrw_bannercnt
10557 NetrwKeepj call histdel("/",-1)
10558 NetrwKeepj call histdel("/",-1)
10559 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010560 endif
10561 endif
10562
10563" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010564" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +010010566
10567" call Dret("s:NetrwRemoteListing 0")
10568 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010569endfun
10570
Bram Moolenaar446cb832008-06-24 21:56:24 +000010571" ---------------------------------------------------------------------
10572" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
10573fun! s:NetrwRemoteRm(usrhost,path) range
10574" call Dfunc("s:NetrwRemoteRm(usrhost<".a:usrhost."> path<".a:path.">) virtcol=".virtcol("."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010575" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010576 let svpos= winsaveview()
10577" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578
10579 let all= 0
10580 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10581 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582" call Decho("remove all marked files with bufnr#".bufnr("%"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583 for fname in s:netrwmarkfilelist_{bufnr("%")}
10584 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010585 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010586 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010587 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010588 let all= 1
10589 endif
10590 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +010010591 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010592
10593 else
10594 " remove files specified by range
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010595" call Decho("remove files specified by range",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010596
10597 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010598 let keepsol = &l:sol
10599 setl nosol
10600 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +000010601
10602 " remove multiple files and directories
10603 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010604 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010605 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010606 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010608 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010609 let all= 1
10610 endif
10611 let ctr= ctr + 1
10612 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010613 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010614 endif
10615
10616 " refresh the (remote) directory listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010617" call Decho("refresh remote directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010618 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010619" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10620 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010621
10622" call Dret("s:NetrwRemoteRm")
10623endfun
10624
10625" ---------------------------------------------------------------------
10626" s:NetrwRemoteRmFile: {{{2
10627fun! s:NetrwRemoteRmFile(path,rmfile,all)
10628" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
10629
10630 let all= a:all
10631 let ok = ""
10632
10633 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
10634 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010635" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010636 if !all
10637 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010638" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010639 call inputsave()
10640 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10641 call inputrestore()
10642 echohl NONE
10643 if ok == ""
10644 let ok="no"
10645 endif
10646 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010647 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010648 let all= 1
10649 endif
10650 endif
10651
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010652 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010653" 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 +000010654 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010655" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010656 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010657 if path =~ '^\a\{3,}://'
10658 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010660 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +000010661 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
10662 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010664 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010665" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010666 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010667 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010668 let ok="q"
10669 else
MiguelBarroc46c21b2024-01-31 20:07:17 +010010670 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010671" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
10672" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
10673" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010674 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010675 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010676 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010677 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010678 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010679" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010680 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010681 if v:shell_error != 0
10682 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +090010683 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 +010010684 else
10685 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
10686 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010687 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010688 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010689 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010690" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010691 endif
10692 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010693 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010694" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010695 endif
10696
10697 else
10698 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010699" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010700 if !all
10701 call inputsave()
10702 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
10703 call inputrestore()
10704 if ok == ""
10705 let ok="no"
10706 endif
10707 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010708 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010709 let all= 1
10710 endif
10711 endif
10712
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010713 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +000010714 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010715 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010716 else
10717 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010718 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
10719" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010720 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010721" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010722
10723 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010724" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
10725 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
10726" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010727 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010728" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010729
10730 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010731 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010732 endif
10733 endif
10734 endif
10735
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010736 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010737" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010738 endif
10739 endif
10740
10741" call Dret("s:NetrwRemoteRmFile ".ok)
10742 return ok
10743endfun
10744
10745" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010746" s:NetrwRemoteRename: rename a remote file or directory {{{2
10747fun! s:NetrwRemoteRename(usrhost,path) range
10748" call Dfunc("NetrwRemoteRename(usrhost<".a:usrhost."> path<".a:path.">)")
10749
10750 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010751 let svpos = winsaveview()
10752" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010753 let ctr = a:firstline
10754 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10755
10756 " rename files given by the markfilelist
10757 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10758 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010759" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010760 if exists("subfrom")
10761 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010762" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010763 else
10764 call inputsave()
10765 let newname= input("Moving ".oldname." to : ",oldname)
10766 call inputrestore()
10767 if newname =~ '^s/'
10768 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10769 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10770 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010771" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010772 endif
10773 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010774
Bram Moolenaar446cb832008-06-24 21:56:24 +000010775 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010776 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010777 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010778 let oldname= s:ShellEscape(a:path.oldname)
10779 let newname= s:ShellEscape(a:path.newname)
10780" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010781 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010782 endif
10783
10784 endfor
10785 call s:NetrwUnMarkFile(1)
10786
10787 else
10788
10789 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010790 let keepsol= &l:sol
10791 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010792 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010793 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010794
10795 let oldname= s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010796" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010797
10798 call inputsave()
10799 let newname= input("Moving ".oldname." to : ",oldname)
10800 call inputrestore()
10801
10802 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10803 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10804 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010805 let oldname= s:ShellEscape(a:path.oldname)
10806 let newname= s:ShellEscape(a:path.newname)
10807" call Decho("system(netrw#WinPath(".rename_cmd.") ".oldname.' '.newname.")",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010808 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010809 endif
10810
10811 let ctr= ctr + 1
10812 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010813 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010814 endif
10815
10816 " refresh the directory
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010817 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010818" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
10819 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010820
10821" call Dret("NetrwRemoteRename")
10822endfun
10823
Bram Moolenaar85850f32019-07-19 22:05:51 +020010824" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010825" Local Directory Browsing Support: {{{1
10826" ==========================================
10827
10828" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010829" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010830" Should accept: file://localhost/etc/fstab
10831" file:///etc/fstab
10832" file:///c:/WINDOWS/clock.avi
10833" file:///c|/WINDOWS/clock.avi
10834" file://localhost/c:/WINDOWS/clock.avi
10835" file://localhost/c|/WINDOWS/clock.avi
10836" file://c:/foo.txt
10837" file:///c:/foo.txt
10838" 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 +020010839fun! netrw#FileUrlEdit(fname)
10840" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010841 let fname = a:fname
10842 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010843" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010844 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010845" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010846 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010847 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010848 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010849" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010850 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010851" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010852 endif
10853 endif
10854 let fname2396 = netrw#RFC2396(fname)
10855 let fname2396e= fnameescape(fname2396)
10856 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010857 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010858" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010859 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010860" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010861 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10862 endif
10863 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010864
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010865" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10866" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010867 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010868 exe 'NetrwKeepj keepalt edit '.plainfname
10869 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10870
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010871" 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 +020010872" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010873 exe "sil doau BufReadPost ".fname2396e
10874endfun
10875
10876" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010877" netrw#LocalBrowseCheck: {{{2
10878fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010879 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010880 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10881 "
10882 " unfortunate interaction -- split window debugging can't be used here, must use
10883 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10884 " another call to LocalBrowseCheck() when attempts to write
10885 " to the DBG buffer are made.
10886 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010887 " The &ft == "netrw" test was installed because the BufEnter event
10888 " would hit when re-entering netrw windows, creating unexpected
10889 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010890" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010891" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010892" 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 +010010893 " getting E930: Cannot use :redir inside execute
10894"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010895" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10896" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010897
Bram Moolenaar97d62492012-11-15 21:28:22 +010010898 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010899 if isdirectory(s:NetrwFile(a:dirname))
10900" 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 +010010901
Bram Moolenaar97d62492012-11-15 21:28:22 +010010902 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10904" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010905 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010906
Bram Moolenaar446cb832008-06-24 21:56:24 +000010907 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010908" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010909 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010910
Bram Moolenaar5c736222010-01-06 20:54:52 +010010911 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010912" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010913 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010914 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010915 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010916" 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 +010010917" call Dret("netrw#LocalBrowseCheck")
10918 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010919 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010920
Bram Moolenaar85850f32019-07-19 22:05:51 +020010921 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010922 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10923 " AND IF the listing style is not a tree listing
10924 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010925" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010926 let ibuf = 1
10927 let buflast = bufnr("$")
10928 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010929 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10930 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010931 endif
10932 let ibuf= ibuf + 1
10933 endwhile
10934 endif
10935 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010936" 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>"))
10937" 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 +000010938 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010939" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010940endfun
10941
10942" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010943" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010944" performed any shell command. The idea is to cause all local-browsing
10945" buffers to be refreshed after a user has executed some shell command,
10946" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010947fun! s:LocalBrowseRefresh()
10948" call Dfunc("s:LocalBrowseRefresh() tabpagenr($)=".tabpagenr("$"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010949" call Decho("s:netrw_browselist =".(exists("s:netrw_browselist")? string(s:netrw_browselist) : '<n/a>'),'~'.expand("<slnum>"))
10950" call Decho("w:netrw_bannercnt =".(exists("w:netrw_bannercnt")? string(w:netrw_bannercnt) : '<n/a>'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010951
Bram Moolenaar446cb832008-06-24 21:56:24 +000010952 " determine which buffers currently reside in a tab
10953 if !exists("s:netrw_browselist")
Bram Moolenaara6878372014-03-22 21:02:50 +010010954" call Dret("s:LocalBrowseRefresh : browselist is empty")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010955 return
10956 endif
10957 if !exists("w:netrw_bannercnt")
Bram Moolenaara6878372014-03-22 21:02:50 +010010958" call Dret("s:LocalBrowseRefresh : don't refresh when focus not on netrw window")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010959 return
10960 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010961 if !empty(getcmdwintype())
10962 " cannot move away from cmdline window, see :h E11
10963 return
10964 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010965 if exists("s:netrw_events") && s:netrw_events == 1
10966 " s:LocalFastBrowser gets called (indirectly) from a
10967 let s:netrw_events= 2
10968" call Dret("s:LocalBrowseRefresh : avoid initial double refresh")
10969 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010970 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010971 let itab = 1
10972 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010973 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010974 while itab <= tabpagenr("$")
10975 let buftablist = buftablist + tabpagebuflist()
10976 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010977 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010979" call Decho("buftablist".string(buftablist),'~'.expand("<slnum>"))
10980" call Decho("s:netrw_browselist<".(exists("s:netrw_browselist")? string(s:netrw_browselist) : "").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010981 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10982 " | refresh any netrw window
10983 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010984 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010985 let ibl = 0
10986 for ibuf in s:netrw_browselist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010987" call Decho("bufwinnr(".ibuf.") index(buftablist,".ibuf.")=".index(buftablist,ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010988 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10989 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010990 " (ibuf not shown in a current window AND
10991 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010992" call Decho("wiping buf#".ibuf,"<".bufname(ibuf).">",'~'.expand("<slnum>"))
10993 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010994 call remove(s:netrw_browselist,ibl)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010995" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010996 continue
10997 elseif index(tabpagebuflist(),ibuf) != -1
10998 " refresh any netrw buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010999" call Decho("refresh buf#".ibuf.'-> win#'.bufwinnr(ibuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011000 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011001 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010011002 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
11003 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
11004 let g:netrw_quickhelp= g:netrw_quickhelp - 1
11005 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011006" call Decho("#3: quickhelp=".g:netrw_quickhelp,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011007 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
11008 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
11009 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011010 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011011 endif
11012 let ibl= ibl + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" call Decho("bottom of s:netrw_browselist for loop: ibl=".ibl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011014 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020011015" call Decho("restore window: win_gotoid(".curwinid.")")
11016 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011017 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011018
Bram Moolenaara6878372014-03-22 21:02:50 +010011019" call Dret("s:LocalBrowseRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011020endfun
11021
11022" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011023" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
11024"
11025" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011026" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010011027" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
11028" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011029" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010011030"
11031" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
11032" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010011033" (re-using a buffer may not be as accurate)
11034"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011035" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010011036" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
11037" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
11038" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
11039" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011040fun! s:LocalFastBrowser()
Bram Moolenaar85850f32019-07-19 22:05:51 +020011041" call Dfunc("s:LocalFastBrowser() g:netrw_fastbrowse=".g:netrw_fastbrowse)
11042" call Decho("s:netrw_events ".(exists("s:netrw_events")? "exists" : 'n/a'),'~'.expand("<slnum>"))
11043" call Decho("autocmd: ShellCmdPost ".(exists("#ShellCmdPost")? "already installed" : "not installed"),'~'.expand("<slnum>"))
11044" call Decho("autocmd: FocusGained ".(exists("#FocusGained")? "already installed" : "not installed"),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011045
11046 " initialize browselist, a list of buffer numbers that the local browser has used
11047 if !exists("s:netrw_browselist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011048" call Decho("initialize s:netrw_browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011049 let s:netrw_browselist= []
11050 endif
11051
11052 " append current buffer to fastbrowse list
11053 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011054" call Decho("appendng current buffer to browselist",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011055 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011056" call Decho("browselist=".string(s:netrw_browselist),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011057 endif
11058
11059 " enable autocmd events to handle refreshing/removing local browser buffers
11060 " If local browse buffer is currently showing: refresh it
11061 " If local browse buffer is currently hidden : wipe it
11062 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
11063 " =1 : medium speed, re-use directory listing for remote only
11064 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010011065 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
11066 let s:netrw_events= 1
11067 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011068 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020011069 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011070" call Decho("installing autocmd: ShellCmdPost",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011071 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011072 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011073" call Decho("installing autocmds: ShellCmdPost FocusGained",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011074 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010011075 endif
11076 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010011077
11078 " user must have changed fastbrowse to its fast setting, so remove
11079 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010011080 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011081" call Decho("remove AuNetrwEvent autcmd group",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011082 unlet s:netrw_events
11083 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011084 au!
11085 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010011086 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010011087 endif
11088
Bram Moolenaar85850f32019-07-19 22:05:51 +020011089" call Dret("s:LocalFastBrowser : browselist<".string(s:netrw_browselist).">")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011090endfun
11091
11092" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011093" s:LocalListing: does the job of "ls" for local directories {{{2
11094fun! s:LocalListing()
11095" call Dfunc("s:LocalListing()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011096" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
11097" call Decho("modified=".&modified." modifiable=".&modifiable." readonly=".&readonly,'~'.expand("<slnum>"))
11098" 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 +010011099
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011100" 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
11101" 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
11102" 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 +010011103
11104 " get the list of files contained in the current directory
11105 let dirname = b:netrw_curdir
11106 let dirnamelen = strlen(b:netrw_curdir)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011107 let filelist = s:NetrwGlob(dirname,"*",0)
11108 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011110
Nir Lichtman1e34b952024-05-08 19:19:34 +020011111 if g:netrw_cygwin == 0 && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011112" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011113 elseif index(filelist,'..') == -1 && b:netrw_curdir !~ '/'
11114 " include ../ in the glob() entry if its missing
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011115" call Decho("forcibly including on \"..\"",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011116 let filelist= filelist+[s:ComposePath(b:netrw_curdir,"../")]
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011117" call Decho("filelist=".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011118 endif
11119
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011120" call Decho("before while: dirname <".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011121" call Decho("before while: dirnamelen<".dirnamelen.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011122" call Decho("before while: filelist =".string(filelist),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011123
11124 if get(g:, 'netrw_dynamic_maxfilenamelen', 0)
11125 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
11126 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011127" call Decho("dynamic_maxfilenamelen: filenames =".string(filelistcopy),'~'.expand("<slnum>"))
11128" call Decho("dynamic_maxfilenamelen: g:netrw_maxfilenamelen=".g:netrw_maxfilenamelen,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011129 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011130" 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 +010011131
11132 for filename in filelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011133" call Decho(" ",'~'.expand("<slnum>"))
11134" call Decho("for filename in filelist: filename<".filename.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011135
11136 if getftype(filename) == "link"
11137 " indicate a symbolic link
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011138" call Decho("indicate <".filename."> is a symbolic link with trailing @",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011139 let pfile= filename."@"
11140
11141 elseif getftype(filename) == "socket"
11142 " indicate a socket
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011143" call Decho("indicate <".filename."> is a socket with trailing =",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011144 let pfile= filename."="
11145
11146 elseif getftype(filename) == "fifo"
11147 " indicate a fifo
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011148" call Decho("indicate <".filename."> is a fifo with trailing |",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011149 let pfile= filename."|"
11150
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011151 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010011152 " indicate a directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011153" call Decho("indicate <".filename."> is a directory with trailing /",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011154 let pfile= filename."/"
11155
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011156 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020011157 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010011158 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
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 elseif executable(filename)
11167 " indicate an executable
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011168" call Decho("indicate <".filename."> is executable with trailing *",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011169 let pfile= filename."*"
11170 else
11171 " normal file
11172 let pfile= filename
11173 endif
11174
11175 else
11176 " normal file
11177 let pfile= filename
11178 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011179" call Decho("pfile<".pfile."> (after *@/ appending)",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011180
11181 if pfile =~ '//$'
11182 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011183" call Decho("change // to /: pfile<".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011184 endif
11185 let pfile= strpart(pfile,dirnamelen)
11186 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011187" call Decho("filename<".filename.">",'~'.expand("<slnum>"))
11188" call Decho("pfile <".pfile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011189
11190 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090011191 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
11192 let sz = getfsize(filename)
11193 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
11194 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010011195
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011196 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011197 let sz= s:NetrwHumanReadable(sz)
11198 endif
K.Takata8750e3c2023-11-22 18:20:01 +090011199 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090011200 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011201" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011202 endif
11203
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011204 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010011205 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010011206 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011207" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011208" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011209 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011210 let ft = printf("%018d",t)
Bram Moolenaar91359012019-11-30 17:57:03 +010011211" call Decho("exe NetrwKeepj put ='".ft.'/'.pfile."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011212 let ftpfile= ft.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011213 sil! NetrwKeepj put=ftpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011214
11215 elseif g:netrw_sort_by =~ "^s"
11216 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011217" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011218" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011219 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090011220 let fsz = printf("%018d",sz)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011221" call Decho("exe NetrwKeepj put ='".fsz.'/'.filename."'",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011222 let fszpfile= fsz.'/'.pfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011223 sil! NetrwKeepj put =fszpfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011224
11225 else
11226 " sort by name
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011227" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011228" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011229 sil! NetrwKeepj put=pfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011230 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011231" call DechoBuf(bufnr("%"),"bufnr(%)")
Bram Moolenaara6878372014-03-22 21:02:50 +010011232 endfor
11233
11234 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011235 sil! NetrwKeepj g/^$/d
11236 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010011237 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011238" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011239 exe "setl ts=".(g:netrw_maxfilenamelen+1)
11240
11241" call Dret("s:LocalListing")
11242endfun
11243
11244" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010011245" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
11246fun! s:NetrwLocalExecute(cmd)
11247" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
11248 let ykeep= @@
11249 " sanity check
11250 if !executable(a:cmd)
11251 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
11252 let @@= ykeep
11253" call Dret("s:NetrwLocalExecute")
11254 return
11255 endif
11256
11257 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011258" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011259 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011260" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011261
11262 " strip any ansi escape sequences off
11263 let result = substitute(result,"\e\\[[0-9;]*m","","g")
11264
11265 " show user the result(s)
11266 echomsg result
11267 let @@= ykeep
11268
11269" call Dret("s:NetrwLocalExecute")
11270endfun
11271
11272" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011273" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010011274fun! s:NetrwLocalRename(path) range
11275" call Dfunc("NetrwLocalRename(path<".a:path.">)")
11276
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011277 if !exists("w:netrw_bannercnt")
11278 let w:netrw_bannercnt= b:netrw_bannercnt
11279 endif
11280
Bram Moolenaar97d62492012-11-15 21:28:22 +010011281 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010011282 let ykeep = @@
11283 let ctr = a:firstline
11284 let svpos = winsaveview()
11285 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011286" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011287
11288 " rename files given by the markfilelist
11289 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11290 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011291" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011292 if exists("subfrom")
11293 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011294" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011295 else
11296 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011297 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010011298 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011299 if newname =~ ''
11300 " two ctrl-x's : ignore all of string preceding the ctrl-x's
11301 let newname = substitute(newname,'^.*','','')
11302 elseif newname =~ ''
11303 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
11304 let newname = substitute(newname,'[^/]*','','')
11305 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011306 if newname =~ '^s/'
11307 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
11308 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011309" call Decho("subfrom<".subfrom."> subto<".subto."> newname<".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011310 let newname = substitute(oldname,subfrom,subto,'')
11311 endif
11312 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011313 if !all && filereadable(newname)
11314 call inputsave()
11315 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
11316 call inputrestore()
11317 if response == "all"
11318 let all= 1
11319 elseif response != "y" && response != "yes"
11320 " refresh the directory
11321" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
11322 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
11323" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11324 NetrwKeepj call winrestview(svpos)
11325 let @@= ykeep
11326" call Dret("NetrwLocalRename")
11327 return
11328 endif
11329 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011330 call rename(oldname,newname)
11331 endfor
11332 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011333
Bram Moolenaar97d62492012-11-15 21:28:22 +010011334 else
11335
11336 " attempt to rename files/directories
11337 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011338 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010011339
11340 " sanity checks
11341 if line(".") < w:netrw_bannercnt
11342 let ctr= ctr + 1
11343 continue
11344 endif
11345 let curword= s:NetrwGetWord()
11346 if curword == "./" || curword == "../"
11347 let ctr= ctr + 1
11348 continue
11349 endif
11350
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011351 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010011352 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar29634562020-01-09 21:46:04 +010011353" call Decho("oldname<".oldname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011354
11355 call inputsave()
11356 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
11357 call inputrestore()
11358
11359 call rename(oldname,newname)
Bram Moolenaar29634562020-01-09 21:46:04 +010011360" call Decho("renaming <".oldname."> to <".newname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011361
11362 let ctr= ctr + 1
11363 endwhile
11364 endif
11365
11366 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011367" call Decho("refresh the directory listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011368 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011369" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11370 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010011371 let @@= ykeep
11372
11373" call Dret("NetrwLocalRename")
11374endfun
11375
11376" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011377" s:NetrwLocalRm: {{{2
11378fun! s:NetrwLocalRm(path) range
11379" call Dfunc("s:NetrwLocalRm(path<".a:path.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011380" call Decho("firstline=".a:firstline." lastline=".a:lastline,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011381
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090011382 if !exists("w:netrw_bannercnt")
11383 let w:netrw_bannercnt= b:netrw_bannercnt
11384 endif
11385
Bram Moolenaar446cb832008-06-24 21:56:24 +000011386 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010011387 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000011388 let ret = 0
11389 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011390 let svpos = winsaveview()
11391" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011392
11393 if exists("s:netrwmarkfilelist_{bufnr('%')}")
11394 " remove all marked files
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011395" call Decho("remove all marked files",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011396 for fname in s:netrwmarkfilelist_{bufnr("%")}
11397 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011398 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011399 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011400 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011401 let all= 1
11402 endif
11403 endfor
11404 call s:NetrwUnMarkFile(1)
11405
11406 else
11407 " remove (multiple) files and directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011408" call Decho("remove files in range [".a:firstline.",".a:lastline."]",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011409
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011410 let keepsol= &l:sol
11411 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011412 let ctr = a:firstline
11413 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011414 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000011415
11416 " sanity checks
11417 if line(".") < w:netrw_bannercnt
11418 let ctr= ctr + 1
11419 continue
11420 endif
11421 let curword= s:NetrwGetWord()
11422 if curword == "./" || curword == "../"
11423 let ctr= ctr + 1
11424 continue
11425 endif
11426 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011427 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011428 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011429 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011430 let all= 1
11431 endif
11432 let ctr= ctr + 1
11433 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011434 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000011435 endif
11436
11437 " refresh the directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011438" call Decho("bufname<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011439 if bufname("%") != "NetrwMessage"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011440 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./'))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011441" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
11442 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011443 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010011444 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000011445
11446" call Dret("s:NetrwLocalRm")
11447endfun
11448
11449" ---------------------------------------------------------------------
11450" s:NetrwLocalRmFile: remove file fname given the path {{{2
11451" Give confirmation prompt unless all==1
11452fun! s:NetrwLocalRmFile(path,fname,all)
11453" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011454
Bram Moolenaar446cb832008-06-24 21:56:24 +000011455 let all= a:all
11456 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011457 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020011458 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011459" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011460
11461 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
11462 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011463" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011464 if !all
11465 echohl Statement
11466 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011467 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011468 call inputrestore()
11469 echohl NONE
11470 if ok == ""
11471 let ok="no"
11472 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011473" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011474 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011475" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011476 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011477 let all= 1
11478 endif
11479 endif
11480
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011481 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000011482 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011483" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011484 endif
11485
11486 else
11487 " attempt to remove directory
11488 if !all
11489 echohl Statement
11490 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020011491 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011492 call inputrestore()
11493 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
11494 if ok == ""
11495 let ok="no"
11496 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011497 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +000011498 let all= 1
11499 endif
11500 endif
11501 let rmfile= substitute(rmfile,'[\/]$','','e')
11502
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011503 if all || ok =~# 'y\%[es]' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020011504 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011505 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011506 endif
11507 endif
11508 endif
11509
11510" call Dret("s:NetrwLocalRmFile ".ok)
11511 return ok
11512endfun
11513
Bram Moolenaar85850f32019-07-19 22:05:51 +020011514" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000011515" Support Functions: {{{1
11516
Bram Moolenaar488c6512005-08-11 20:09:58 +000011517" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011518" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
11519" 0: marked file list of current buffer
11520" 1: marked file target
11521fun! netrw#Access(ilist)
11522 if a:ilist == 0
11523 if exists("s:netrwmarkfilelist_".bufnr('%'))
11524 return s:netrwmarkfilelist_{bufnr('%')}
11525 else
11526 return "no-list-buf#".bufnr('%')
11527 endif
11528 elseif a:ilist == 1
11529 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020011530 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011531endfun
11532
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011533" ---------------------------------------------------------------------
11534" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
11535fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011536 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011537endfun
11538
Bram Moolenaara6878372014-03-22 21:02:50 +010011539" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011540" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
11541" I expect this function to be used in
11542" :PChkAssert netrw#Expose("netrwmarkfilelist")
11543" for example.
11544fun! netrw#Expose(varname)
11545" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011546 if exists("s:".a:varname)
11547 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011548" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011549 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011550" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011551 if type(retval) == 3
11552 let retval = copy(retval)
11553 let i = 0
11554 while i < len(retval)
11555 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
11556 let i = i + 1
11557 endwhile
11558 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011559" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011560 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011561 else
11562" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011563 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011564 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010011565" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011566 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011567 endif
11568
11569" call Dret("netrw#Expose ".string(retval))
11570 return retval
11571endfun
11572
11573" ---------------------------------------------------------------------
11574" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
11575fun! netrw#Modify(varname,newvalue)
11576" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
11577 exe "let s:".a:varname."= ".string(a:newvalue)
11578" call Dret("netrw#Modify")
11579endfun
11580
11581" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010011582" netrw#RFC2396: converts %xx into characters {{{2
11583fun! netrw#RFC2396(fname)
11584" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090011585 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010011586" call Dret("netrw#RFC2396 ".fname)
11587 return fname
11588endfun
11589
11590" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011591" netrw#UserMaps: supports user-specified maps {{{2
11592" see :help function()
11593"
11594" g:Netrw_UserMaps is a List with members such as:
11595" [[keymap sequence, function reference],...]
11596"
11597" The referenced function may return a string,
11598" refresh : refresh the display
11599" -other- : this string will be executed
11600" or it may return a List of strings.
11601"
11602" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020011603" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011604" Related functions:
11605" netrw#Expose(varname) -- see s:varname variables
11606" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
11607" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
11608fun! netrw#UserMaps(islocal)
11609" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
11610" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
11611
11612 " set up usermaplist
11613 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
11614" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
11615 for umap in g:Netrw_UserMaps
11616" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
11617" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
11618 " if umap[0] is a string and umap[1] is a string holding a function name
11619 if type(umap[0]) == 1 && type(umap[1]) == 1
11620" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
11621 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
11622 else
11623 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
11624 endif
11625 endfor
11626 endif
11627" call Dret("netrw#UserMaps")
11628endfun
11629
11630" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011631" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
11632fun! netrw#WinPath(path)
11633" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020011634 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011635 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010011636 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011637 " remove trailing slash (Win95)
11638 let path = substitute(path, '\(\\\|/\)$', '', 'g')
11639 " remove escaped spaces
11640 let path = substitute(path, '\ ', ' ', 'g')
11641 " convert slashes to backslashes
11642 let path = substitute(path, '/', '\', 'g')
11643 else
11644 let path= a:path
11645 endif
11646" call Dret("netrw#WinPath <".path.">")
11647 return path
11648endfun
11649
11650" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020011651" s:StripTrailingSlash: removes trailing slashes from a path {{{2
11652fun! s:StripTrailingSlash(path)
11653 " remove trailing slash
11654 return substitute(a:path, '[/\\]$', '', 'g')
11655endfun
11656
11657
11658" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020011659" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
11660" cb : bl2mf=0 add marked files to buffer list
11661" cB : bl2mf=1 use bufferlist to mark files
11662" (mnemonic: cb = copy (marked files) to buffer list)
11663fun! s:NetrwBadd(islocal,bl2mf)
11664" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
11665 if a:bl2mf
11666 " cB: add buffer list to marked files
11667 redir => bufl
11668 ls
11669 redir END
11670 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
11671 for fname in bufl
11672 call s:NetrwMarkFile(a:islocal,fname)
11673 endfor
11674 else
11675 " cb: add marked files to buffer list
11676 for fname in s:netrwmarkfilelist_{bufnr("%")}
11677" " call Decho("badd ".fname,'~'.expand("<slnum>"))
11678 exe "badd ".fnameescape(fname)
11679 endfor
11680 let curbufnr = bufnr("%")
11681 let curdir = s:NetrwGetCurdir(a:islocal)
11682 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
11683 endif
11684" call Dret("s:NetrwBadd")
11685endfun
11686
11687" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011688" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
11689fun! s:ComposePath(base,subdir)
11690" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
11691
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011692 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011693" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011694 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000011695 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011696 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011697 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011698 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000011699 endif
11700
Bram Moolenaar85850f32019-07-19 22:05:51 +020011701 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020011702 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011703" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011704 let ret= a:subdir
11705
Nir Lichtman1e34b952024-05-08 19:19:34 +020011706 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011707" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010011708 if a:base =~ '[/\\]$'
11709 let ret= a:base.a:subdir
11710 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011711 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010011712 endif
11713
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011714 elseif a:base =~ '^\a\{3,}://'
11715" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011716 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
11717 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
11718 if a:subdir == '../'
11719 if curpath =~ '[^/]/[^/]\+/$'
11720 let curpath= substitute(curpath,'[^/]\+/$','','')
11721 else
11722 let curpath=""
11723 endif
11724 let ret= urlbase.curpath
11725 else
11726 let ret= urlbase.curpath.a:subdir
11727 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011728" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
11729" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
11730" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011731
11732 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011733" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011734 let ret = substitute(a:base."/".a:subdir,"//","/","g")
11735 if a:base =~ '^//'
11736 " keeping initial '//' for the benefit of network share listing support
11737 let ret= '/'.ret
11738 endif
11739 let ret= simplify(ret)
11740 endif
11741
11742" call Dret("s:ComposePath ".ret)
11743 return ret
11744endfun
11745
11746" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011747" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
11748" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
11749fun! s:DeleteBookmark(fname)
11750" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
11751 call s:MergeBookmarks()
11752
11753 if exists("g:netrw_bookmarklist")
11754 let indx= index(g:netrw_bookmarklist,a:fname)
11755 if indx == -1
11756 let indx= 0
11757 while indx < len(g:netrw_bookmarklist)
11758 if g:netrw_bookmarklist[indx] =~ a:fname
11759 call remove(g:netrw_bookmarklist,indx)
11760 let indx= indx - 1
11761 endif
11762 let indx= indx + 1
11763 endwhile
11764 else
11765 " remove exact match
11766 call remove(g:netrw_bookmarklist,indx)
11767 endif
11768 endif
11769
11770" call Dret("s:DeleteBookmark")
11771endfun
11772
11773" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011774" s:FileReadable: o/s independent filereadable {{{2
11775fun! s:FileReadable(fname)
11776" call Dfunc("s:FileReadable(fname<".a:fname.">)")
11777
11778 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011779 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011780 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011781 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011782 endif
11783
11784" call Dret("s:FileReadable ".ret)
11785 return ret
11786endfun
11787
11788" ---------------------------------------------------------------------
11789" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
11790" Places correct suffix on end of temporary filename,
11791" using the suffix provided with fname
11792fun! s:GetTempfile(fname)
11793" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
11794
11795 if !exists("b:netrw_tmpfile")
11796 " get a brand new temporary filename
11797 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011798" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011799
Bram Moolenaarc236c162008-07-13 17:41:49 +000011800 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011801" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011802
Bram Moolenaar9964e462007-05-05 17:54:07 +000011803 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011804 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
11805" 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 +010011806 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000011807" call Dret("s:GetTempfile getcwd<".getcwd().">")
11808 return ""
11809 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011810
Bram Moolenaar9964e462007-05-05 17:54:07 +000011811 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011812 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011813" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011814
Bram Moolenaar9964e462007-05-05 17:54:07 +000011815 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000011816 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010011817 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020011818 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000011819 if !exists("+shellslash") || !&ssl
11820 let tmpfile = substitute(tmpfile,'/','\','g')
11821 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011822 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000011823 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000011824 endif
11825 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011826" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011827 else
11828 " re-use temporary filename
11829 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011830" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011831 endif
11832
11833 " use fname's suffix for the temporary file
11834 if a:fname != ""
11835 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011836" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011837 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011838 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011839 elseif a:fname =~ '.txz$'
11840 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011841 else
11842 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11843 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011844" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011845 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011846" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011847 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011848" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011849 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11850 endif
11851 endif
11852
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011853" 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 +000011854" call Dret("s:GetTempfile <".tmpfile.">")
11855 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011856endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011857
11858" ---------------------------------------------------------------------
11859" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011860" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011861fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011862" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011863 if s:user == ""
11864 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11865 else
11866 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11867 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011868 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011869 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011870 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011871 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011872 else
11873 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11874 endif
11875" call Dret("s:MakeSshCmd <".sshcmd.">")
11876 return sshcmd
11877endfun
11878
11879" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011880" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11881fun! s:MakeBookmark(fname)
11882" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11883
11884 if !exists("g:netrw_bookmarklist")
11885 let g:netrw_bookmarklist= []
11886 endif
11887
11888 if index(g:netrw_bookmarklist,a:fname) == -1
11889 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011890 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011891 call add(g:netrw_bookmarklist,a:fname.'/')
11892 elseif a:fname !~ '/'
11893 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11894 else
11895 call add(g:netrw_bookmarklist,a:fname)
11896 endif
11897 call sort(g:netrw_bookmarklist)
11898 endif
11899
11900" call Dret("s:MakeBookmark")
11901endfun
11902
11903" ---------------------------------------------------------------------
11904" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11905fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011906" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011907 " get bookmarks from .netrwbook file
11908 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011909 if filereadable(s:NetrwFile(savefile))
11910" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011911 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011912" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011913 NetrwKeepj call delete(savefile)
11914 endif
11915" call Dret("s:MergeBookmarks")
11916endfun
11917
11918" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011919" s:NetrwBMShow: {{{2
11920fun! s:NetrwBMShow()
11921" call Dfunc("s:NetrwBMShow()")
11922 redir => bmshowraw
11923 menu
11924 redir END
11925 let bmshowlist = split(bmshowraw,'\n')
11926 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011927 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011928 if bmshowfuncs != []
11929 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011930 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011931 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011932 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011933 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011934 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011935" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11936endfun
11937
11938" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011939" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011940fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011941 if !exists("w:netrw_liststyle")
11942 let w:netrw_liststyle= g:netrw_liststyle
11943 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011944" 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 +020011945
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011946" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11947
Bram Moolenaaradc21822011-04-01 18:03:16 +020011948 if &ft != "netrw"
11949 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11950 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011951" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011952
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011953 elseif g:netrw_cursor == 8
11954 if w:netrw_liststyle == s:WIDELIST
11955 setl cursorline
11956 setl cursorcolumn
11957 else
11958 setl cursorline
11959 endif
11960 elseif g:netrw_cursor == 7
11961 setl cursorline
11962 elseif g:netrw_cursor == 6
11963 if w:netrw_liststyle == s:WIDELIST
11964 setl cursorline
11965 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011966 elseif g:netrw_cursor == 4
11967 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011968" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011969 setl cursorline
11970 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011971
11972 elseif g:netrw_cursor == 3
11973 " thin-long-tree: cursorline, user's cursorcolumn
11974 " wide : cursorline, cursorcolumn
11975 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011976" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011977 setl cursorline
11978 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011979 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011980" 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 +020011981 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011982 endif
11983
11984 elseif g:netrw_cursor == 2
11985 " thin-long-tree: cursorline, user's cursorcolumn
11986 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011987" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011988 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011989
11990 elseif g:netrw_cursor == 1
11991 " thin-long-tree: user's cursorline, user's cursorcolumn
11992 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011993 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011994" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011995 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011996 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011997" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011998 endif
11999
12000 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020012001 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012002" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012003 let &l:cursorline = s:netrw_usercul
12004 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012005 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020012006
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012007" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020012008" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012009endfun
12010
12011" ---------------------------------------------------------------------
12012" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
12013fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010012014" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020012015 if exists("s:netrw_usercul")
12016 let &l:cursorline = s:netrw_usercul
12017 endif
12018 if exists("s:netrw_usercuc")
12019 let &l:cursorcolumn = s:netrw_usercuc
12020 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012021" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012022" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
12023endfun
12024
Christian Brabandt62f7b552024-06-23 20:23:40 +020012025" s:RestoreRegister: restores all registers given in the dict {{{2
12026fun! s:RestoreRegister(dict)
12027 for [key, val] in items(a:dict)
12028 if key == 'unnamed'
12029 let key = ''
12030 endif
12031 call setreg(key, val[0], val[1])
12032 endfor
12033endfun
12034
Bram Moolenaar00a927d2010-05-14 23:24:24 +020012035" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012036" s:NetrwDelete: Deletes a file. {{{2
12037" Uses Steve Hall's idea to insure that Windows paths stay
12038" acceptable. No effect on Unix paths.
12039" Examples of use: let result= s:NetrwDelete(path)
12040fun! s:NetrwDelete(path)
12041" call Dfunc("s:NetrwDelete(path<".a:path.">)")
12042
Bram Moolenaar5c736222010-01-06 20:54:52 +010012043 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012044 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000012045 if exists("+shellslash")
12046 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020012047 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000012048 let result = delete(path)
12049 let &shellslash = sskeep
12050 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012051" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012052 let result= delete(path)
12053 endif
12054 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012055" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012056 let result= delete(path)
12057 endif
12058 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012059 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012060 endif
12061
12062" call Dret("s:NetrwDelete ".result)
12063 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000012064endfun
12065
12066" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012067" s:NetrwBufRemover: removes a buffer that: {{{2s
12068" has buffer-id > 1
12069" is unlisted
12070" is unnamed
12071" does not appear in any window
12072fun! s:NetrwBufRemover(bufid)
12073" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
12074" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
12075" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
12076" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
12077" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
12078
yasuda4dbb2662023-10-04 20:50:35 +020012079 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012080" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020012081 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012082 endif
12083
12084" call Dret("s:NetrwBufRemover")
12085endfun
12086
12087" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012088" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010012089fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012090" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012091" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012092
Bram Moolenaar89a9c152021-08-29 21:55:35 +020012093 " Clean out the last buffer:
12094 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
12095 " If so, delete it.
12096 call s:NetrwBufRemover(bufnr("$"))
12097
Bram Moolenaar446cb832008-06-24 21:56:24 +000012098 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012099" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012100 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
12101 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
12102 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
12103 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
12104 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12105 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
12106 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
12107 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
12108 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
12109 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12110 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
12111 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
12112 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
12113 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
12114 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
12115 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
12116
Bram Moolenaar85850f32019-07-19 22:05:51 +020012117 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012118" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012119 " when tree listing uses file TreeListing... a new buffer is made.
12120 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012121 " COMBAK: this causes a problem, see P43
12122" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012123 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010012124 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020012125 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012126" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020012127 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012128
Bram Moolenaar446cb832008-06-24 21:56:24 +000012129 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012130" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012131 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
12132 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
12133 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
12134 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
12135 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
12136 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
12137 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
12138 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
12139 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
12140 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
12141 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
12142 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
12143 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
12144 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
12145 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
12146 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
12147
Bram Moolenaar5c736222010-01-06 20:54:52 +010012148 if a:0 > 0
12149 let b:netrw_curdir= a:1
12150 if b:netrw_curdir =~ '/$'
12151 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012152 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010012153 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012154 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020012155 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
12156 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010012157 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012158 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010012159 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012160 endif
12161 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012162 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
12163 let &l:bexpr = "netrw#BalloonHelp()"
12164 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012165
Bram Moolenaar8d043172014-01-23 14:24:41 +010012166" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012167endfun
12168
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012169" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012170" s:NetrwExe: executes a string using "!" {{{2
12171fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020012172" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +010012173 if has("win32") && &shell !~? 'cmd\|pwsh\|powershell' && !g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +020012174" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012175 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
12176 set shell& shellcmdflag& shellxquote& shellxescape&
12177 set shellquote& shellpipe& shellredir& shellslash&
12178 exe a:cmd
12179 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
12180 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012181" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012182 exe a:cmd
12183 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010012184 if v:shell_error
12185 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
12186 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012187" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012188endfun
12189
12190" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012191" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
12192fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012193 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012194" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012195 let curbuf = bufnr("%")
12196 let curwin = winnr()
12197 let iwin = 1
12198 while iwin <= winnr("$")
12199 exe iwin."wincmd w"
12200 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
12201 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
12202 let winvars= w:
12203 break
12204 endif
12205 let iwin= iwin + 1
12206 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020012207 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012208 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012209" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012210 for k in keys(winvars)
12211 let w:{k}= winvars[k]
12212 endfor
12213 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012214" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012215 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012216endfun
12217
Bram Moolenaara6878372014-03-22 21:02:50 +010012218" ---------------------------------------------------------------------
12219" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020012220" Returns: 0=success
12221" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010012222fun! s:NetrwLcd(newdir)
12223" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012224" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012225
Bram Moolenaar85850f32019-07-19 22:05:51 +020012226 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012227 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012228 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010012229 catch /^Vim\%((\a\+)\)\=:E344/
12230 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
12231 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012232 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010012233 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
12234 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020012235 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010012236 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
12237 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090012238 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010012239 endif
12240 endif
12241 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020012242 let err472= 1
12243 endtry
12244
12245 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010012246 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
12247 if exists("w:netrw_prvdir")
12248 let a:newdir= w:netrw_prvdir
12249 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020012250 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012251" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020012252 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012253" 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 +010012254 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010012255 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020012256" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
12257 return -1
12258 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012259
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020012260" call Decho("getcwd <".getcwd().">")
12261" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012262" call Dret("s:NetrwLcd 0")
12263 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010012264endfun
12265
Bram Moolenaar9964e462007-05-05 17:54:07 +000012266" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012267" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
12268" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
12269fun! s:NetrwSaveWordPosn()
12270" call Dfunc("NetrwSaveWordPosn()")
12271 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
12272" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
12273endfun
12274
12275" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012276" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
12277" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
12278fun! s:NetrwHumanReadable(sz)
12279" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
12280
12281 if g:netrw_sizestyle == 'h'
12282 if a:sz >= 1000000000
12283 let sz = printf("%.1f",a:sz/1000000000.0)."g"
12284 elseif a:sz >= 10000000
12285 let sz = printf("%d",a:sz/1000000)."m"
12286 elseif a:sz >= 1000000
12287 let sz = printf("%.1f",a:sz/1000000.0)."m"
12288 elseif a:sz >= 10000
12289 let sz = printf("%d",a:sz/1000)."k"
12290 elseif a:sz >= 1000
12291 let sz = printf("%.1f",a:sz/1000.0)."k"
12292 else
12293 let sz= a:sz
12294 endif
12295
12296 elseif g:netrw_sizestyle == 'H'
12297 if a:sz >= 1073741824
12298 let sz = printf("%.1f",a:sz/1073741824.0)."G"
12299 elseif a:sz >= 10485760
12300 let sz = printf("%d",a:sz/1048576)."M"
12301 elseif a:sz >= 1048576
12302 let sz = printf("%.1f",a:sz/1048576.0)."M"
12303 elseif a:sz >= 10240
12304 let sz = printf("%d",a:sz/1024)."K"
12305 elseif a:sz >= 1024
12306 let sz = printf("%.1f",a:sz/1024.0)."K"
12307 else
12308 let sz= a:sz
12309 endif
12310
12311 else
12312 let sz= a:sz
12313 endif
12314
12315" call Dret("s:NetrwHumanReadable ".sz)
12316 return sz
12317endfun
12318
12319" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012320" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
12321" changed sorting, etc. Also see s:NetrwSaveWordPosn().
12322fun! s:NetrwRestoreWordPosn()
12323" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012324 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000012325" call Dret("NetrwRestoreWordPosn")
12326endfun
12327
12328" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012329" s:RestoreBufVars: {{{2
12330fun! s:RestoreBufVars()
12331" call Dfunc("s:RestoreBufVars()")
12332
12333 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
12334 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
12335 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
12336 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
12337 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
12338 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
12339
12340" call Dret("s:RestoreBufVars")
12341endfun
12342
12343" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000012344" s:RemotePathAnalysis: {{{2
12345fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020012346" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000012347
Bram Moolenaara6878372014-03-22 21:02:50 +010012348 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010012349 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000012350 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010012351 let s:user = substitute(a:dirname,dirpat,'\3','')
12352 let s:machine = substitute(a:dirname,dirpat,'\4','')
12353 let s:port = substitute(a:dirname,dirpat,'\5','')
12354 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020012355 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010012356 if s:machine =~ '@'
12357 let dirpat = '^\(.*\)@\(.\{-}\)$'
12358 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
12359 let s:machine = substitute(s:machine,dirpat,'\2','')
12360 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012361
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012362" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
12363" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
12364" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
12365" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
12366" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
12367" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012368
12369" call Dret("s:RemotePathAnalysis")
12370endfun
12371
12372" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012373" s:RemoteSystem: runs a command on a remote host using ssh {{{2
12374" Returns status
12375" Runs system() on
12376" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012377" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000012378fun! s:RemoteSystem(cmd)
12379" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
12380 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012381 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 +000012382 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012383 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000012384 else
12385 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
12386 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
12387 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012388 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000012389 else
12390 let cmd= cmd.' '
12391 endif
12392 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012393" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000012394 let ret= system(cmd)
12395 endif
12396" call Dret("s:RemoteSystem ".ret)
12397 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000012398endfun
12399
12400" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012401" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012402fun! s:RestoreWinVars()
12403" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012404 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012405 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
12406 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
12407 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
12408 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
12409 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
12410 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
12411 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
12412 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
12413 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
12414 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
12415 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
12416 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000012417 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
12418 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000012419 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
12420 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
12421 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
12422" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000012423endfun
12424
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012425" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012426" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
12427"
12428" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
12429" is true) and a command, :Rexplore, which call this function.
12430"
Bram Moolenaar85850f32019-07-19 22:05:51 +020012431" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012432"
12433" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000012434fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020012435 if exists("s:netrwdrag")
12436 return
12437 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012438" 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 +010012439" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
12440" 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 +010012441
12442 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012443 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012444" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012445 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010012446 unlet w:netrw_rexfile
12447" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020012448 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012449" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012450" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
12451" 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 +020012452 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012453
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012454 " ---------------------------
12455 " :Rex issued while in a file
12456 " ---------------------------
12457
Bram Moolenaara6878372014-03-22 21:02:50 +010012458 " record current file so :Rex can return to it from netrw
12459 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012460" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010012461
12462 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012463" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010012464 return
12465 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012466" 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 +020012467 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012468 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012469 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012470 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012471 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020012472 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010012473 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020012474 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012475 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012476" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
12477 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012478" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
12479 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012480 if exists("s:rexposn_".bufnr('%'))
12481 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012482 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020012483 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012484" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012485 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012486
Bram Moolenaar85850f32019-07-19 22:05:51 +020012487 if has("syntax") && exists("g:syntax_on") && g:syntax_on
12488 if exists("s:explore_match")
12489 exe "2match netrwMarkFile /".s:explore_match."/"
12490 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010012491 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010012492
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012493" 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 +010012494" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012495endfun
12496
12497" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012498" s:SaveBufVars: save selected b: variables to s: variables {{{2
12499" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000012500fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012501" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000012502
12503 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
12504 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
12505 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
12506 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
12507 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
12508 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
12509
12510" call Dret("s:SaveBufVars")
12511endfun
12512
12513" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012514" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
12515fun! s:SavePosn(posndict)
12516" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
12517
Bram Moolenaar85850f32019-07-19 22:05:51 +020012518 if !exists("a:posndict[bufnr('%')]")
12519 let a:posndict[bufnr("%")]= []
12520 endif
12521" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12522 call add(a:posndict[bufnr("%")],winsaveview())
12523" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012524
12525" call Dret("s:SavePosn posndict")
12526 return a:posndict
12527endfun
12528
12529" ---------------------------------------------------------------------
12530" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
12531fun! s:RestorePosn(posndict)
12532" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020012533 if exists("a:posndict")
12534 if has_key(a:posndict,bufnr("%"))
12535" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12536 let posnlen= len(a:posndict[bufnr("%")])
12537 if posnlen > 0
12538 let posnlen= posnlen - 1
12539" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
12540 call winrestview(a:posndict[bufnr("%")][posnlen])
12541 call remove(a:posndict[bufnr("%")],posnlen)
12542" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
12543 endif
12544 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012545 endif
12546" call Dret("s:RestorePosn")
12547endfun
12548
12549" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012550" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000012551fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012552" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012553 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
12554 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
12555 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
12556 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
12557 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
12558 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
12559 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
12560 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
12561 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
12562 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
12563 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
12564 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
12565 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
12566 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
12567 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
12568 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
12569 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
12570 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
12571" call Dret("s:SaveWinVars")
12572endfun
12573
12574" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012575" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012576" To allow separate windows to have their own activities, such as
12577" Explore **/pattern, several variables have been made window-oriented.
12578" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012579" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012580" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012581fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010012582" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000012583 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
12584 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
12585 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
12586 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
12587 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
12588 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
12589 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
12590 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
12591 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
12592 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
12593" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012594endfun
12595
12596" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012597" s:SetRexDir: set directory for :Rexplore {{{2
12598fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012599" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012600 let w:netrw_rexdir = a:dirname
12601 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012602 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012603" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
12604" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012605" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012606" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010012607" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012608endfun
12609
12610" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012611" s:ShowLink: used to modify thin and tree listings to show links {{{2
12612fun! s:ShowLink()
12613" " call Dfunc("s:ShowLink()")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012614" " call Decho("b:netrw_curdir<".(exists("b:netrw_curdir")? b:netrw_curdir : "doesn't exist").">",'~'.expand("<slnum>"))
12615" " call Decho(printf("line#%4d: %s",line("."),getline(".")),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012616 if exists("b:netrw_curdir")
12617 norm! $?\a
12618 let fname = b:netrw_curdir.'/'.s:NetrwGetWord()
12619 let resname = resolve(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012620" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12621" " call Decho("resname <".resname.">",'~'.expand("<slnum>"))
12622" " call Decho("b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
12623 if resname =~ '^\M'.b:netrw_curdir.'/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012624 let dirlen = strlen(b:netrw_curdir)
12625 let resname = strpart(resname,dirlen+1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012626" " call Decho("resname<".resname."> (b:netrw_curdir elided)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012627 endif
12628 let modline = getline(".")."\t --> ".resname
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012629" " call Decho("fname <".fname.">",'~'.expand("<slnum>"))
12630" " call Decho("modline<".modline.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012631 setl noro ma
12632 call setline(".",modline)
12633 setl ro noma nomod
12634 endif
12635" " call Dret("s:ShowLink".((exists("fname")? ' : '.fname : 'n/a')))
12636endfun
12637
12638" ---------------------------------------------------------------------
12639" s:ShowStyle: {{{2
12640fun! s:ShowStyle()
12641 if !exists("w:netrw_liststyle")
12642 let liststyle= g:netrw_liststyle
12643 else
12644 let liststyle= w:netrw_liststyle
12645 endif
12646 if liststyle == s:THINLIST
12647 return s:THINLIST.":thin"
12648 elseif liststyle == s:LONGLIST
12649 return s:LONGLIST.":long"
12650 elseif liststyle == s:WIDELIST
12651 return s:WIDELIST.":wide"
12652 elseif liststyle == s:TREELIST
12653 return s:TREELIST.":tree"
12654 else
12655 return 'n/a'
12656 endif
12657endfun
12658
12659" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010012660" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
12661" Solution from Nicolai Weibull, vim docs (:help strlen()),
12662" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000012663fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012664" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
12665
12666 if v:version >= 703 && exists("*strdisplaywidth")
12667 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012668
Bram Moolenaar8d043172014-01-23 14:24:41 +010012669 elseif type(g:Align_xstrlen) == 1
12670 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
12671 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012672
Bram Moolenaar8d043172014-01-23 14:24:41 +010012673 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000012674 " number of codepoints (Latin a + combining circumflex is two codepoints)
12675 " (comment from TM, solution from NW)
12676 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012677
Bram Moolenaar8d043172014-01-23 14:24:41 +010012678 elseif g:Align_xstrlen == 2
12679 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000012680 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
12681 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012682 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012683
Bram Moolenaar8d043172014-01-23 14:24:41 +010012684 elseif g:Align_xstrlen == 3
12685 " virtual length (counting, for instance, tabs as anything between 1 and
12686 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000012687 " preceded by lam, one otherwise, etc.)
12688 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010012689 let modkeep= &l:mod
12690 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000012691 call setline(line("."),a:x)
12692 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010012693 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012694 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010012695 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012696
Bram Moolenaar446cb832008-06-24 21:56:24 +000012697 else
12698 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010012699 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012700 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010012701" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000012702 return ret
12703endfun
12704
12705" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012706" s:ShellEscape: shellescape(), or special windows handling {{{2
12707fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020012708 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012709 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
12710 endif
12711 let f = a:0 > 0 ? a:1 : 0
12712 return shellescape(a:s, f)
12713endfun
12714
12715" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012716" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000012717fun! s:TreeListMove(dir)
12718" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012719 let curline = getline('.')
12720 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
12721 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
12722 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
12723 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
12724 let treedepthchr = substitute(s:treedepthstring,' ','','g')
12725 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
12726" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
12727" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
12728" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
12729" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
12730" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
12731 " COMBAK : need to handle when on a directory
12732 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000012733 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012734 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012735 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012736 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012737" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012738 elseif a:dir == '[]' && nxtline != ''
12739 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020012740" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010012741 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
12742 if nl != 0
12743 NetrwKeepj norm! k
12744 else
12745 NetrwKeepj norm! G
12746 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012747" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000012748 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000012749 endif
12750
12751" call Dret("s:TreeListMove")
12752endfun
12753
12754" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000012755" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
12756" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
12757" can't be called except via emenu. But due to locale, that menu line may not be called
12758" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
12759fun! s:UpdateBuffersMenu()
12760" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020012761 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012762 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020012763 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000012764 catch /^Vim\%((\a\+)\)\=:E/
12765 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010012766 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000012767 endtry
12768 endif
12769" call Dret("s:UpdateBuffersMenu")
12770endfun
12771
12772" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000012773" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020012774" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012775fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012776" call Dfunc("s:UseBufWinVars()")
12777 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012778 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
12779 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
12780 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
12781 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
12782 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
12783 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
12784 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
12785 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
12786 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 +000012787" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000012788endfun
12789
Bram Moolenaar1afcace2005-11-25 19:54:28 +000012790" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010012791" s:UserMaps: supports user-defined UserMaps {{{2
12792" * calls a user-supplied funcref(islocal,curdir)
12793" * interprets result
12794" See netrw#UserMaps()
12795fun! s:UserMaps(islocal,funcname)
12796" call Dfunc("s:UserMaps(islocal=".a:islocal.",funcname<".a:funcname.">)")
12797
12798 if !exists("b:netrw_curdir")
12799 let b:netrw_curdir= getcwd()
12800 endif
12801 let Funcref = function(a:funcname)
12802 let result = Funcref(a:islocal)
12803
12804 if type(result) == 1
12805 " if result from user's funcref is a string...
12806" call Decho("result string from user funcref<".result.">",'~'.expand("<slnum>"))
12807 if result == "refresh"
12808" call Decho("refreshing display",'~'.expand("<slnum>"))
12809 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12810 elseif result != ""
12811" call Decho("executing result<".result.">",'~'.expand("<slnum>"))
12812 exe result
12813 endif
12814
12815 elseif type(result) == 3
12816 " if result from user's funcref is a List...
12817" call Decho("result List from user funcref<".string(result).">",'~'.expand("<slnum>"))
12818 for action in result
12819 if action == "refresh"
12820" call Decho("refreshing display",'~'.expand("<slnum>"))
12821 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
12822 elseif action != ""
12823" call Decho("executing action<".action.">",'~'.expand("<slnum>"))
12824 exe action
12825 endif
12826 endfor
12827 endif
12828
12829" call Dret("s:UserMaps")
12830endfun
12831
Bram Moolenaar85850f32019-07-19 22:05:51 +020012832" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020012833" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012834" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000012835let &cpo= s:keepcpo
12836unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000012837
Bram Moolenaar85850f32019-07-19 22:05:51 +020012838" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000012839" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020012840" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000012841" vim:ts=8 fdm=marker
Bram Moolenaar71badf92023-04-22 22:40:14 +010012842" doing autoload/netrw.vim version v172g ~57
12843" varname<g:netrw_dirhistcnt> value=0 ~1
12844" varname<s:THINLIST> value=0 ~1
12845" varname<s:LONGLIST> value=1 ~1
12846" varname<s:WIDELIST> value=2 ~1
12847" varname<s:TREELIST> value=3 ~1
12848" varname<s:MAXLIST> value=4 ~1
12849" varname<g:netrw_use_errorwindow> value=2 ~1
12850" varname<g:netrw_http_xcmd> value=-q -O ~1
12851" varname<g:netrw_http_put_cmd> value=curl -T ~1
12852" varname<g:netrw_keepj> value=keepj ~1
12853" varname<g:netrw_rcp_cmd> value=rcp ~1
12854" varname<g:netrw_rsync_cmd> value=rsync ~1
12855" varname<g:netrw_rsync_sep> value=/ ~1
12856" varname<g:netrw_scp_cmd> value=scp -q ~1
12857" varname<g:netrw_sftp_cmd> value=sftp ~1
12858" varname<g:netrw_ssh_cmd> value=ssh ~1
12859" varname<g:netrw_alto> value=0 ~1
12860" varname<g:netrw_altv> value=1 ~1
12861" varname<g:netrw_banner> value=1 ~1
12862" varname<g:netrw_browse_split> value=0 ~1
12863" varname<g:netrw_bufsettings> value=noma nomod nonu nobl nowrap ro nornu ~1
12864" varname<g:netrw_chgwin> value=-1 ~1
12865" varname<g:netrw_clipboard> value=1 ~1
12866" varname<g:netrw_compress> value=gzip ~1
12867" varname<g:netrw_ctags> value=ctags ~1
12868" varname<g:netrw_cursor> value=2 ~1
12869" (netrw) COMBAK: cuc=0 cul=0 initialization of s:netrw_cu[cl]
12870" varname<g:netrw_cygdrive> value=/cygdrive ~1
12871" varname<s:didstarstar> value=0 ~1
12872" varname<g:netrw_dirhistcnt> value=0 ~1
12873" varname<g:netrw_decompress> value={ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" } ~1
12874" varname<g:netrw_dirhistmax> value=10 ~1
12875" varname<g:netrw_errorlvl> value=0 ~1
12876" varname<g:netrw_fastbrowse> value=1 ~1
12877" varname<g:netrw_ftp_browse_reject> value=^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$ ~1
12878" varname<g:netrw_ftpmode> value=binary ~1
12879" varname<g:netrw_hide> value=1 ~1
12880" varname<g:netrw_keepdir> value=1 ~1
12881" varname<g:netrw_list_hide> value= ~1
12882" varname<g:netrw_localmkdir> value=mkdir ~1
12883" varname<g:netrw_remote_mkdir> value=mkdir ~1
12884" varname<g:netrw_liststyle> value=0 ~1
12885" varname<g:netrw_markfileesc> value=*./[\~ ~1
12886" varname<g:netrw_maxfilenamelen> value=32 ~1
12887" varname<g:netrw_menu> value=1 ~1
12888" varname<g:netrw_mkdir_cmd> value=ssh USEPORT HOSTNAME mkdir ~1
12889" varname<g:netrw_mousemaps> value=1 ~1
12890" varname<g:netrw_retmap> value=0 ~1
12891" varname<g:netrw_chgperm> value=chmod PERM FILENAME ~1
12892" varname<g:netrw_preview> value=0 ~1