blob: f920c64f8d6d8c30e96e2196c2297a5ef4adf042 [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
Luca Saccarolaa7d45612024-10-21 21:27:03 +02007" 2023 Nov 21 by Vim Project: ignore wildignore when expanding $COMSPEC (v173a)
8" 2023 Nov 22 by Vim Project: fix handling of very long filename on longlist style (v173a)
Christian Brabandt8fad5d52024-02-29 18:12:30 +01009" 2024 Feb 19 by Vim Project: (announce adoption)
10" 2024 Feb 29 by Vim Project: handle symlinks in tree mode correctly
Christian Brabandt08d24012024-04-03 22:44:27 +020011" 2024 Apr 03 by Vim Project: detect filetypes for remote edited files
Nir Lichtman1e34b952024-05-08 19:19:34 +020012" 2024 May 08 by Vim Project: cleanup legacy Win9X checks
Nir Lichtmance2ad9f2024-05-09 20:20:36 +020013" 2024 May 09 by Vim Project: remove hard-coded private.ppk
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020014" 2024 May 10 by Vim Project: recursively delete directories by default
Christian Brabandt43f2edc2024-05-13 20:56:43 +020015" 2024 May 13 by Vim Project: prefer scp over pscp
Christian Brabandt98b73eb2024-06-04 18:15:57 +020016" 2024 Jun 04 by Vim Project: set bufhidden if buffer changed, nohidden is set and buffer shall be switched (#14915)
Christian Brabandt14879472024-06-13 21:25:35 +020017" 2024 Jun 13 by Vim Project: glob() on Windows fails when a directory name contains [] (#14952)
Enno3146d632024-07-04 19:44:42 +020018" 2024 Jun 23 by Vim Project: save ad restore registers when liststyle = WIDELIST (#15077, #15114)
Damien9d57ea52024-07-22 20:23:48 +020019" 2024 Jul 22 by Vim Project: avoid endless recursion (#15318)
Christian Brabandt581d4a72024-07-23 21:14:06 +020020" 2024 Jul 23 by Vim Project: escape filename before trying to delete it (#15330)
Travis Sheltone34d0e32024-07-30 21:08:56 +020021" 2024 Jul 30 by Vim Project: handle mark-copy to same target directory (#12112)
Ivan Shapovalovc527d902024-08-02 19:43:12 +020022" 2024 Aug 02 by Vim Project: honor g:netrw_alt{o,v} for :{S,H,V}explore (#15417)
Damien7c754112024-08-15 21:58:57 +020023" 2024 Aug 15 by Vim Project: style changes, prevent E121 (#15501)
yasuda38cfa2b2024-08-22 20:54:47 +020024" 2024 Aug 22 by Vim Project: fix mf-selection highlight (#15551)
yasudac75dad02024-08-22 21:06:32 +020025" 2024 Aug 22 by Vim Project: adjust echo output of mx command (#15550)
Christian Brabandt0f5effb2024-09-15 19:17:23 +020026" 2024 Sep 15 by Vim Project: more strict confirmation dialog (#15680)
yasudac18a9d52024-09-19 18:09:51 +020027" 2024 Sep 19 by Vim Project: mf-selection highlight uses wrong pattern (#15700)
Peter Aronoffbe551da2024-09-22 11:29:40 +020028" 2024 Sep 21 by Vim Project: remove extraneous closing bracket (#15718)
Luca Saccarolaa7d45612024-10-21 21:27:03 +020029" 2024 Oct 21 by Vim Project: remove netrwFileHandlers (#15895)
Konfekt3d7e5672024-10-27 22:16:49 +010030" 2024 Oct 27 by Vim Project: clean up gx mapping (#15721)
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +010031" 2024 Oct 30 by Vim Project: fix filetype detection for remote files (#15961)
Christian Brabandt9f320692024-10-30 18:36:20 +010032" 2024 Oct 30 by Vim Project: fix x mapping on cygwin (#13687)
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010033" 2024 Oct 31 by Vim Project: add netrw#Launch() and netrw#Open() (#15962)
Tom Benham4d618002024-10-31 10:47:23 +010034" 2024 Oct 31 by Vim Project: fix E874 when browsing remote dir (#15964)
Christian Brabandta063b222024-11-07 14:30:30 +010035" 2024 Nov 07 by Vim Project: use keeppatterns to prevent polluting the search history
Tom Benham64a536d2024-11-07 21:15:03 +010036" 2024 Nov 07 by Vim Project: fix a few issues with netrw tree listing (#15996)
Christian Brabandt5b63b232024-11-10 20:22:34 +010037" 2024 Nov 10 by Vim Project: directory symlink not resolved in tree view (#16020)
Konfekt460799d2024-11-14 21:42:27 +010038" 2024 Nov 14 by Vim Project: small fixes to netrw#BrowseX (#16056)
Christian Brabandtcacfccf2024-11-23 13:28:01 +010039" 2024 Nov 23 by Vim Project: update decompress defaults (#16104)
GuyBrushd7745ac2024-11-23 14:13:10 +010040" 2024 Nov 23 by Vim Project: fix powershell escaping issues (#16094)
Travis Sheltone34d0e32024-07-30 21:08:56 +020041" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010042" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000043" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010044" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000045" Permission is hereby granted to use and distribute this code,
46" with or without modifications, provided that this copyright
47" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000048" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000049" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000050" expressed or implied. By using this plugin, you agree that
51" in no event will the copyright holder be liable for any damages
52" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010053"
54" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
55" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
56"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020057"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000058"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000059" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000060" (James 1:22 RSV)
61" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000062" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000063if &cp || exists("g:loaded_netrw")
64 finish
65endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020066
67" Check that vim has patches that netrw requires.
68" Patches needed for v7.4: 1557, and 213.
69" (netrw will benefit from vim's having patch#656, too)
70let s:needspatches=[1557,213]
71if exists("s:needspatches")
72 for ptch in s:needspatches
73 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
74 if !exists("s:needpatch{ptch}")
75 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
76 endif
77 let s:needpatch{ptch}= 1
78 finish
79 endif
80 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020081endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020082
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010083let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000084
Bram Moolenaar1afcace2005-11-25 19:54:28 +000085let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010086setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020087"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010088"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010089"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000090
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000091" ======================
92" Netrw Variables: {{{1
93" ======================
94
Bram Moolenaar071d4272004-06-13 20:20:40 +000095" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020096" netrw#ErrorMsg: {{{2
97" 0=note = s:NOTE
98" 1=warning = s:WARNING
99" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100100" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
101" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
102" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +0100103" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200104fun! netrw#ErrorMsg(level,msg,errnum)
105" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
106
107 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200108" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200109 return
110 endif
111
112 if a:level == 1
113 let level= "**warning** (netrw) "
114 elseif a:level == 2
115 let level= "**error** (netrw) "
116 else
117 let level= "**note** (netrw) "
118 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100119" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200120
Damienb4d11642024-08-15 22:00:45 +0200121 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200122 " use popup window
123 if type(a:msg) == 3
124 let msg = [level]+a:msg
125 else
126 let msg= level.a:msg
127 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200128 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200129 let s:popuperr_text= ""
130 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 " (default) netrw creates a one-line window to show error/warning
132 " messages (reliably displayed)
133
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100134 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200135 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100136" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200137
138 " getting messages out reliably is just plain difficult!
139 " This attempt splits the current window, creating a one line window.
140 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100141" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200142 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100143" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200144 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100145 if type(a:msg) == 3
146 for msg in a:msg
147 NetrwKeepj call setline(line("$")+1,level.msg)
148 endfor
149 else
150 NetrwKeepj call setline(line("$")+1,level.a:msg)
151 endif
152 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200153 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100154" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200155 bo 1split
156 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200157 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200158 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100159 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100160" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200161 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100162 if type(a:msg) == 3
163 for msg in a:msg
164 NetrwKeepj call setline(line("$")+1,level.msg)
165 endfor
166 else
167 NetrwKeepj call setline(line("$"),level.a:msg)
168 endif
169 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200170 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100171" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200172 if &fo !~ '[ta]'
173 syn clear
174 syn match netrwMesgNote "^\*\*note\*\*"
175 syn match netrwMesgWarning "^\*\*warning\*\*"
176 syn match netrwMesgError "^\*\*error\*\*"
177 hi link netrwMesgWarning WarningMsg
178 hi link netrwMesgError Error
179 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100180" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200181 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200182
183 else
184 " (optional) netrw will show messages using echomsg. Even if the
185 " message doesn't appear, at least it'll be recallable via :messages
186" redraw!
187 if a:level == s:WARNING
188 echohl WarningMsg
189 elseif a:level == s:ERROR
190 echohl Error
191 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100192
193 if type(a:msg) == 3
194 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100195 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100196 endfor
197 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100198 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100199 endif
200
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100201" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200202 echohl None
203 endif
204
205" call Dret("netrw#ErrorMsg")
206endfun
207
208" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100209" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100210" Loosely, varname = value.
211fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100212" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100213 if !exists(a:varname)
214 if type(a:value) == 0
215 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200216 elseif type(a:value) == 1 && a:value =~ '^[{[]'
217 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100218 elseif type(a:value) == 1
219 exe "let ".a:varname."="."'".a:value."'"
220 else
221 exe "let ".a:varname."=".a:value
222 endif
223 endif
224endfun
225
226" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000227" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200228call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000229if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100230 call s:NetrwInit("s:THINLIST",0)
231 call s:NetrwInit("s:LONGLIST",1)
232 call s:NetrwInit("s:WIDELIST",2)
233 call s:NetrwInit("s:TREELIST",3)
234 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000235endif
236
Damien7c754112024-08-15 21:58:57 +0200237let s:NOTE = 0
238let s:WARNING = 1
239let s:ERROR = 2
240call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
241
Bram Moolenaar9964e462007-05-05 17:54:07 +0000242" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200243" Default option values: {{{2
244let g:netrw_localcopycmdopt = ""
245let g:netrw_localcopydircmdopt = ""
246let g:netrw_localmkdiropt = ""
247let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200248
249" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000250" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200251if exists("*popup_atcursor")
252\ && has("syntax")
253\ && exists("g:syntax_on")
254\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200255 call s:NetrwInit("g:netrw_use_errorwindow",2)
256else
257 call s:NetrwInit("g:netrw_use_errorwindow",1)
258endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200259
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000260if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100261 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000262 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100263 elseif executable("curl")
264 let g:netrw_dav_cmd = "curl"
265 else
266 let g:netrw_dav_cmd = ""
267 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000268endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000269if !exists("g:netrw_fetch_cmd")
270 if executable("fetch")
271 let g:netrw_fetch_cmd = "fetch -o"
272 else
273 let g:netrw_fetch_cmd = ""
274 endif
275endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100276if !exists("g:netrw_file_cmd")
277 if executable("elinks")
278 call s:NetrwInit("g:netrw_file_cmd","elinks")
279 elseif executable("links")
280 call s:NetrwInit("g:netrw_file_cmd","links")
281 endif
282endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000283if !exists("g:netrw_ftp_cmd")
284 let g:netrw_ftp_cmd = "ftp"
285endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200286let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200287if !exists("g:netrw_ftp_options")
288 let g:netrw_ftp_options= "-i -n"
289endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000290if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100291 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100292 let g:netrw_http_cmd = "wget"
293 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100294 elseif executable("curl")
295 let g:netrw_http_cmd = "curl"
296 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200297 elseif executable("elinks")
298 let g:netrw_http_cmd = "elinks"
299 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000300 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100301 let g:netrw_http_cmd = "fetch"
302 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200303 elseif executable("links")
304 let g:netrw_http_cmd = "links"
305 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000306 else
307 let g:netrw_http_cmd = ""
308 endif
309endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100310call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100311call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100312call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
313call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200314call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200315if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200316 if executable("scp")
317 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
318 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200319 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200320 else
321 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
322 endif
323endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100324call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
325call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000326
Nir Lichtman1e34b952024-05-08 19:19:34 +0200327if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000328 \ && exists("g:netrw_use_nt_rcp")
329 \ && g:netrw_use_nt_rcp
330 \ && executable( $SystemRoot .'/system32/rcp.exe')
331 let s:netrw_has_nt_rcp = 1
332 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000333else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000334 let s:netrw_has_nt_rcp = 0
335 let s:netrw_rcpmode = ''
336endif
337
338" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000339" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000340" Cygwin Detection ------- {{{3
341if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200342 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
343 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000344 else
345 let g:netrw_cygwin= 0
346 endif
347endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000348" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100349call s:NetrwInit("g:netrw_alto" , &sb)
350call s:NetrwInit("g:netrw_altv" , &spr)
351call s:NetrwInit("g:netrw_banner" , 1)
352call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200353call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100354call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200355call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100356call s:NetrwInit("g:netrw_compress" , "gzip")
357call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200358if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
359 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
360 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000361endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200362call s:NetrwInit("g:netrw_cursor" , 2)
363let s:netrw_usercul = &cursorline
364let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200365"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100366call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000367" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200368call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200369call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Christian Brabandtcacfccf2024-11-23 13:28:01 +0100370let s:xz_opt = has('unix') ? "XZ_OPT=-T0" :
371 \ (has("win32") && &shell =~? '\vcmd(\.exe)?$' ?
372 \ "setx XZ_OPT=-T0 &&" : "")
373call s:NetrwInit("g:netrw_decompress ", "{"
374 \ .."'.lz4': 'lz4 -d',"
375 \ .."'.lzo': 'lzop -d',"
376 \ .."'.lz': 'lzip -dk',"
377 \ .."'.7z': '7za x',"
378 \ .."'.001': '7za x',"
379 \ .."'.zip': 'unzip',"
380 \ .."'.bz': 'bunzip2 -k',"
381 \ .."'.bz2': 'bunzip2 -k',"
382 \ .."'.gz': 'gunzip -k',"
383 \ .."'.lzma': 'unlzma -T0 -k',"
384 \ .."'.xz': 'unxz -T0 -k',"
385 \ .."'.zst': 'zstd -T0 -d',"
386 \ .."'.Z': 'uncompress -k',"
387 \ .."'.tar': 'tar -xvf',"
388 \ .."'.tar.bz': 'tar -xvjf',"
389 \ .."'.tar.bz2': 'tar -xvjf',"
390 \ .."'.tbz': 'tar -xvjf',"
391 \ .."'.tbz2': 'tar -xvjf',"
392 \ .."'.tar.gz': 'tar -xvzf',"
393 \ .."'.tgz': 'tar -xvzf',"
394 \ .."'.tar.lzma': '"..s:xz_opt.." tar -xvf --lzma',"
395 \ .."'.tlz': '"..s:xz_opt.." tar -xvf --lzma',"
396 \ .."'.tar.xz': '"..s:xz_opt.." tar -xvfJ',"
397 \ .."'.txz': '"..s:xz_opt.." tar -xvfJ',"
398 \ .."'.tar.zst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
399 \ .."'.tzst': '"..s:xz_opt.." tar -xvf --use-compress-program=unzstd',"
400 \ .."'.rar': '"..(executable("unrar")?"unrar x -ad":"rar x -ad").."'"
401 \ .."}")
402unlet s:xz_opt
Bram Moolenaar5c736222010-01-06 20:54:52 +0100403call s:NetrwInit("g:netrw_dirhistmax" , 10)
404call s:NetrwInit("g:netrw_fastbrowse" , 1)
405call 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 +0000406if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000407 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
408 let g:netrw_ftp_list_cmd = "ls -lF"
409 let g:netrw_ftp_timelist_cmd = "ls -tlF"
410 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000411 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000412 let g:netrw_ftp_list_cmd = "dir"
413 let g:netrw_ftp_timelist_cmd = "dir"
414 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000415 endif
416endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100417call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000418" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100419call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000420if !exists("g:netrw_ignorenetrc")
421 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
422 let g:netrw_ignorenetrc= 1
423 else
424 let g:netrw_ignorenetrc= 0
425 endif
426endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100427call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000428if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000429 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100430 if exists("g:netrw_list_cmd_options")
431 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
432 else
433 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
434 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000435 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200436 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100437 if exists("g:netrw_list_cmd_options")
438 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
439 else
440 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
441 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000442 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100443" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000444 let g:netrw_list_cmd= ""
445 endif
446endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100447call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000448" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200449if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200450 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200451 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
452endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100453if !exists("g:netrw_localcmdshell")
454 let g:netrw_localcmdshell= ""
455endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000456if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200457 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000458 if g:netrw_cygwin
459 let g:netrw_localcopycmd= "cp"
460 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000461 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200462 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000463 endif
464 elseif has("unix") || has("macunix")
465 let g:netrw_localcopycmd= "cp"
466 else
467 let g:netrw_localcopycmd= ""
468 endif
469endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100470if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200471 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100472 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200473 let g:netrw_localcopydircmd = "cp"
474 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100475 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000476 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200477 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100478 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200479 elseif has("unix")
480 let g:netrw_localcopydircmd = "cp"
481 let g:netrw_localcopydircmdopt= " -R"
482 elseif has("macunix")
483 let g:netrw_localcopydircmd = "cp"
484 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100485 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200486 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100487 endif
488endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200489if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100490 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200491 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
492endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200493if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200494 if g:netrw_cygwin
495 call s:NetrwInit("g:netrw_localmkdir","mkdir")
496 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000497 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200498 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200499 endif
500else
501 call s:NetrwInit("g:netrw_localmkdir","mkdir")
502endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200503call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200504if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200505 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200506 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
507endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000508if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200509 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000510 if g:netrw_cygwin
511 let g:netrw_localmovecmd= "mv"
512 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000513 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200514 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000515 endif
516 elseif has("unix") || has("macunix")
517 let g:netrw_localmovecmd= "mv"
518 else
519 let g:netrw_localmovecmd= ""
520 endif
521endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100522" following serves as an example for how to insert a version&patch specific test
523"if v:version < 704 || (v:version == 704 && !has("patch1107"))
524"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
526" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000527if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000528 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000529endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000530if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000531 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
532endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000533" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100534call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
535call s:NetrwInit("g:netrw_maxfilenamelen", 32)
536call s:NetrwInit("g:netrw_menu" , 1)
537call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200538call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100539call s:NetrwInit("g:netrw_retmap" , 0)
540if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
541 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200542elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100543 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
544else
545 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000546endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100547call s:NetrwInit("g:netrw_preview" , 0)
548call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100549call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100550call s:NetrwInit("g:netrw_sshport" , "-p")
551call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
552call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
553call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100554call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
555" Default values - q-s ---------- {{{3
556call s:NetrwInit("g:netrw_quickhelp",0)
557let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100558 \ "(create new) %:file d:directory",
559 \ "(windows split&open) o:horz v:vert p:preview",
560 \ "i:style qf:file info O:obtain r:reverse",
561 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
562 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
563 \ "(history) qb:list u:go up U:go down",
564 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100565" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
566call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100567if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
568 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
569else
570 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
571endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100572call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
573call s:NetrwInit("g:netrw_sort_options" , "")
574call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000575if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100576 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200577 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100578 else
579 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000580 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000581endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100582call s:NetrwInit("g:netrw_special_syntax" , 0)
583call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100584call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100585call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000586" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100587call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200588if !exists("g:netrw_xstrlen")
589 if exists("g:Align_xstrlen")
590 let g:netrw_xstrlen= g:Align_xstrlen
591 elseif exists("g:drawit_xstrlen")
592 let g:netrw_xstrlen= g:drawit_xstrlen
593 elseif &enc == "latin1" || !has("multi_byte")
594 let g:netrw_xstrlen= 0
595 else
596 let g:netrw_xstrlen= 1
597 endif
598endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100599call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200600call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100601call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200602if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000603" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000604" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100605call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200606if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200607 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200608else
Bram Moolenaarff034192013-04-24 18:51:19 +0200609 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200610endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200611call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100612call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
613call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100614if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100615 let s:treedepthstring= "│ "
616else
617 let s:treedepthstring= "| "
618endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200619call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000620
621" BufEnter event ignored by decho when following variable is true
622" Has a side effect that doau BufReadPost doesn't work, so
623" files read by network transfer aren't appropriately highlighted.
624"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625
Bram Moolenaaradc21822011-04-01 18:03:16 +0200626" ======================
627" Netrw Initialization: {{{1
628" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200629if 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 +0100630" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100631 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200632" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100633 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100634 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
635 au VimEnter * let s:initbeval= &beval
636"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100637" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
638" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
639" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
640" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
641" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
642" 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 +0200643endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200644au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200645
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200646if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100647 com! -nargs=* NetrwKeepj keepj <args>
648else
649 let g:netrw_keepj= ""
650 com! -nargs=* NetrwKeepj <args>
651endif
652
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000653" ==============================
654" Netrw Utility Functions: {{{1
655" ==============================
656
Bram Moolenaaradc21822011-04-01 18:03:16 +0200657" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100658" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100659if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100660" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100661 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100662 if &ft != "netrw"
663 return ""
664 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200665 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
666 " popup error window is still showing
667 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
668 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
669 " text under mouse hasn't changed; only close window when it changes
670 call popup_close(s:popuperr_id)
671 unlet s:popuperr_text
672 else
673 let s:popuperr_text= v:beval_text
674 endif
675 let mesg= ""
676 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 +0100677 let mesg= ""
678 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
679 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
680 elseif getline(v:beval_lnum) =~ '^"\s*/'
681 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
682 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100683 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100684 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
685 let mesg = "S: edit sorting sequence"
686 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
687 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
688 elseif v:beval_text == "Quick" || v:beval_text == "Help"
689 let mesg = "Help: press <F1>"
690 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
691 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
692 else
693 let mesg= ""
694 endif
695 return mesg
696 endfun
697"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100698" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
699" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
700" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
701" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
702" 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 +0200703endif
704
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200706" netrw#Explore: launch the local browser in the directory of the current file {{{2
707" indx: == -1: Nexplore
708" == -2: Pexplore
709" == +: this is overloaded:
710" * If Nexplore/Pexplore is in use, then this refers to the
711" indx'th item in the w:netrw_explore_list[] of items which
712" matched the */pattern **/pattern *//pattern **//pattern
713" * If Hexplore or Vexplore, then this will override
714" g:netrw_winsize to specify the qty of rows or columns the
715" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100716" 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 +0200717" dosplit==1: the window will be split before running the local browser
718" style == 0: Explore style == 1: Explore!
719" == 2: Hexplore style == 3: Hexplore!
720" == 4: Vexplore style == 5: Vexplore!
721" == 6: Texplore
722fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaarff034192013-04-24 18:51:19 +0200723 if !exists("b:netrw_curdir")
724 let b:netrw_curdir= getcwd()
Bram Moolenaarff034192013-04-24 18:51:19 +0200725 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100726
727 " record current file for Rexplore's benefit
728 if &ft != "netrw"
729 let w:netrw_rexfile= expand("%:p")
730 endif
731
732 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200733 let curdir = simplify(b:netrw_curdir)
734 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200735 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200736 let curdir= substitute(curdir,'\','/','g')
737 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100738
739 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
740 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
741 " try Explore again.
742 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100743 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200744 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
745 if a1 != a:1
746 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
747 return
748 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100749 endif
750 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200751
752 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200753 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100754" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100755 sil! let keepregstar = @*
756 sil! let keepregplus = @+
757 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200758 sil! let keepregslash= @/
759
Bram Moolenaar8d043172014-01-23 14:24:41 +0100760 " if dosplit
761 " -or- file has been modified AND file not hidden when abandoned
762 " -or- Texplore used
763 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200764 call s:SaveWinVars()
765 let winsz= g:netrw_winsize
766 if a:indx > 0
767 let winsz= a:indx
768 endif
769
770 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200771 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200772 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200773 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200774
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200775 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200777 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200778 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200779
780 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200782 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200783 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200784
785 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200787 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200788 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200789
790 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200792 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200793 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200794
795 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200796 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200797 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200798 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200799
800 elseif a:style == 6 " Texplore
801 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 exe "keepalt tabnew ".fnameescape(curdir)
803 call s:RestoreBufVars()
804 endif
805 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200806 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100807 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200808
809 if a:0 > 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200810 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaarff034192013-04-24 18:51:19 +0200811 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaarff034192013-04-24 18:51:19 +0200812 elseif a:1 == '.'
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
814 if dirname !~ '/$'
815 let dirname= dirname."/"
816 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200817 elseif a:1 =~ '\$'
Bram Moolenaarff034192013-04-24 18:51:19 +0200818 let dirname= simplify(expand(a:1))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200819 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaarff034192013-04-24 18:51:19 +0200820 let dirname= simplify(a:1)
Bram Moolenaarff034192013-04-24 18:51:19 +0200821 else
Bram Moolenaarff034192013-04-24 18:51:19 +0200822 let dirname= a:1
823 endif
824 else
825 " clear explore
Bram Moolenaarff034192013-04-24 18:51:19 +0200826 call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200827 return
828 endif
829
Bram Moolenaarff034192013-04-24 18:51:19 +0200830 if dirname =~ '\.\./\=$'
831 let dirname= simplify(fnamemodify(dirname,':p:h'))
832 elseif dirname =~ '\.\.' || dirname == '.'
833 let dirname= simplify(fnamemodify(dirname,':p'))
834 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200835
836 if dirname =~ '^\*//'
837 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
839 let starpat= 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200840 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
841
842 elseif dirname =~ '^\*\*//'
843 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200844 let pattern= substitute(dirname,'^\*\*//','','')
845 let starpat= 2
Bram Moolenaarff034192013-04-24 18:51:19 +0200846
847 elseif dirname =~ '/\*\*/'
848 " handle .../**/.../filepat
Bram Moolenaarff034192013-04-24 18:51:19 +0200849 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200850 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200851 let b:netrw_curdir = prefixdir
852 else
853 let b:netrw_curdir= getcwd().'/'.prefixdir
854 endif
855 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
856 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200857
858 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200859 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200860 let starpat= 3
Bram Moolenaarff034192013-04-24 18:51:19 +0200861
862 elseif dirname=~ '^\*\*/'
863 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
864 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200865
866 else
867 let starpat= 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 endif
869
870 if starpat == 0 && a:indx >= 0
871 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaarff034192013-04-24 18:51:19 +0200872 if dirname == ""
873 let dirname= curfiledir
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 Moolenaarff034192013-04-24 18:51:19 +0200889 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 endif
891 if exists("w:netrw_bannercnt")
892 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
893 " If one wants to return the same place in the netrw window, use :Rex instead.
894 exe w:netrw_bannercnt
895 endif
896
Bram Moolenaarff034192013-04-24 18:51:19 +0200897
898 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
899 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
900 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
901 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
902 elseif a:indx <= 0
903 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaarff034192013-04-24 18:51:19 +0200904 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200905 let s:didstarstar= 1
906 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
907 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
908 endif
909
910 if has("path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200911 if !exists("w:netrw_explore_indx")
912 let w:netrw_explore_indx= 0
913 endif
914
915 let indx = a:indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200916
917 if indx == -1
918 " Nexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200919 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100920 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 +0200921 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100922 if @* != keepregstar | sil! let @* = keepregstar | endif
923 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100924 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200925 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200926 return
927 endif
928 let indx= w:netrw_explore_indx
929 if indx < 0 | let indx= 0 | endif
930 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
931 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200932 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
933 let indx= indx + 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200934 endwhile
935 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200936
937 elseif indx == -2
938 " Pexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200939 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100940 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 +0200941 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100942 if @* != keepregstar | sil! let @* = keepregstar | endif
943 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100944 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200945 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 return
947 endif
948 let indx= w:netrw_explore_indx
949 if indx < 0 | let indx= 0 | endif
950 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
951 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200952 while indx >= 0 && curfile == w:netrw_explore_list[indx]
953 let indx= indx - 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 endwhile
955 if indx < 0 | let indx= 0 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200956
957 else
958 " Explore -- initialize
959 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100960 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200961 let w:netrw_explore_indx= 0
962 if !exists("b:netrw_curdir")
963 let b:netrw_curdir= getcwd()
964 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200965
966 " switch on starpat to build the w:netrw_explore_list of files
967 if starpat == 1
968 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200969 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100970 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200971 catch /^Vim\%((\a\+)\)\=:E480/
972 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +0200973 return
974 endtry
975 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
976 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
977
978 elseif starpat == 2
979 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200980 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100981 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200982 catch /^Vim\%((\a\+)\)\=:E480/
983 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
984 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200985 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100986 if @* != keepregstar | sil! let @* = keepregstar | endif
987 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100988 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200989 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200990 return
991 endtry
992 let s:netrw_curdir = b:netrw_curdir
993 let w:netrw_explore_list = getqflist()
994 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
995 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
996
997 elseif starpat == 3
998 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200999 let filepat= substitute(dirname,'^\*/','','')
1000 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaarff034192013-04-24 18:51:19 +02001001 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
1002 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
1003
1004 elseif starpat == 4
1005 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +02001006 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
1007 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
1008 endif " switch on starpat to build w:netrw_explore_list
1009
1010 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaarff034192013-04-24 18:51:19 +02001011
1012 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001013 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001014 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001015 if @* != keepregstar | sil! let @* = keepregstar | endif
1016 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001017 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001018 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001019 return
1020 endif
1021 endif " if indx ... endif
1022
1023 " NetrwStatusLine support - for exploring support
1024 let w:netrw_explore_indx= indx
Bram Moolenaarff034192013-04-24 18:51:19 +02001025
1026 " wrap the indx around, but issue a note
1027 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaarff034192013-04-24 18:51:19 +02001028 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
1029 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001030 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +02001031 endif
1032
1033 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaarff034192013-04-24 18:51:19 +02001034 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +02001035
Bram Moolenaarff034192013-04-24 18:51:19 +02001036 call netrw#LocalBrowseCheck(newdir)
1037 if !exists("w:netrw_liststyle")
1038 let w:netrw_liststyle= g:netrw_liststyle
1039 endif
1040 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001041 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001042 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001043 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001044 endif
1045 let w:netrw_explore_mtchcnt = indx + 1
1046 let w:netrw_explore_bufnr = bufnr("%")
1047 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001048 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaarff034192013-04-24 18:51:19 +02001049
1050 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001051 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001052 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 +02001053 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001054 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001055 if @* != keepregstar | sil! let @* = keepregstar | endif
1056 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001057 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001058 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001059 return
1060 endif
1061
1062 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001063 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1064 sil! unlet w:netrw_treedict
1065 sil! unlet w:netrw_treetop
1066 endif
1067 let newdir= dirname
1068 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001069 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001070 else
Tom Benham64a536d2024-11-07 21:15:03 +01001071 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02001072 endif
1073 endif
1074
1075 " visual display of **/ **// */ Exploration files
Bram Moolenaarff034192013-04-24 18:51:19 +02001076 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +02001077 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001078 " only update match list when current directory isn't the same as before
Bram Moolenaarff034192013-04-24 18:51:19 +02001079 let s:explore_prvdir = b:netrw_curdir
1080 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001081 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001082 if b:netrw_curdir !~ '/$'
1083 let dirlen= dirlen + 1
1084 endif
1085 let prvfname= ""
1086 for fname in w:netrw_explore_list
Bram Moolenaarff034192013-04-24 18:51:19 +02001087 if fname =~ '^'.b:netrw_curdir
1088 if s:explore_match == ""
1089 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1090 else
1091 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1092 endif
1093 elseif fname !~ '^/' && fname != prvfname
1094 if s:explore_match == ""
1095 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1096 else
1097 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1098 endif
1099 endif
1100 let prvfname= fname
1101 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02001102 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1103 exe "2match netrwMarkFile /".s:explore_match."/"
1104 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001105 endif
1106 echo "<s-up>==Pexplore <s-down>==Nexplore"
1107 else
1108 2match none
1109 if exists("s:explore_match") | unlet s:explore_match | endif
1110 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001111 endif
1112
Bram Moolenaara6878372014-03-22 21:02:50 +01001113 " since Explore may be used to initialize netrw's browser,
1114 " there's no danger of a late FocusGained event on initialization.
1115 " Consequently, set s:netrw_events to 2.
1116 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001117 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001118 if @* != keepregstar | sil! let @* = keepregstar | endif
1119 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001120 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001121 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001122endfun
1123
1124" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001125" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001126" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1127" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1128" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1129" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1130" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001131fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001132" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001133 let curwin= winnr()
1134
Bram Moolenaara6878372014-03-22 21:02:50 +01001135 if a:0 > 0 && a:1 != ""
1136 " if a netrw window is already on the left-side of the tab
1137 " and a directory has been specified, explore with that
1138 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001139 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001140 exe "1wincmd w"
1141 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001142 exe "Explore ".fnameescape(a1)
1143 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001144 let s:lexplore_win= curwin
1145 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001146 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001147 unlet t:netrw_lexposn
1148 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001149 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001150 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001151 exe curwin."wincmd w"
1152 else
1153 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001154 endif
1155
Bram Moolenaar8d043172014-01-23 14:24:41 +01001156 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001157 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001158 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001159 else
1160 let lexwinnr= 0
1161 endif
1162
1163 if lexwinnr > 0
1164 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001165 exe lexwinnr."wincmd w"
1166 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001167 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001168 close
1169 if lexwinnr < curwin
1170 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001171 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001172 if lexwinnr != curwin
1173 exe curwin."wincmd w"
1174 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001175 unlet t:netrw_lexbufnr
1176
1177 else
1178 " open netrw explorer window
1179 exe "1wincmd w"
1180 let keep_altv = g:netrw_altv
1181 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001182 if a:count != 0
1183 let netrw_winsize = g:netrw_winsize
1184 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001185 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001186 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001187 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1188 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001189 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001190 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001191 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001192 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001193 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001194 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001195 endif
1196 if a:count != 0
1197 let g:netrw_winsize = netrw_winsize
1198 endif
1199 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001200 let g:netrw_altv = keep_altv
1201 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001202 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1203 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001204 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001205 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001206 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001207 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001208 unlet t:netrw_lexposn
1209 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001210 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001211
1212 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001213 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001214 if a:rightside
1215 let g:netrw_chgwin= 1
1216 else
1217 let g:netrw_chgwin= 2
1218 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001219 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001220
Bram Moolenaar8d043172014-01-23 14:24:41 +01001221endfun
1222
1223" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001224" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001225" supports :NetrwClean -- remove netrw from first directory on runtimepath
1226" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001227fun! netrw#Clean(sys)
1228" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001229
1230 if a:sys
1231 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1232 else
1233 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1234 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001235" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001236 let diddel= 0
1237 let diddir= ""
1238
1239 if choice == 1
1240 for dir in split(&rtp,',')
1241 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001242" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001243 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1244 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1245 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1246 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1247 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1248 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 +00001249 let diddir= dir
1250 let diddel= diddel + 1
1251 if !a:sys|break|endif
1252 endif
1253 endfor
1254 endif
1255
1256 echohl WarningMsg
1257 if diddel == 0
1258 echomsg "netrw is either not installed or not removable"
1259 elseif diddel == 1
1260 echomsg "removed one copy of netrw from <".diddir.">"
1261 else
1262 echomsg "removed ".diddel." copies of netrw"
1263 endif
1264 echohl None
1265
Bram Moolenaara6878372014-03-22 21:02:50 +01001266" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001267endfun
1268
Bram Moolenaar5c736222010-01-06 20:54:52 +01001269" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001270" netrw#MakeTgt: make a target out of the directory name provided {{{2
1271fun! netrw#MakeTgt(dname)
1272" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1273 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001274 let svpos = winsaveview()
1275" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001276 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1277" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001278 if s:netrwmftgt_islocal
1279 let netrwmftgt= simplify(a:dname)
1280 else
1281 let netrwmftgt= a:dname
1282 endif
1283 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1284 " re-selected target, so just clear it
1285 unlet s:netrwmftgt s:netrwmftgt_islocal
1286 else
1287 let s:netrwmftgt= netrwmftgt
1288 endif
1289 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001290 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001291 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001292" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1293 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001294" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001295endfun
1296
Bram Moolenaara6878372014-03-22 21:02:50 +01001297" ---------------------------------------------------------------------
1298" netrw#Obtain: {{{2
1299" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001300" islocal=0 obtain from remote source
1301" =1 obtain from local source
1302" fname : a filename or a list of filenames
1303" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001304fun! netrw#Obtain(islocal,fname,...)
1305" 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 +02001306 " NetrwStatusLine support - for obtaining support
1307
1308 if type(a:fname) == 1
1309 let fnamelist= [ a:fname ]
1310 elseif type(a:fname) == 3
1311 let fnamelist= a:fname
1312 else
1313 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 +01001314" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001315 return
1316 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001317" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001318 if a:0 > 0
1319 let tgtdir= a:1
1320 else
1321 let tgtdir= getcwd()
1322 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001323" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001324
1325 if exists("b:netrw_islocal") && b:netrw_islocal
1326 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001327" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001328 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1329 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001330 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001331 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001332" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001333 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001334" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001335 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001336 if v:shell_error != 0
1337 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 +01001338" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001339 return
1340 endif
1341 endfor
1342 else
1343 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001344" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1345 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1346" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001347 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001348 if v:shell_error != 0
1349 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 +01001350" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001351 return
1352 endif
1353 endif
1354 elseif !exists("b:netrw_curdir")
1355 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1356 else
1357 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1358 endif
1359
1360 else
1361 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001362" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001363 if type(a:fname) == 1
1364 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1365 endif
1366 call s:NetrwMethod(b:netrw_curdir)
1367
1368 if b:netrw_method == 4
1369 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001370" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001371 if exists("g:netrw_port") && g:netrw_port != ""
1372 let useport= " ".g:netrw_scpport." ".g:netrw_port
1373 else
1374 let useport= ""
1375 endif
1376 if b:netrw_fname =~ '/'
1377 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1378 else
1379 let path= ""
1380 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001381 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001382 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 +02001383
1384 elseif b:netrw_method == 2
1385 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001386" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001387 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001388 let tmpbufnr= bufnr("%")
1389 setl ff=unix
1390 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001391 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001392" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001393 endif
1394
1395 if exists("b:netrw_fname") && b:netrw_fname != ""
1396 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001397" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001398 endif
1399
1400 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001401 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001402" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001403 endif
1404 for fname in fnamelist
1405 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001406" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001407 endfor
1408 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001409 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 +02001410 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001411 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001412 endif
1413 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1414 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1415 let debugkeep= &debug
1416 setl debug=msg
1417 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1418 let &debug= debugkeep
1419 endif
1420
1421 elseif b:netrw_method == 3
1422 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001423" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001424 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001425 let tmpbufnr= bufnr("%")
1426 setl ff=unix
1427
1428 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001429 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001430" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001431 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001432 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001433" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001434 endif
1435
1436 if exists("g:netrw_uid") && g:netrw_uid != ""
1437 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001438 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001439" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001440 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001441 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001442 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001443" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001444 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001445 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001446" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001447 endif
1448 endif
1449
1450 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001451 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001452" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001453 endif
1454
1455 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001456 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001457" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001458 endif
1459
1460 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001461 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001462" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001463 endif
1464
1465 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001466 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001467" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001468 endif
1469 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001470 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001471 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001472" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001473
1474 " perform ftp:
1475 " -i : turns off interactive prompting from ftp
1476 " -n unix : DON'T use <.netrc>, even though it exists
1477 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001478 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1479 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001480 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001481 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1482 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001483" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001484 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001485 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001486 endif
1487 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001488
1489 elseif b:netrw_method == 9
1490 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001491" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001492 if a:fname =~ '/'
1493 let localfile= substitute(a:fname,'^.*/','','')
1494 else
1495 let localfile= a:fname
1496 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001497 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 +02001498
Bram Moolenaarff034192013-04-24 18:51:19 +02001499 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001500 " probably a badly formed url; protocol not recognized
1501" call Dret("netrw#Obtain : unsupported method")
1502 return
1503
1504 else
1505 " protocol recognized but not supported for Obtain (yet?)
1506 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001507 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001508 endif
1509" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001510 return
1511 endif
1512
1513 " restore status line
1514 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001515 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001516 endif
1517
1518 endif
1519
1520 " cleanup
1521 if exists("tmpbufnr")
1522 if bufnr("%") != tmpbufnr
1523 exe tmpbufnr."bw!"
1524 else
1525 q!
1526 endif
1527 endif
1528
Bram Moolenaara6878372014-03-22 21:02:50 +01001529" call Dret("netrw#Obtain")
1530endfun
1531
1532" ---------------------------------------------------------------------
1533" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1534fun! netrw#Nread(mode,fname)
1535" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001536 let svpos= winsaveview()
1537" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001538 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001539" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1540 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001541
1542 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1543 if exists("w:netrw_bannercnt")
1544 " start with cursor just after the banner
1545 exe w:netrw_bannercnt
1546 endif
1547 endif
1548" call Dret("netrw#Nread")
1549endfun
1550
1551" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001552" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1553" Options get restored by s:NetrwOptionsRestore()
1554"
1555" Option handling:
1556" * save user's options (s:NetrwOptionsSave)
1557" * set netrw-safe options (s:NetrwOptionsSafe)
1558" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1559" * restore user's options (s:netrwOPtionsRestore)
1560" - restore a user option when != safe option (s:NetrwRestoreSetting)
1561" vt: (variable type) normally its either "w:" or "s:"
1562fun! s:NetrwOptionsSave(vt)
1563" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1564" 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 +02001565" 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>"))
1566" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001567
1568 if !exists("{a:vt}netrw_optionsave")
1569 let {a:vt}netrw_optionsave= 1
1570 else
1571" call Dret("s:NetrwOptionsSave : options already saved")
1572 return
1573 endif
1574" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1575
1576 " Save current settings and current directory
1577" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1578 let s:yykeep = @@
1579 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1580 let {a:vt}netrw_aikeep = &l:ai
1581 let {a:vt}netrw_awkeep = &l:aw
1582 let {a:vt}netrw_bhkeep = &l:bh
1583 let {a:vt}netrw_blkeep = &l:bl
1584 let {a:vt}netrw_btkeep = &l:bt
1585 let {a:vt}netrw_bombkeep = &l:bomb
1586 let {a:vt}netrw_cedit = &cedit
1587 let {a:vt}netrw_cikeep = &l:ci
1588 let {a:vt}netrw_cinkeep = &l:cin
1589 let {a:vt}netrw_cinokeep = &l:cino
1590 let {a:vt}netrw_comkeep = &l:com
1591 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001592 let {a:vt}netrw_cuckeep = &l:cuc
1593 let {a:vt}netrw_culkeep = &l:cul
1594" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001595 let {a:vt}netrw_diffkeep = &l:diff
1596 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001597 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1598 let {a:vt}netrw_ffkeep = &l:ff
1599 endif
1600 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1601 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001602 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001603 let {a:vt}netrw_hidkeep = &l:hidden
1604 let {a:vt}netrw_imkeep = &l:im
1605 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001606 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001607 let {a:vt}netrw_lskeep = &l:ls
1608 let {a:vt}netrw_makeep = &l:ma
1609 let {a:vt}netrw_magickeep = &l:magic
1610 let {a:vt}netrw_modkeep = &l:mod
1611 let {a:vt}netrw_nukeep = &l:nu
1612 let {a:vt}netrw_rnukeep = &l:rnu
1613 let {a:vt}netrw_repkeep = &l:report
1614 let {a:vt}netrw_rokeep = &l:ro
1615 let {a:vt}netrw_selkeep = &l:sel
1616 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001617 if !g:netrw_use_noswf
1618 let {a:vt}netrw_swfkeep = &l:swf
1619 endif
1620 let {a:vt}netrw_tskeep = &l:ts
1621 let {a:vt}netrw_twkeep = &l:tw " textwidth
1622 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1623 let {a:vt}netrw_wrapkeep = &l:wrap
1624 let {a:vt}netrw_writekeep = &l:write
1625
1626 " save a few selected netrw-related variables
1627" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1628 if g:netrw_keepdir
1629 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001630" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001631 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001632 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001633 sil! let {a:vt}netrw_starkeep = @*
1634 sil! let {a:vt}netrw_pluskeep = @+
1635 endif
1636 sil! let {a:vt}netrw_slashkeep= @/
1637
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001638" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001639" 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>"))
1640" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1641endfun
1642
1643" ---------------------------------------------------------------------
1644" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1645" Use s:NetrwSaveOptions() to save user settings
1646" Use s:NetrwOptionsRestore() to restore user settings
1647fun! s:NetrwOptionsSafe(islocal)
1648" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1649" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1650" 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>"))
1651 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1652 call s:NetrwSetSafeSetting("&l:ai",0)
1653 call s:NetrwSetSafeSetting("&l:aw",0)
1654 call s:NetrwSetSafeSetting("&l:bl",0)
1655 call s:NetrwSetSafeSetting("&l:bomb",0)
1656 if a:islocal
1657 call s:NetrwSetSafeSetting("&l:bt","nofile")
1658 else
1659 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1660 endif
1661 call s:NetrwSetSafeSetting("&l:ci",0)
1662 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001663 if g:netrw_fastbrowse > a:islocal
1664 call s:NetrwSetSafeSetting("&l:bh","hide")
1665 else
1666 call s:NetrwSetSafeSetting("&l:bh","delete")
1667 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001668 call s:NetrwSetSafeSetting("&l:cino","")
1669 call s:NetrwSetSafeSetting("&l:com","")
1670 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1671 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1672 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001673 if &go =~ 'a' | set go-=a | endif
1674 if &go =~ 'A' | set go-=A | endif
1675 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001676 call s:NetrwSetSafeSetting("&l:hid",0)
1677 call s:NetrwSetSafeSetting("&l:im",0)
1678 setl isk+=@ isk+=* isk+=/
1679 call s:NetrwSetSafeSetting("&l:magic",1)
1680 if g:netrw_use_noswf
1681 call s:NetrwSetSafeSetting("swf",0)
1682 endif
1683 call s:NetrwSetSafeSetting("&l:report",10000)
1684 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1685 call s:NetrwSetSafeSetting("&l:spell",0)
1686 call s:NetrwSetSafeSetting("&l:tw",0)
1687 call s:NetrwSetSafeSetting("&l:wig","")
1688 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001689
1690 " set up cuc and cul based on g:netrw_cursor and listing style
1691 " COMBAK -- cuc cul related
1692 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001693
1694 " allow the user to override safe options
1695" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1696 if &ft == "netrw"
1697" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1698 keepalt NetrwKeepj doau FileType netrw
1699 endif
1700
1701" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1702" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
1703" call Dret("s:NetrwOptionsSafe")
1704endfun
1705
1706" ---------------------------------------------------------------------
1707" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1708fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001709 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001710 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1711 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1712 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001713 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001714 else
1715 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001716 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001717 return
1718 endif
1719 unlet {a:vt}netrw_optionsave
1720
1721 if exists("+acd")
1722 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001723 let curdir = getcwd()
1724 let &l:acd = {a:vt}netrw_acdkeep
1725 unlet {a:vt}netrw_acdkeep
1726 if &l:acd
1727 call s:NetrwLcd(curdir)
1728 endif
1729 endif
1730 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001731 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1732 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1733 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1734 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1735 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1736 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1737 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1738 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1739 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1740 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1741 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1742 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1743 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1744 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1745 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001746 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001747 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1748 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001749 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001750 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001751 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1752 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001753 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001754 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1755 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001756 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001757 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1758 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001759 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1760 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1761 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1762 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001763 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001764 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1765 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1766 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001767 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1768 call s:NetrwRestoreSetting("s:yykeep","@@")
1769 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1770 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1771 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1772 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1773
Bram Moolenaara6878372014-03-22 21:02:50 +01001774 if exists("{a:vt}netrw_swfkeep")
1775 if &directory == ""
1776 " user hasn't specified a swapfile directory;
1777 " netrw will temporarily set the swapfile directory
1778 " to the current directory as returned by getcwd().
1779 let &l:directory= getcwd()
1780 sil! let &l:swf = {a:vt}netrw_swfkeep
1781 setl directory=
1782 unlet {a:vt}netrw_swfkeep
1783 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001784 if !g:netrw_use_noswf
1785 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1786 sil! let &l:swf= {a:vt}netrw_swfkeep
1787 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001788 unlet {a:vt}netrw_swfkeep
1789 endif
1790 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001791 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001792 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1793 if exists("{a:vt}netrw_dirkeep")
1794 call s:NetrwLcd(dirkeep)
1795 unlet {a:vt}netrw_dirkeep
1796 endif
1797 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001798 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001799 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1800 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001801 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001802 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001803
Bram Moolenaara6878372014-03-22 21:02:50 +01001804 " Moved the filetype detect here from NetrwGetFile() because remote files
1805 " were having their filetype detect-generated settings overwritten by
1806 " NetrwOptionRestore.
1807 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001808 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001809 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001810endfun
1811
1812" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001813" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1814" but only when the options' value and the safe setting differ
1815" Doing this means that netrw will not come up as having changed a
1816" setting last when it really didn't actually change it.
1817"
1818" Called from s:NetrwOptionsSafe
1819" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1820fun! s:NetrwSetSafeSetting(setting,safesetting)
1821" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001822
Bram Moolenaar85850f32019-07-19 22:05:51 +02001823 if a:setting =~ '^&'
1824" call Decho("fyi: a:setting starts with &")
1825 exe "let settingval= ".a:setting
1826" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001827
Bram Moolenaar85850f32019-07-19 22:05:51 +02001828 if settingval != a:safesetting
1829" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1830 if type(a:safesetting) == 0
1831 exe "let ".a:setting."=".a:safesetting
1832 elseif type(a:safesetting) == 1
1833 exe "let ".a:setting."= '".a:safesetting."'"
1834 else
1835 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1836 endif
1837 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001838 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001839
Bram Moolenaar85850f32019-07-19 22:05:51 +02001840" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001841endfun
1842
1843" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001844" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1845" but only if the setting value differs from the associated keepvar.
1846" Doing this means that netrw will not come up as having changed a
1847" setting last when it really didn't actually change it.
1848"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001849" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001850" keepvars are set up by s:NetrwOptionsSave
1851fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001852""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001853
Bram Moolenaar85850f32019-07-19 22:05:51 +02001854 " typically called from s:NetrwOptionsRestore
1855 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1856 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001857 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001858 if exists(a:keepvar)
1859 exe "let keepvarval= ".a:keepvar
1860 exe "let setting= ".a:setting
1861
1862"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1863"" call Decho("fyi: keepvarval=".keepvarval)
1864"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1865
1866 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001867"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001868 if type(a:setting) == 0
1869 exe "let ".a:setting."= ".keepvarval
1870 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001871 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001872 else
1873 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1874 endif
1875 endif
1876
1877 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001878 endif
1879
Bram Moolenaar85850f32019-07-19 22:05:51 +02001880"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001881endfun
1882
1883" ---------------------------------------------------------------------
1884" NetrwStatusLine: {{{2
1885fun! NetrwStatusLine()
1886
1887" vvv NetrwStatusLine() debugging vvv
1888" let g:stlmsg=""
1889" if !exists("w:netrw_explore_bufnr")
1890" let g:stlmsg="!X<explore_bufnr>"
1891" elseif w:netrw_explore_bufnr != bufnr("%")
1892" let g:stlmsg="explore_bufnr!=".bufnr("%")
1893" endif
1894" if !exists("w:netrw_explore_line")
1895" let g:stlmsg=" !X<explore_line>"
1896" elseif w:netrw_explore_line != line(".")
1897" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1898" endif
1899" if !exists("w:netrw_explore_list")
1900" let g:stlmsg=" !X<explore_list>"
1901" endif
1902" ^^^ NetrwStatusLine() debugging ^^^
1903
1904 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")
1905 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001906 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001907 let &laststatus = s:netrw_users_ls
1908 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1909 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1910 return ""
1911 else
1912 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1913 endif
1914endfun
1915
Bram Moolenaar85850f32019-07-19 22:05:51 +02001916" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001917" Netrw Transfer Functions: {{{1
1918" ===============================
1919
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001921" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001922" mode: =0 read remote file and insert before current line
1923" =1 read remote file and insert after current line
1924" =2 replace with remote file
1925" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001926fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001927" 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 +00001928
Bram Moolenaar5c736222010-01-06 20:54:52 +01001929 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001930 call s:NetrwOptionsSave("w:")
1931 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001932 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001933 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1934 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1935 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001936" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001937
Bram Moolenaar5c736222010-01-06 20:54:52 +01001938 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001939 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001940 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001941 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001942 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001943 elseif a:mode == 2 " replace with remote file
1944 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001945 elseif a:mode == 3 " skip read of file (leave as temporary)
1946 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001947 else
1948 exe a:mode
1949 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001950 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001951 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001952" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001953
Bram Moolenaar5c736222010-01-06 20:54:52 +01001954 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001955 let tmpfile= s:GetTempfile("")
1956 if tmpfile == ""
1957" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001958 return
1959 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001960
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001961 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001962
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001963 " attempt to repeat with previous host-file-etc
1964 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001965" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001966 let choice = b:netrw_lastfile
1967 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001968
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001969 else
1970 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001971" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001972
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001973 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001974 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001975 echomsg 'NetRead Usage:'
1976 echomsg ':Nread machine:path uses rcp'
1977 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1978 echomsg ':Nread "machine id password path" uses ftp'
1979 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1980 echomsg ':Nread fetch://machine/path uses fetch'
1981 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1982 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001983 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001984 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001985 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1986 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1987 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1988 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001989 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001990 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001991
Bram Moolenaar9964e462007-05-05 17:54:07 +00001992 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001993 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001994" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001995 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001996 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001997 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001998 else
1999 " case "... ... ..."
2000 let choice = strpart(choice,1,strlen(choice)-1)
2001 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002002
Bram Moolenaar9964e462007-05-05 17:54:07 +00002003 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002004 let wholechoice = wholechoice . " " . choice
2005 let ichoice = ichoice + 1
2006 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002007 if !exists("g:netrw_quiet")
2008 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
2009 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002010" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002011 return
2012 endif
2013 let choice= a:{ichoice}
2014 endwhile
2015 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2016 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 endif
2018 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002020" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002021 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002022
Bram Moolenaar5c736222010-01-06 20:54:52 +01002023 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00002024 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002025 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002026" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01002027 return
2028 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002029 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002030
Bram Moolenaar8d043172014-01-23 14:24:41 +01002031 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002032" 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 +02002033 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002034" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002035 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002036" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002037 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002039
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002040 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002041 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002042 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002043 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2044 echo "(netrw) Processing your read request..."
2045 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002046
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002047 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002048 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002049 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002050" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002051 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002052 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002053 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002054 " ER: the tmpfile is full path: rcp sees C:\... as host C
2055 if s:netrw_has_nt_rcp == 1
2056 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2057 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2058 else
2059 " Any way needed it machine contains a '.'
2060 let uid_machine = g:netrw_machine .'.'. $USERNAME
2061 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002063 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2064 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2065 else
2066 let uid_machine = g:netrw_machine
2067 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002068 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002069 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 +00002070 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002071 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002072
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002074 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002076" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002077 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002078 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002079 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002080 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002081 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002082" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002083 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002084 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002085" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002086 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002087 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002088" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002089 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002090 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 +00002091 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002092 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002093 endif
2094 " 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 +00002095 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002096 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002097 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002098 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002099 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002100 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002101 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002102 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002103 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2104 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002105 q!
2106 endif
2107 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002108 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002110
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002111 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002112 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002113 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2114 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002115" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002116 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002117 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002118 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002119 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002120 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002121 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002122" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002124 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002125" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002126 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002127
Bram Moolenaar97d62492012-11-15 21:28:22 +01002128 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002129 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002130 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002131" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002132 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002133 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002134 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002135" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002136 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002137 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002138" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002139 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002141
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002142 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002143 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002144" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002145 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002146 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002147 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002148" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002149 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002150 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002151" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002152
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002153 " perform ftp:
2154 " -i : turns off interactive prompting from ftp
2155 " -n unix : DON'T use <.netrc>, even though it exists
2156 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002157 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002158 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002159 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2160 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002161" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002162 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002163 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002164 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002165 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002166 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002167 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002168 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002169
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002170 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002171 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002172 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002173" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002174 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002175 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002176 else
2177 let useport= ""
2178 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002179 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2180 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002181 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002182 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2183 else
2184 let tmpfile_get = tmpfile
2185 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002186 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 +00002187 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002188 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002189
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002190 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002191 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002192 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002193" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002194 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002195 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002196 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002197 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002198" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002199 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002200 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002201
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002202 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2203 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002204" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002205 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002206 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 +00002207 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002208 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 +00002209 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002210 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002211
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002212 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002213 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002214" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002215 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2216 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002217" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2218" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2219 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 +00002220 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002221" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002222 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002223 endif
2224 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002225" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002226 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002227
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002228 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002229 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002230 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002231" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002232
Bram Moolenaar5c736222010-01-06 20:54:52 +01002233 if !executable(g:netrw_dav_cmd)
2234 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2235" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2236 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002237 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002238 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002239 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 +01002240 else
2241 " Construct execution string (four lines) which will be passed through filter
2242 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2243 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002244 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002245 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002246 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002247 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002248 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002249 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002250 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002251 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002252 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002253 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2254 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002255
Bram Moolenaar5c736222010-01-06 20:54:52 +01002256 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002257 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002258 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002259 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002260 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002261 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002262 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002263
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002264 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002265 " NetRead: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002266 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002267" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002268 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 +00002269 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002270 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002271
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002273 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002275 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002276" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002277 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002278 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002279 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002280 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002281" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002282 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002283 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002284 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002285 let netrw_option= "http"
2286 else
2287 let netrw_option= "ftp"
2288 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002289" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002290
Bram Moolenaar446cb832008-06-24 21:56:24 +00002291 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002292 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 +00002293 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002294 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 +00002295 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002296
Bram Moolenaar446cb832008-06-24 21:56:24 +00002297 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002298 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002299" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002300 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002301
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002303 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002304 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002305" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2306 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 +00002307 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002308 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002309
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002311 " NetRead: (file) NetRead Method #10 {{{3
2312 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002313" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2314 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002315 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2316 let b:netrw_lastfile = choice
2317
2318 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002319 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002320 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002321 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002322 endif
2323 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002324
Bram Moolenaar5c736222010-01-06 20:54:52 +01002325 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002326 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002327" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002328 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002329 unlet b:netrw_fname
2330 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002331 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 +01002332" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002333 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002334 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002335 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002336
Bram Moolenaar9964e462007-05-05 17:54:07 +00002337" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002338endfun
2339
2340" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002341" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002342fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002343" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002344
Bram Moolenaar5c736222010-01-06 20:54:52 +01002345 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002346 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002347 call s:NetrwOptionsSave("w:")
2348 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002349
Bram Moolenaar5c736222010-01-06 20:54:52 +01002350 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002351 let tmpfile= s:GetTempfile("")
2352 if tmpfile == ""
2353" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002354 return
2355 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002356
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002357 if a:0 == 0
2358 let ichoice = 0
2359 else
2360 let ichoice = 1
2361 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002362
Bram Moolenaar9964e462007-05-05 17:54:07 +00002363 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002364" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002365 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002366 " For binary writes, always write entire file.
2367 " (line numbers don't really make sense for that).
2368 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002369" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002370 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002371 elseif g:netrw_cygwin
2372 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002373 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002374" 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 +01002375 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002376 else
2377 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002378" 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 +01002379 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002380 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002381
Bram Moolenaar9964e462007-05-05 17:54:07 +00002382 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002383 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002384 " on the temporary file's name. Deletion of the temporary file during
2385 " cleanup then causes an error message.
2386 0file!
2387 endif
2388
Bram Moolenaar5c736222010-01-06 20:54:52 +01002389 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002391
Bram Moolenaar9964e462007-05-05 17:54:07 +00002392 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002393 " attempt to repeat with previous host-file-etc
2394 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002395" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002396 let choice = b:netrw_lastfile
2397 let ichoice= ichoice + 1
2398 else
2399 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002400
Bram Moolenaar8d043172014-01-23 14:24:41 +01002401 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002402 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002403 echomsg 'NetWrite Usage:"'
2404 echomsg ':Nwrite machine:path uses rcp'
2405 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2406 echomsg ':Nwrite "machine id password path" uses ftp'
2407 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2408 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2409 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2410 echomsg ':Nwrite rcp://machine/path uses rcp'
2411 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2412 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2413 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002414 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002415 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002416
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002417 elseif match(choice,"^\"") != -1
2418 if match(choice,"\"$") != -1
2419 " case "..."
2420 let choice=strpart(choice,1,strlen(choice)-2)
2421 else
2422 " case "... ... ..."
2423 let choice = strpart(choice,1,strlen(choice)-1)
2424 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002425
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002426 while match(choice,"\"$") == -1
2427 let wholechoice= wholechoice . " " . choice
2428 let ichoice = ichoice + 1
2429 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002430 if !exists("g:netrw_quiet")
2431 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2432 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002433" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002434 return
2435 endif
2436 let choice= a:{ichoice}
2437 endwhile
2438 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2439 endif
2440 endif
2441 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002442 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002443" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002444
Bram Moolenaar9964e462007-05-05 17:54:07 +00002445 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002446 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002447 if !exists("b:netrw_method") || b:netrw_method < 0
2448" call Dfunc("netrw#NetWrite : unsupported method")
2449 return
2450 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002451
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002452 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002453 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002454 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002455 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2456 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002457" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002458 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002459
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002460 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002461 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002462 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002463" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002464 if s:netrw_has_nt_rcp == 1
2465 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2466 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2467 else
2468 let uid_machine = g:netrw_machine .'.'. $USERNAME
2469 endif
2470 else
2471 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2472 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2473 else
2474 let uid_machine = g:netrw_machine
2475 endif
2476 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002477 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 +00002478 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002479
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002480 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002481 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002482 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002483" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002484 let netrw_fname = b:netrw_fname
2485
2486 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2487 let bhkeep = &l:bh
2488 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002489 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002490 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002491
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002492" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002493 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002494 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002495" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002496 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002497 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002498" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002499 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002500 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002501" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002503 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 +00002504 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002505" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2506 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 endif
2508 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2509 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002510 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002511 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002512 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002513 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002515
2516 " remove enew buffer (quietly)
2517 let filtbuf= bufnr("%")
2518 exe curbuf."b!"
2519 let &l:bh = bhkeep
2520 exe filtbuf."bw!"
2521
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002523
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002524 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002525 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002526 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002527 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002528" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002529 let netrw_fname = b:netrw_fname
2530 let bhkeep = &l:bh
2531
2532 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2533 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002534 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002535 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002536 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002537
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002538 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002539 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002540" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002541 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002542 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002543" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002544 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002545 if exists("g:netrw_uid") && g:netrw_uid != ""
2546 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002547 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002548" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002549 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002550 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002551 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002552" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002553 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002554 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002555" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002556 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002557 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002558 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002559" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002560 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002561 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002562" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002563 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002564 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002565" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002566 " save choice/id/password for future use
2567 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002568
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002569 " perform ftp:
2570 " -i : turns off interactive prompting from ftp
2571 " -n unix : DON'T use <.netrc>, even though it exists
2572 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002573 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002574 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002575 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2576 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002577 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002578 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002579 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002580 let mod=1
2581 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002582
2583 " remove enew buffer (quietly)
2584 let filtbuf= bufnr("%")
2585 exe curbuf."b!"
2586 let &l:bh= bhkeep
2587 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002588
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002589 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002590 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002591 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002592" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002593 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002594 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002595 else
2596 let useport= ""
2597 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002598 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 +00002599 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002600
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002601 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002602 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002603 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002604" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002605 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2606 if executable(curl)
2607 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002608 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 +01002609 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002610 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002611 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002612
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002613 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002614 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002615 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002616" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002617
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002618 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002619 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2620 let bhkeep = &l:bh
2621
2622 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2623 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002624 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002625 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002626
Bram Moolenaarff034192013-04-24 18:51:19 +02002627 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002628 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002629 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002630 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002631 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002632 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002633 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002634 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002635 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002636 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002637
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002638 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002639 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002640 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002641
2642 " remove enew buffer (quietly)
2643 let filtbuf= bufnr("%")
2644 exe curbuf."b!"
2645 let &l:bh = bhkeep
2646 exe filtbuf."bw!"
2647
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002648 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002649
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002650 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002651 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002652 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002653" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002654 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 +00002655 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002656
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002657 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002658 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002659 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002661 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002662 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2663 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2664 else
2665 let uid_machine = g:netrw_machine
2666 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002667
2668 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2669 let bhkeep = &l:bh
2670 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002671 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002672 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002673
Bram Moolenaarff034192013-04-24 18:51:19 +02002674 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002675 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002676" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002677 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002678 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002679 let filtbuf= bufnr("%")
2680 exe curbuf."b!"
2681 let &l:bh = bhkeep
2682 exe filtbuf."bw!"
2683 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002684
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002685 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002686 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002687 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002688 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002689 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002691 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002692
Bram Moolenaar5c736222010-01-06 20:54:52 +01002693 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002694" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002695 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002696" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002697 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002698 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002699 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002700
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002701 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002702 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002703 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002704" 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 +02002705 elseif !exists("leavemod")
2706 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002707" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002708 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002709" 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 +00002710 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002711
Bram Moolenaar9964e462007-05-05 17:54:07 +00002712" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002713endfun
2714
2715" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002716" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002717" uses NetRead to get a copy of the file into a temporarily file,
2718" then sources that file,
2719" then removes that file.
2720fun! netrw#NetSource(...)
2721" call Dfunc("netrw#NetSource() a:0=".a:0)
2722 if a:0 > 0 && a:1 == '?'
2723 " give help
2724 echomsg 'NetSource Usage:'
2725 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2726 echomsg ':Nsource fetch://machine/path uses fetch'
2727 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002728 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002729 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2730 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2731 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2732 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2733 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002734 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002735 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002736 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002737 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002738" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002739 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002740" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002741 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002742" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002743 if delete(s:netrw_tmpfile)
2744 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2745 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002746 unlet s:netrw_tmpfile
2747 else
2748 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2749 endif
2750 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002751 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002752 endif
2753" call Dret("netrw#NetSource")
2754endfun
2755
Bram Moolenaar8d043172014-01-23 14:24:41 +01002756" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002757" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2758" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002759fun! netrw#SetTreetop(iscmd,...)
Bram Moolenaara6878372014-03-22 21:02:50 +01002760
Bram Moolenaar85850f32019-07-19 22:05:51 +02002761 " iscmd==0: netrw#SetTreetop called using gn mapping
2762 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
Bram Moolenaar8d043172014-01-23 14:24:41 +01002763 " clear out the current tree
2764 if exists("w:netrw_treetop")
2765 let inittreetop= w:netrw_treetop
2766 unlet w:netrw_treetop
2767 endif
2768 if exists("w:netrw_treedict")
2769 unlet w:netrw_treedict
2770 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002771
Bram Moolenaar85850f32019-07-19 22:05:51 +02002772 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002773 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002774 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002775 if isdirectory(s:NetrwFile(a:1))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002776 let treedir = a:1
2777 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002778 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002779 let treedir = b:netrw_curdir."/".a:1
2780 let s:netrw_treetop = treedir
Bram Moolenaar8d043172014-01-23 14:24:41 +01002781 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002782 " normally the cursor is left in the message window.
2783 " However, here this results in the directory being listed in the message window, which is not wanted.
2784 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002785 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002787 let treedir = "."
2788 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002789 endif
2790 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002791
2792 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002793 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02002794
2795 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002796 if islocal
Tom Benham64a536d2024-11-07 21:15:03 +01002797 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002798 else
Tom Benham64a536d2024-11-07 21:15:03 +01002799 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002800 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002801
Bram Moolenaar8d043172014-01-23 14:24:41 +01002802endfun
2803
Bram Moolenaar9964e462007-05-05 17:54:07 +00002804" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002805" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002806" readcmd == %r : replace buffer with newly read file
2807" == 0r : read file at top of buffer
2808" == r : read file after current line
2809" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002810fun! s:NetrwGetFile(readcmd, tfile, method)
2811" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002812
2813 " readcmd=='t': simply do nothing
2814 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002815" 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 +01002816" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002817 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002818 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002819
Bram Moolenaar9964e462007-05-05 17:54:07 +00002820 " get name of remote filename (ie. url and all)
2821 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002823
Bram Moolenaar9964e462007-05-05 17:54:07 +00002824 if exists("*NetReadFixup")
2825 " for the use of NetReadFixup (not otherwise used internally)
2826 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002827 endif
2828
Bram Moolenaar9964e462007-05-05 17:54:07 +00002829 if a:readcmd[0] == '%'
2830 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002831" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002832
2833 " rename the current buffer to the temp file (ie. tfile)
2834 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002835 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002836 else
2837 let tfile= a:tfile
2838 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002839 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002840
2841 " edit temporary file (ie. read the temporary file in)
2842 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002843" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002844 call zip#Browse(tfile)
2845 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002846" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002847 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002848 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002849" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002850 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002851 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002853 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002854 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002855" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002856 call tar#Browse(tfile)
2857 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002858" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002859 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002860 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002861" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002862 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002863 endif
2864
2865 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002866 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002867
Bram Moolenaar71badf92023-04-22 22:40:14 +01002868 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002869 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002870 " Note that isk must not include a "/" for scripts.vim
2871 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002872" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2873" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002874" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002875" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2876 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002877 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002878 filetype detect
2879" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002880 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002881" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002882 let line1 = 1
2883 let line2 = line("$")
2884
Bram Moolenaar8d043172014-01-23 14:24:41 +01002885 elseif !&ma
2886 " attempting to read a file after the current line in the file, but the buffer is not modifiable
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002887 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002888" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002889 return
2890
Bram Moolenaar9964e462007-05-05 17:54:07 +00002891 elseif s:FileReadable(a:tfile)
2892 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002893" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002894 let curline = line(".")
2895 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002896" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002897 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002898 let line1= curline + 1
2899 let line2= line("$") - lastline + 1
2900
2901 else
2902 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002903" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2904" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002905 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002906" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002907 return
2908 endif
2909
2910 " User-provided (ie. optional) fix-it-up command
2911 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002912" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002913 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002914" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002915" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002916 endif
2917
Bram Moolenaaradc21822011-04-01 18:03:16 +02002918 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002919 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002920 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002921 endif
2922
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002923" call Decho("readcmd<".a:readcmd."> cmdarg<".v:cmdarg."> tfile<".a:tfile."> readable=".s:FileReadable(a:tfile),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002924
2925 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002926" redraw!
2927
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002928" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00002929" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002930endfun
2931
Bram Moolenaar9964e462007-05-05 17:54:07 +00002932" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002933" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002934" Input:
2935" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2936" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002937" b:netrw_method= 1: rcp
2938" 2: ftp + <.netrc>
2939" 3: ftp + machine, id, password, and [path]filename
2940" 4: scp
2941" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002942" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002943" 7: rsync
2944" 8: fetch
2945" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002946" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002947" g:netrw_machine= hostname
2948" b:netrw_fname = filename
2949" g:netrw_port = optional port number (for ftp)
2950" g:netrw_choice = copy of input url (choice)
2951fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002952" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002953
Bram Moolenaar251e1912011-06-19 05:09:16 +02002954 " sanity check: choice should have at least three slashes in it
2955 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2956 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2957 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002958" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002959 return
2960 endif
2961
Bram Moolenaar5c736222010-01-06 20:54:52 +01002962 " record current g:netrw_machine, if any
2963 " curmachine used if protocol == ftp and no .netrc
2964 if exists("g:netrw_machine")
2965 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002966" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002967 else
2968 let curmachine= "N O T A HOST"
2969 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002970 if exists("g:netrw_port")
2971 let netrw_port= g:netrw_port
2972 endif
2973
2974 " insure that netrw_ftp_cmd starts off every method determination
2975 " with the current g:netrw_ftp_cmd
2976 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002977
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002978 " initialization
2979 let b:netrw_method = 0
2980 let g:netrw_machine = ""
2981 let b:netrw_fname = ""
2982 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002983 let g:netrw_choice = a:choice
2984
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002985 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002986 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002987 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2988 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002989 " rcpurm : rcp://[user@]host/filename Use rcp
2990 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002991 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002992 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002993 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002994 " rsyncurm : rsync://host[:port]/path Use rsync
2995 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2996 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002997 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002998 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2999 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003000 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
3001 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003002 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003003 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003004 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003005 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003006 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02003007 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003008 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003009 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003010
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003011" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003012 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02003013 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003014 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003015" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00003016 let b:netrw_method = 1
3017 let userid = substitute(a:choice,rcpurm,'\1',"")
3018 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
3019 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003020 if userid != ""
3021 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003023
Bram Moolenaaradc21822011-04-01 18:03:16 +02003024 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003025 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003026" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003027 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00003028 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
3029 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
3030 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003031
Bram Moolenaar15146672011-10-20 22:22:38 +02003032 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003033 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003034" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003035 let b:netrw_method = 5
3036 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3037 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003038 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003039
Bram Moolenaaradc21822011-04-01 18:03:16 +02003040 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003041 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003042" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003043 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003044 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003045 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3046 else
3047 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3048 endif
3049 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003050
Bram Moolenaaradc21822011-04-01 18:03:16 +02003051 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003052 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003053" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003054 let b:netrw_method = 7
3055 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3056 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003057
Bram Moolenaaradc21822011-04-01 18:03:16 +02003058 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003059 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003060" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003061 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003062 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3063 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3064 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003065" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003066 if userid != ""
3067 let g:netrw_uid= userid
3068 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003069
Bram Moolenaaradc21822011-04-01 18:03:16 +02003070 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003071 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003072 call NetUserPass("ftp:".g:netrw_machine)
3073 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003074 " if there's a change in hostname, require password re-entry
3075 unlet s:netrw_passwd
3076 endif
3077 if exists("netrw_port")
3078 unlet netrw_port
3079 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003080 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003081
Bram Moolenaar446cb832008-06-24 21:56:24 +00003082 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003083 let b:netrw_method = 3
3084 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003085 let host= substitute(g:netrw_machine,'\..*$','','')
3086 if exists("s:netrw_hup[host]")
3087 call NetUserPass("ftp:".host)
3088
Nir Lichtman1e34b952024-05-08 19:19:34 +02003089 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003090" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3091" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003092 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003093 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003094" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003095 endif
3096 let b:netrw_method= 2
3097 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003098" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003099 let b:netrw_method= 2
3100 else
3101 if !exists("g:netrw_uid") || g:netrw_uid == ""
3102 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003103 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003104 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003105 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003106 endif
3107 let b:netrw_method= 3
3108 endif
3109 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003110
Bram Moolenaaradc21822011-04-01 18:03:16 +02003111 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003112 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003113" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003114 let b:netrw_method = 8
3115 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3116 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3117 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3118 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003119
Bram Moolenaaradc21822011-04-01 18:03:16 +02003120 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003121 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003122" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003124 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3125 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003126 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003127 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003128 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003129
Bram Moolenaaradc21822011-04-01 18:03:16 +02003130 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003131 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003132" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003133 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003134 let b:netrw_method = 3
3135 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3136 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003137
Bram Moolenaar9964e462007-05-05 17:54:07 +00003138 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003139 let b:netrw_method = 2
3140 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3141 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3142 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003143
Bram Moolenaaradc21822011-04-01 18:03:16 +02003144 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003145 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003146" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003147 let b:netrw_method = 9
3148 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3149 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003150
Bram Moolenaaradc21822011-04-01 18:03:16 +02003151 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003152 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003153" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003154 let b:netrw_method = 1
3155 let userid = substitute(a:choice,rcphf,'\2',"")
3156 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3157 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003158" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3159" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3160" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3161" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003162 if userid != ""
3163 let g:netrw_uid= userid
3164 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003165
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003166 " Method#10: file://user@hostname/...path-to-file {{{3
3167 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003168" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003169 let b:netrw_method = 10
3170 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003171" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003172
Bram Moolenaaradc21822011-04-01 18:03:16 +02003173 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003174 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003175 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003176 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003177 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003178 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003180 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003181
Bram Moolenaar81695252004-12-29 20:58:21 +00003182 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003183 " remove any leading [:#] from port number
3184 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3185 elseif exists("netrw_port")
3186 " retain port number as implicit for subsequent ftp operations
3187 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003188 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003189
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003190" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3191" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3192" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3193" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003194" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003195" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003196" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003197" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003198" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003199" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003200" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003201" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203
Bram Moolenaar9964e462007-05-05 17:54:07 +00003204" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003205" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003206" Usage: :call NetUserPass() -- will prompt for userid and password
3207" :call NetUserPass("uid") -- will prompt for password
3208" :call NetUserPass("uid","password") -- sets global userid and password
3209" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3210" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211fun! NetUserPass(...)
3212
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003213" call Dfunc("NetUserPass() a:0=".a:0)
3214
3215 if !exists('s:netrw_hup')
3216 let s:netrw_hup= {}
3217 endif
3218
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003220 " case: no input arguments
3221
3222 " change host and username if not previously entered; get new password
3223 if !exists("g:netrw_machine")
3224 let g:netrw_machine= input('Enter hostname: ')
3225 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003227 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228 let g:netrw_uid= input('Enter username: ')
3229 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003230 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003231 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003232
3233 " set up hup database
3234 let host = substitute(g:netrw_machine,'\..*$','','')
3235 if !exists('s:netrw_hup[host]')
3236 let s:netrw_hup[host]= {}
3237 endif
3238 let s:netrw_hup[host].uid = g:netrw_uid
3239 let s:netrw_hup[host].passwd = s:netrw_passwd
3240
3241 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003242 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003243
3244 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003245 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003246 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003247" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003248 let host = substitute(a:1,'^ftp:','','')
3249 let host = substitute(host,'\..*','','')
3250 if exists("s:netrw_hup[host]")
3251 let g:netrw_uid = s:netrw_hup[host].uid
3252 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003253" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3254" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003255 else
3256 let g:netrw_uid = input("Enter UserId: ")
3257 let s:netrw_passwd = inputsecret("Enter Password: ")
3258 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003259
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003260 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003261 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003262" 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 +02003263 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003264 if g:netrw_machine =~ '[0-9.]\+'
3265 let host= g:netrw_machine
3266 else
3267 let host= substitute(g:netrw_machine,'\..*$','','')
3268 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003269 else
3270 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003271 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003272 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003273" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003274 if exists("g:netrw_passwd")
3275 " ask for password if one not previously entered
3276 let s:netrw_passwd= g:netrw_passwd
3277 else
3278 let s:netrw_passwd = inputsecret("Enter Password: ")
3279 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003280 endif
3281
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003282" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003283 if exists("host")
3284 if !exists('s:netrw_hup[host]')
3285 let s:netrw_hup[host]= {}
3286 endif
3287 let s:netrw_hup[host].uid = g:netrw_uid
3288 let s:netrw_hup[host].passwd = s:netrw_passwd
3289 endif
3290
3291 elseif a:0 == 2
3292 let g:netrw_uid = a:1
3293 let s:netrw_passwd = a:2
3294
3295 elseif a:0 == 3
3296 " enter hostname, user-id, and password into the hup dictionary
3297 let host = substitute(a:1,'^\a\+:','','')
3298 let host = substitute(host,'\..*$','','')
3299 if !exists('s:netrw_hup[host]')
3300 let s:netrw_hup[host]= {}
3301 endif
3302 let s:netrw_hup[host].uid = a:2
3303 let s:netrw_hup[host].passwd = a:3
3304 let g:netrw_uid = s:netrw_hup[host].uid
3305 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003306" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3307" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003309
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003310" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312
Bram Moolenaar85850f32019-07-19 22:05:51 +02003313" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003314" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003315" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003317" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003318" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3319fun! s:ExplorePatHls(pattern)
3320" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3321 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003322" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003323 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003324" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003325 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3326" call Dret("s:ExplorePatHls repat<".repat.">")
3327 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003328endfun
3329
3330" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003331" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003332" 0: (user: <mb>) bookmark current directory
3333" 1: (user: <gb>) change to the bookmarked directory
3334" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003335" 3: (browsing) records current directory history
3336" 4: (user: <u>) go up (previous) directory, using history
3337" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003338" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003339fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003340" 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 +02003341 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3342" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3343 return
3344 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003345
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003346 let ykeep = @@
3347 let curbufnr = bufnr("%")
3348
Bram Moolenaar9964e462007-05-05 17:54:07 +00003349 if a:chg == 0
3350 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003351" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003352 if exists("s:netrwmarkfilelist_{curbufnr}")
3353 call s:NetrwBookmark(0)
3354 echo "bookmarked marked files"
3355 else
3356 call s:MakeBookmark(a:curdir)
3357 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003358 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003359
KSR-Yasudaf4498252023-10-06 03:34:17 +09003360 try
3361 call s:NetrwBookHistSave()
3362 catch
3363 endtry
3364
Bram Moolenaar9964e462007-05-05 17:54:07 +00003365 elseif a:chg == 1
3366 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003367" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003368 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003369" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003370 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003371 else
3372 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3373 endif
3374
3375 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003376" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003377 let didwork= 0
3378 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003379" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003380 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003381" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003382 let cnt= 1
3383 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003384" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003385 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003386 let didwork = 1
3387 let cnt = cnt + 1
3388 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003389 endif
3390
3391 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003392 " Note: history is saved only when PerformListing is done;
3393 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3394 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003395 let first = 1
3396 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003397 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003398 while ( first || cnt != g:netrw_dirhistcnt )
3399" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003400 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003401" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003402 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003403 let didwork= 1
3404 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003405 let histcnt = histcnt + 1
3406 let first = 0
3407 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003408 if cnt < 0
3409 let cnt= cnt + g:netrw_dirhistmax
3410 endif
3411 endwhile
3412 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003413 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003414 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003415 if didwork
3416 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3417 endif
3418
3419 elseif a:chg == 3
3420 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003421" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003422 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 +02003423 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003424 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3425 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003426 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003427" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003428 endif
3429
3430 elseif a:chg == 4
3431 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003432" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003433 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003434 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3435 if g:netrw_dirhistcnt < 0
3436 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003437 endif
3438 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003439 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003440 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003441 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3442" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003443 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003444 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003445" call Decho("setl ma noro",'~'.expand("<slnum>"))
3446 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003447 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003448" call Decho("setl nomod",'~'.expand("<slnum>"))
3449" 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 +00003450 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003451" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3452 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003453 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003454 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003455 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003456 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003457 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003458 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003459 echo "Sorry, no predecessor directory exists yet"
3460 endif
3461
3462 elseif a:chg == 5
3463 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003464" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003465 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003466 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3467 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3468" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003469 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003470" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003471 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003472 sil! NetrwKeepj %d _
3473" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3474" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003475 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003476" 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 +02003477 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003478" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3479 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003480 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003481 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3482 if g:netrw_dirhistcnt < 0
3483 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003484 endif
3485 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003486 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003487 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003488 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003489 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003490 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003491
3492 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003493" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003494 if exists("s:netrwmarkfilelist_{curbufnr}")
3495 call s:NetrwBookmark(1)
3496 echo "removed marked files from bookmarks"
3497 else
3498 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003499 let iremove = v:count
3500 let dremove = g:netrw_bookmarklist[iremove - 1]
3501" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003502 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003503" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3504 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3505 echo "removed ".dremove." from g:netrw_bookmarklist"
3506" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003507 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003508" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003509
3510 try
3511 call s:NetrwBookHistSave()
3512 catch
3513 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003514 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003515 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003516 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003517 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003518" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003519endfun
3520
3521" ---------------------------------------------------------------------
3522" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003523" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003524" Sister function: s:NetrwBookHistSave()
3525fun! s:NetrwBookHistRead()
3526" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003527 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003528" 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 +02003529 return
3530 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003531 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003532
3533 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003534 if !exists("s:netrw_initbookhist")
3535 let home = s:NetrwHome()
3536 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003537 if filereadable(s:NetrwFile(savefile))
3538" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003539 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003540 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003541
3542 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003543 if g:netrw_dirhistmax > 0
3544 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003545 if filereadable(s:NetrwFile(savefile))
3546" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003547 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003548 endif
3549 let s:netrw_initbookhist= 1
3550 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003551 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003552 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003553
Bram Moolenaar97d62492012-11-15 21:28:22 +01003554 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003555" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3556" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003557" call Dret("s:NetrwBookHistRead")
3558endfun
3559
3560" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003561" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003562" Sister function: s:NetrwBookHistRead()
3563" I used to do this via viminfo but that appears to
3564" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003565" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3566" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003567" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003568fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003569" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003570 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003571" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003572 return
3573 endif
3574
Bram Moolenaar5c736222010-01-06 20:54:52 +01003575 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003576" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003577 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003578
3579 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003580 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003581" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003582 if g:netrw_use_noswf
3583 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3584 else
3585 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3586 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003587 setl nocin noai noci magic nospell nohid wig= noaw
3588 setl ma noro write
3589 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003590 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003591
Bram Moolenaar85850f32019-07-19 22:05:51 +02003592 " rename enew'd file: .netrwhist -- no attempt to merge
3593 " record dirhistmax and current dirhistcnt
3594 " save history
3595" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003596 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003597 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003598 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3599 if g:netrw_dirhistmax > 0
3600 let lastline = line("$")
3601 let cnt = g:netrw_dirhistcnt
3602 let first = 1
3603 while ( first || cnt != g:netrw_dirhistcnt )
3604 let lastline= lastline + 1
3605 if exists("g:netrw_dirhist_{cnt}")
3606 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3607" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3608 endif
3609 let first = 0
3610 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3611 if cnt < 0
3612 let cnt= cnt + g:netrw_dirhistmax
3613 endif
3614 endwhile
3615 exe "sil! w! ".savefile
3616" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3617 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003618
Bram Moolenaar85850f32019-07-19 22:05:51 +02003619 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003620 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003621 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003622" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003623 " merge and write .netrwbook
3624 let savefile= s:NetrwHome()."/.netrwbook"
3625
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003626 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003627 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003628 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003629 for bdm in booklist
3630 if index(g:netrw_bookmarklist,bdm) == -1
3631 call add(g:netrw_bookmarklist,bdm)
3632 endif
3633 endfor
3634 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003635 endif
3636
3637 " construct and save .netrwbook
3638 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003639 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003640" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003641 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003642
3643 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003644 let bgone= bufnr("%")
3645 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003646 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003647
3648" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003649endfun
3650
3651" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003652" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3653" list of the contents of a local or remote directory. It is assumed that the
3654" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3655" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003656" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003657fun! s:NetrwBrowse(islocal,dirname)
3658 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003659
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003660 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3661 " This is useful when one edits a local file, then :e ., then :Rex
3662 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3663 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003664 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003665
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003666 " s:NetrwBrowse : initialize history {{{3
3667 if !exists("s:netrw_initbookhist")
3668 NetrwKeepj call s:NetrwBookHistRead()
3669 endif
3670
3671 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003672 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003673 let dirname= simplify(a:dirname)
3674 else
3675 let dirname= a:dirname
3676 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003677
Bram Moolenaar85850f32019-07-19 22:05:51 +02003678 " repoint t:netrw_lexbufnr if appropriate
3679 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02003680 let repointlexbufnr= 1
3681 endif
3682
3683 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003684 if exists("s:netrw_skipbrowse")
3685 unlet s:netrw_skipbrowse
Bram Moolenaar446cb832008-06-24 21:56:24 +00003686 return
3687 endif
3688 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003689 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003690 return
3691 endif
3692 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003693 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003694 return
3695 endif
3696
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003697 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003698 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003699
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003700 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003701 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3702 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003703 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3704 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003705 endif
3706
3707 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003708 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003709 if s:NetrwLcd(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003710 return
3711 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003712
Bram Moolenaar5c736222010-01-06 20:54:52 +01003713 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003714 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003715 if bufname(dirname) != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003716 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003717 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003718 " attempt transfer of remote regular file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003719
3720 " remove any filetype indicator from end of dirname, except for the
3721 " "this is a directory" indicator (/).
3722 " There shouldn't be one of those here, anyway.
3723 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003724 call s:RemotePathAnalysis(dirname)
3725
3726 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3727 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003728 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003729 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003730 let b:netrw_curdir = dirname
3731 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003732 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003733 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3734 sil call netrw#NetRead(2,url)
3735 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003736 if s:path =~ '.bz2'
3737 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3738 elseif s:path =~ '.gz'
3739 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3740 elseif s:path =~ '.gz'
3741 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3742 else
3743 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3744 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003745 endif
3746
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003747 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003748 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003749 call s:NetrwOptionsRestore("w:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003750 setl ma nomod noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00003751 return
3752 endif
3753
Bram Moolenaaradc21822011-04-01 18:03:16 +02003754 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003755 call s:UseBufWinVars()
3756
3757 " set up some variables {{{3
3758 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003759 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003760 let s:last_sort_by = g:netrw_sort_by
3761
3762 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003763 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003764
Bram Moolenaar97d62492012-11-15 21:28:22 +01003765 " get/set-up buffer {{{3
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003766 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01003767
3768 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the
3769 " previous buffer
3770 let prevbufnr = bufnr('%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003771 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Tom Benham64a536d2024-11-07 21:15:03 +01003772 if exists("s:rexposn_".prevbufnr)
3773 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr}
3774 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003775
Bram Moolenaar446cb832008-06-24 21:56:24 +00003776 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003777 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3778 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02003779 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3780 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003781 2match none
3782 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003783 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003784 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003785 call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003786 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003787 return
3788 endif
3789
3790 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003791 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003792 if b:netrw_curdir =~ '[/\\]$'
3793 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3794 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003795 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003796 let b:netrw_curdir= b:netrw_curdir."/"
3797 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003798 if b:netrw_curdir == ''
3799 if has("amiga")
3800 " On the Amiga, the empty string connotes the current directory
3801 let b:netrw_curdir= getcwd()
3802 else
3803 " under unix, when the root directory is encountered, the result
3804 " from the preceding substitute is an empty string.
3805 let b:netrw_curdir= '/'
3806 endif
3807 endif
3808 if !a:islocal && b:netrw_curdir !~ '/$'
3809 let b:netrw_curdir= b:netrw_curdir.'/'
3810 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003811
3812 " ------------
3813 " (local only) {{{3
3814 " ------------
3815 if a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00003816 " Set up ShellCmdPost handling. Append current buffer to browselist
3817 call s:LocalFastBrowser()
3818
3819 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3820 if !g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003821 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003822 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003823 return
3824 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003825 endif
3826 endif
3827
3828 " --------------------------------
3829 " remote handling: {{{3
3830 " --------------------------------
3831 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003832
Bram Moolenaar97d62492012-11-15 21:28:22 +01003833 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003834 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003835 let dirname= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003836 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3837 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3838 if dirname !~ '/$'
3839 let dirname= dirname.'/'
3840 endif
3841 let b:netrw_curdir = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003842 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003843 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003844 endif
3845
3846 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3847 if dirname !~ dirpat
3848 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003849 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003850 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003851 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003852 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003853 return
3854 endif
3855 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003856 endif " (additional remote handling)
3857
Bram Moolenaar85850f32019-07-19 22:05:51 +02003858 " -------------------------------
3859 " Perform Directory Listing: {{{3
3860 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003861 NetrwKeepj call s:NetrwMaps(a:islocal)
3862 NetrwKeepj call s:NetrwCommands(a:islocal)
3863 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003864
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003865 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003866 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003867
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003868 " If there is a rexposn: restore position with rexposn
3869 " Otherwise : set rexposn
3870 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003871 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3872 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3873 NetrwKeepj exe w:netrw_bannercnt
3874 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003875 else
3876 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3877 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003878 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003879 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara6878372014-03-22 21:02:50 +01003880 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003881 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003882
Bram Moolenaar85850f32019-07-19 22:05:51 +02003883 " repoint t:netrw_lexbufnr if appropriate
3884 if exists("repointlexbufnr")
3885 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003886 endif
3887
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003888 " restore position
3889 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003890 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003891 endif
3892
Bram Moolenaara6878372014-03-22 21:02:50 +01003893 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003894 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
3895 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003896 return
3897endfun
3898
3899" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003900" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3901" may not apply correctly; ie. netrw's idea of the current directory may
3902" differ from vim's. This function insures that netrw's idea of the current
3903" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003904" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003905fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003906" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
3907" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3908" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3909" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3910" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003911
3912 " clean up any leading treedepthstring
3913 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3914 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02003915" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003916 else
3917 let fname= a:fname
3918 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003919
3920 if g:netrw_keepdir
3921 " vim's idea of the current directory possibly may differ from netrw's
3922 if !exists("b:netrw_curdir")
3923 let b:netrw_curdir= getcwd()
3924 endif
3925
Nir Lichtman1e34b952024-05-08 19:19:34 +02003926 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003927 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003928 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003929 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003930" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003931 else
3932 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003933 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003934" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003935 endif
3936
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003937 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003938 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003939 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003940" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003941 else
3942 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003943 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003944" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003945 endif
3946 else
3947 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003948 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003949" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
3950" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3951" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003952 endif
3953
Bram Moolenaar85850f32019-07-19 22:05:51 +02003954" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003955 return ret
3956endfun
3957
3958" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003959" s:NetrwFileInfo: supports qf (query for file information) {{{2
3960fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003961" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003962 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003963 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003964 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003965 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003966 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003967 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003968 let lsopt= "-lsadh --si"
3969 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003970" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003971 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003972
3973 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003974 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003975" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003976
Bram Moolenaara6878372014-03-22 21:02:50 +01003977 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003978 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003979" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003980
3981 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003982 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003983" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003984
Bram Moolenaar446cb832008-06-24 21:56:24 +00003985 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003986" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003987 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003988" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003989 endif
3990 else
3991 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003992" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
3993 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994 let fname= substitute(a:fname,".$","","")
3995 else
3996 let fname= a:fname
3997 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003998 let t = getftime(s:NetrwFile(fname))
3999 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004000 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004001 let sz= s:NetrwHumanReadable(sz)
4002 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004003 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
4004" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004005 endif
4006 else
4007 echo "sorry, \"qf\" not supported yet for remote files"
4008 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004009 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004010" call Dret("s:NetrwFileInfo")
4011endfun
4012
4013" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004014" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
4015fun! s:NetrwFullPath(filename)
4016" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
4017 let filename= a:filename
4018 if filename !~ '^/'
4019 let filename= resolve(getcwd().'/'.filename)
4020 endif
4021 if filename != "/" && filename =~ '/$'
4022 let filename= substitute(filename,'/$','','')
4023 endif
4024" " call Dret("s:NetrwFullPath <".filename.">")
4025 return filename
4026endfun
4027
4028" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004029" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004030" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004031" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004032" 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 +00004033fun! s:NetrwGetBuffer(islocal,dirname)
4034" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004035" 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 +02004036" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4037" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004038 let dirname= a:dirname
4039
4040 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004041" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004042 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004043" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004044 let s:netrwbuf= {}
4045 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004046" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4047" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4048
4049 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4050 let bufnum = -1
4051
4052 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4053 if has_key(s:netrwbuf,"NetrwTreeListing")
4054 let bufnum= s:netrwbuf["NetrwTreeListing"]
4055 else
4056 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4057 endif
4058" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4059 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004060 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004061 let bufnum= -1
4062 endif
4063 elseif bufnr("NetrwTreeListing") != -1
4064 let bufnum= bufnr("NetrwTreeListing")
4065" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4066 else
4067" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4068 let bufnum= -1
4069 endif
4070
4071 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004072 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004073" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004074 if !bufexists(bufnum)
4075 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4076 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004077 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004078
Bram Moolenaar446cb832008-06-24 21:56:24 +00004079 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004080" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004081 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004082 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004083" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4084
Bram Moolenaar71badf92023-04-22 22:40:14 +01004085 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004086 " IF the buffer already has the desired name
4087 " AND it is empty
4088 let curbuf = bufname("%")
4089 if curbuf == '.'
4090 let curbuf = getcwd()
4091 endif
4092" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004093" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004094" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4095" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4096" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4097" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4098 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004099" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4100 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004101 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004102" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004103 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004104 " 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 +00004105
4106 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004107 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004108" 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 +00004109 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004110" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004111 " name the buffer
4112 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4113 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004114" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004115 let w:netrw_treebufnr = bufnr("%")
4116 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004117 if g:netrw_use_noswf
4118 setl nobl bt=nofile noswf
4119 else
4120 setl nobl bt=nofile
4121 endif
4122 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4123 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4124 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4125 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004126" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004127 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004128 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004129 " enter the new buffer into the s:netrwbuf dictionary
4130 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4131" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4132" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004133 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004134" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004135
4136 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004137" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004138 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004139 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004140 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004141
4142 if &ft == "netrw"
4143" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4144 exe "sil! NetrwKeepj noswapfile b ".bufnum
4145" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004146 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004147" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4148 call s:NetrwEditBuf(bufnum)
4149" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004150 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004151" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004152 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004153 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004154 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004155
4156 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004157 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004158
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004159 if line("$") <= 1 && getline(1) == ""
4160 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004161 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004162" 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>"))
4163" 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 +01004164" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4165 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004166
Bram Moolenaar97d62492012-11-15 21:28:22 +01004167 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004168" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004169 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170 sil NetrwKeepj %d _
4171" 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>"))
4172" 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 +01004173" 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 +00004174 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004175
Bram Moolenaar446cb832008-06-24 21:56:24 +00004176 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004177" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4178" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004179 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004180 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004181 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004182" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
4183" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004184" call Dret("s:NetrwGetBuffer 0<cleared buffer> : re-using buffer#".bufnr("%").", but treelist mode always needs a refresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004185 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004186
Bram Moolenaar446cb832008-06-24 21:56:24 +00004187 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004188" 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>"))
4189" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4190" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004191 return 1
4192 endif
4193 endif
4194
4195 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4196 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4197 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4198 " med 1 D H
4199 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004200" 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 +00004201 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004202 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004203 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004204
4205 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004206" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4207" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4208 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004209
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004210" 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>"))
4211" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4212" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004213 return 0
4214endfun
4215
4216" ---------------------------------------------------------------------
4217" s:NetrwGetcwd: get the current directory. {{{2
4218" Change backslashes to forward slashes, if any.
4219" If doesc is true, escape certain troublesome characters
4220fun! s:NetrwGetcwd(doesc)
4221" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4222 let curdir= substitute(getcwd(),'\\','/','ge')
4223 if curdir !~ '[\/]$'
4224 let curdir= curdir.'/'
4225 endif
4226 if a:doesc
4227 let curdir= fnameescape(curdir)
4228 endif
4229" call Dret("NetrwGetcwd <".curdir.">")
4230 return curdir
4231endfun
4232
4233" ---------------------------------------------------------------------
4234" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4235fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004236" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4237" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4238 let keepsol= &l:sol
4239 setl nosol
4240
Bram Moolenaar446cb832008-06-24 21:56:24 +00004241 call s:UseBufWinVars()
4242
4243 " insure that w:netrw_liststyle is set up
4244 if !exists("w:netrw_liststyle")
4245 if exists("g:netrw_liststyle")
4246 let w:netrw_liststyle= g:netrw_liststyle
4247 else
4248 let w:netrw_liststyle= s:THINLIST
4249 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004250" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004251 endif
4252
4253 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4254 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004255" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004256 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004257 let dirname= "./"
4258 let curline= getline('.')
4259
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004260 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004261 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004262 let s:netrw_skipbrowse= 1
4263 echo 'Pressing "s" also works'
4264
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004265 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004266 let s:netrw_skipbrowse= 1
4267 echo 'Press "S" to edit sorting sequence'
4268
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004269 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004270 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004271 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004272
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004273 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004274 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004275 let s:netrw_skipbrowse= 1
4276 echo 'Pressing "a" also works'
4277
4278 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004279 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004280 endif
4281
4282 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004283" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004284 NetrwKeepj norm! 0
4285 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004286
4287 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004288" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004289 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004290 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4291
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004292 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004293" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004294 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004295 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004296
4297 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004298" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004299 let dirname= getline('.')
4300
4301 if !exists("b:netrw_cpf")
4302 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004303 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 +01004304 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004305" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004306 endif
4307
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004308" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004309 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004310" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4311" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004312 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004313 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004314 else
4315 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004316 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004317 endif
Enno3146d632024-07-04 19:44:42 +02004318
4319 let dict={}
4320 " save the unnamed register and register 0-9 and a
4321 let dict.a=[getreg('a'), getregtype('a')]
4322 for i in range(0, 9)
4323 let dict[i] = [getreg(i), getregtype(i)]
4324 endfor
4325 let dict.unnamed = [getreg(''), getregtype('')]
4326
Bram Moolenaarc236c162008-07-13 17:41:49 +00004327 let eofname= filestart + b:netrw_cpf + 1
4328 if eofname <= col("$")
4329 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004330 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004331 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004332 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004333 endif
Enno3146d632024-07-04 19:44:42 +02004334
Bram Moolenaar446cb832008-06-24 21:56:24 +00004335 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004336 call s:RestoreRegister(dict)
4337
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004338" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004339 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004340" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004341 endif
4342
4343 " symlinks are indicated by a trailing "@". Remove it before further processing.
4344 let dirname= substitute(dirname,"@$","","")
4345
4346 " executables are indicated by a trailing "*". Remove it before further processing.
4347 let dirname= substitute(dirname,"\*$","","")
4348
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004349 let &l:sol= keepsol
4350
Bram Moolenaar446cb832008-06-24 21:56:24 +00004351" call Dret("s:NetrwGetWord <".dirname.">")
4352 return dirname
4353endfun
4354
4355" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004356" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4357" g:netrw_bufsettings will be used after the listing is produced.
4358" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004359fun! s:NetrwListSettings(islocal)
4360" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004361" 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 +00004362 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004363" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4364 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4365 setl bt=nofile nobl ma nonu nowrap noro nornu
4366 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004367 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004368 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004370" call Dredir("ls!","s:NetrwListSettings")
4371" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004372 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004373 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004374 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004375 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004377 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004378 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004379" 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 +00004380" call Dret("s:NetrwListSettings")
4381endfun
4382
4383" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004384" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004385" islocal=0: remote browsing
4386" =1: local browsing
4387fun! s:NetrwListStyle(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004388 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004389 let fname = s:NetrwGetWord()
4390 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004391 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004392 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004393
Bram Moolenaar85850f32019-07-19 22:05:51 +02004394 " repoint t:netrw_lexbufnr if appropriate
4395 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02004396 let repointlexbufnr= 1
4397 endif
4398
Bram Moolenaar446cb832008-06-24 21:56:24 +00004399 if w:netrw_liststyle == s:THINLIST
4400 " use one column listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004401 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4402
4403 elseif w:netrw_liststyle == s:LONGLIST
4404 " use long list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004405 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4406
4407 elseif w:netrw_liststyle == s:WIDELIST
4408 " give wide list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004409 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4410
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004411 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004412 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4413
4414 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004415 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004416 let g:netrw_liststyle = s:THINLIST
4417 let w:netrw_liststyle = g:netrw_liststyle
4418 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4419 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004420 setl ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00004421
4422 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004423 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004424 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004425 setl nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00004426
4427 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01004428 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004429 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004430
Bram Moolenaar85850f32019-07-19 22:05:51 +02004431 " repoint t:netrw_lexbufnr if appropriate
4432 if exists("repointlexbufnr")
4433 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004434 endif
4435
Bram Moolenaar13600302014-05-22 18:26:40 +02004436 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004437" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4438 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004439 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004440
Bram Moolenaar446cb832008-06-24 21:56:24 +00004441endfun
4442
4443" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004444" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4445fun! s:NetrwBannerCtrl(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004446 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004447 " toggle the banner (enable/suppress)
4448 let g:netrw_banner= !g:netrw_banner
4449
4450 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004451 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01004452 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004453
4454 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004455 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4456 let fname= s:NetrwGetWord()
4457 sil NetrwKeepj $
4458 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4459" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4460 if result <= 0 && exists("w:netrw_bannercnt")
4461 exe "NetrwKeepj ".w:netrw_bannercnt
4462 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004463 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004464 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004465" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4466endfun
4467
4468" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004469" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4470"
4471" No bang: enters files/directories into Netrw's bookmark system
4472" No argument and in netrw buffer:
4473" if there are marked files: bookmark marked files
4474" otherwise : bookmark file/directory under cursor
4475" No argument and not in netrw buffer: bookmarks current open file
4476" Has arguments: globs them individually and bookmarks them
4477"
4478" With bang: deletes files/directories from Netrw's bookmark system
4479fun! s:NetrwBookmark(del,...)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004480 if a:0 == 0
4481 if &ft == "netrw"
4482 let curbufnr = bufnr("%")
4483
4484 if exists("s:netrwmarkfilelist_{curbufnr}")
4485 " for every filename in the marked list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004486 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004487 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004488 for fname in s:netrwmarkfilelist_{curbufnr}
4489 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4490 endfor
4491 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4492 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01004493 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004494 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004495 else
4496 let fname= s:NetrwGetWord()
4497 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4498 endif
4499
4500 else
4501 " bookmark currently open file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004502 let fname= expand("%")
4503 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4504 endif
4505
4506 else
4507 " bookmark specified files
4508 " attempts to infer if working remote or local
4509 " by deciding if the current file begins with an url
4510 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004511 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004512 let i = 1
4513 while i <= a:0
4514 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004515 if v:version > 704 || (v:version == 704 && has("patch656"))
4516 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004517 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004518 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004519 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004520 else
4521 let mbfiles= [a:{i}]
4522 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004523 for mbfile in mbfiles
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004524 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4525 endfor
4526 let i= i + 1
4527 endwhile
4528 endif
4529
4530 " update the menu
4531 call s:NetrwBookmarkMenu()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004532endfun
4533
4534" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004535" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4536" .2.[cnt] for bookmarks, and
4537" .3.[cnt] for history
4538" (see s:NetrwMenu())
4539fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004540 if !exists("s:netrw_menucnt")
4541 return
4542 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004543" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004544
4545 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004546 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004547 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004548" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004549 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4550 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004551 endif
4552 if !exists("s:netrw_initbookhist")
4553 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004554 endif
4555
4556 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004557 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004558 let cnt= 1
4559 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004560" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004561 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004562
4563 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004564 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004565
4566 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004567 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 +01004568 let cnt= cnt + 1
4569 endfor
4570
4571 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004572
4573 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004574 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004575 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004576 let first = 1
4577 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004578 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004579 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004580 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004581 if exists("g:netrw_dirhist_{cnt}")
4582 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004583" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004584 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4585 endif
4586 let first = 0
4587 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4588 if cnt < 0
4589 let cnt= cnt + g:netrw_dirhistmax
4590 endif
4591 endwhile
4592 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004593
Bram Moolenaar9964e462007-05-05 17:54:07 +00004594 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004595" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004596endfun
4597
4598" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004599" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4600" directory and a new directory name. Also, if the
4601" "new directory name" is actually a file,
4602" NetrwBrowseChgDir() edits the file.
Tom Benham64a536d2024-11-07 21:15:03 +01004603" cursor=0: newdir is relative to b:netrw_curdir
4604" =1: newdir is relative to the path to the word under the cursor in
4605" tree view
4606fun! s:NetrwBrowseChgDir(islocal,newdir,cursor,...)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004607 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004608 if !exists("b:netrw_curdir")
4609 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4610 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004611 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004612 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004613 endif
4614
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004615 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02004616 call s:SavePosn(s:netrw_posn)
4617 NetrwKeepj call s:NetrwOptionsSave("s:")
4618 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Tom Benham64a536d2024-11-07 21:15:03 +01004619
4620 let newdir = a:newdir
4621 if a:cursor && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
4622 " dirname is the path to the word under the cursor
4623 let dirname = s:NetrwTreePath(w:netrw_treetop)
Christian Brabandt5b63b232024-11-10 20:22:34 +01004624 " newdir resolves to a directory and points to a directory in dirname
4625 " /tmp/test/folder_symlink/ -> /tmp/test/original_folder/
4626 if a:islocal && fnamemodify(dirname, ':t') == newdir && isdirectory(resolve(dirname)) && resolve(dirname) == resolve(newdir)
4627 let dirname = fnamemodify(resolve(dirname), ':p:h:h')
4628 let newdir = fnamemodify(resolve(newdir), ':t')
4629 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004630 " Remove trailing "/"
4631 let dirname = substitute(dirname, "/$", "", "")
4632
4633 " If the word under the cursor is a directory (except for ../), NetrwTreePath
4634 " returns the full path, including the word under the cursor, remove it
4635 if newdir =~ "/$" && newdir != "../"
4636 let dirname = fnamemodify(dirname, ":h")
4637 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004638 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004639 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004640 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004641 if has("win32")
4642 let dirname = substitute(dirname,'\\','/','ge')
4643 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004644 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004645 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004646
4647 " ignore <cr>s when done in the banner
4648 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01004649 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004650 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +01004651 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaar13600302014-05-22 18:26:40 +02004652 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004653 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004654 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004655 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004656 endif
4657 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004658 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004659
Bram Moolenaar446cb832008-06-24 21:56:24 +00004660 " set up o/s-dependent directory recognition pattern
4661 if has("amiga")
4662 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004663 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004664 let dirpat= '[\/]$'
4665 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004666
4667 if dirname !~ dirpat
4668 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004669 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004670 let dirname= dirname.'/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004671 endif
4672
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004673 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004674 " ------------------------------
4675 " NetrwBrowseChgDir: edit a file {{{3
4676 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004677
Bram Moolenaar97d62492012-11-15 21:28:22 +01004678 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004679 let s:rexposn_{bufnr("%")}= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01004680
Bram Moolenaar446cb832008-06-24 21:56:24 +00004681 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004682 if dirname =~ '/$'
4683 let dirname= dirname.newdir
4684 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004685 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004686 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004687 elseif newdir =~ '^\(/\|\a:\)'
4688 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004689 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004690 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004691 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004692 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004693 if a:0 < 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004694 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004695 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004696 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004697 if type(g:netrw_browse_split) == 3
4698 " open file in server
4699 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004700 call s:NetrwServerEdit(a:islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004701 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004702
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004703 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004704 " horizontally splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004705 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4706 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004707 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004708 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004709 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004710 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004711
Bram Moolenaar446cb832008-06-24 21:56:24 +00004712 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004713 " vertically splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004714 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4715 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004716 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004717 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004718 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004719 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004720
Bram Moolenaar446cb832008-06-24 21:56:24 +00004721 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004722 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004723 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004724 if !exists("b:netrw_curdir")
4725 let b:netrw_curdir= getcwd()
4726 endif
4727 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004728
Bram Moolenaar446cb832008-06-24 21:56:24 +00004729 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004730 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004731 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004732 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004733 return
4734 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004735 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004736
Bram Moolenaar9964e462007-05-05 17:54:07 +00004737 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004738 " handling a file, didn't split, so remove menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00004739 call s:NetrwMenu(0)
4740 " optional change to window
4741 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004742 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004743 " if g:netrw_chgwin is set to one more than the last window, then
4744 " vertically split the last window to make that window available.
4745 let curwin= winnr()
4746 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4747 vs
4748 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004749 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004750 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004751 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004752 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004753 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004754
Bram Moolenaar9964e462007-05-05 17:54:07 +00004755 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004756
Bram Moolenaar446cb832008-06-24 21:56:24 +00004757 " the point where netrw actually edits the (local) file
4758 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004759 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004760 if !&mod
4761 " if e the new file would fail due to &mod, then don't change any of the flags
4762 let dolockout= 1
4763 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004764 if a:islocal
Bram Moolenaar8d043172014-01-23 14:24:41 +01004765 " some like c-^ to return to the last edited file
4766 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004767 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4768 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004769 call s:NetrwEditFile("e","",dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004770 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004771 if &hidden || &bufhidden == "hide"
4772 " file came from vim's hidden storage. Don't "restore" options with it.
4773 let dorestore= 0
4774 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004775 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00004776 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004777
4778 " handle g:Netrw_funcref -- call external-to-netrw functions
4779 " This code will handle g:Netrw_funcref as an individual function reference
4780 " or as a list of function references. It will ignore anything that's not
4781 " a function reference. See :help Funcref for information about function references.
4782 if exists("g:Netrw_funcref")
4783 if type(g:Netrw_funcref) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004784 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004785 elseif type(g:Netrw_funcref) == 3
4786 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004787 if type(Fncref) == 2
4788 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004789 endif
4790 endfor
4791 endif
4792 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004793 endif
4794
4795 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004796 " ----------------------------------------------------
4797 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4798 " ----------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004799 let dirname = newdir
4800 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004801 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004802 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004803
4804 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004805 " ---------------------------------------------
4806 " NetrwBrowseChgDir: refresh the directory list {{{3
4807 " ---------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004808 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004809 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004810
4811 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004812 " --------------------------------------
4813 " NetrwBrowseChgDir: go up one directory {{{3
4814 " --------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004815
4816 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4817 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004818 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004819 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004820 endif
4821
4822 if has("amiga")
4823 " amiga
Bram Moolenaar446cb832008-06-24 21:56:24 +00004824 if a:islocal
4825 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4826 let dirname= substitute(dirname,'/$','','')
4827 else
4828 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4829 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004830
Nir Lichtman1e34b952024-05-08 19:19:34 +02004831 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004832 " windows
4833 if a:islocal
4834 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4835 if dirname == ""
4836 let dirname= '/'
4837 endif
4838 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004839 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004840 endif
4841 if dirname =~ '^\a:$'
4842 let dirname= dirname.'/'
4843 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004844
Bram Moolenaar446cb832008-06-24 21:56:24 +00004845 else
4846 " unix or cygwin
Bram Moolenaar446cb832008-06-24 21:56:24 +00004847 if a:islocal
4848 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4849 if dirname == ""
4850 let dirname= '/'
4851 endif
4852 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004853 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004854 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004855 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004856 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004857 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858
4859 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004860 " --------------------------------------
4861 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4862 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004863 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004864 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004865 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004866 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004867 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004868 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004869 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004870 let haskey = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004871
4872 " search treedict for tree dir as-is
4873 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004874 let haskey= 1
4875 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004876 endif
4877
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004878 " search treedict for treedir with a [/@] appended
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004879 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004880 if has_key(w:netrw_treedict,treedir."/")
4881 let treedir= treedir."/"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004882 let haskey = 1
4883 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004884 endif
4885 endif
4886
4887 " search treedict for treedir with any trailing / elided
4888 if !haskey && treedir =~ '/$'
4889 let treedir= substitute(treedir,'/$','','')
4890 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004891 let haskey = 1
4892 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004893 endif
4894 endif
4895
4896 if haskey
4897 " close tree listing for selected subdirectory
Bram Moolenaar446cb832008-06-24 21:56:24 +00004898 call remove(w:netrw_treedict,treedir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004899 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004900 else
4901 " go down one directory
4902 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004903 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004904 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004905 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004906
4907 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004908 " ----------------------------------------
4909 " NetrwBrowseChgDir: Go down one directory {{{3
4910 " ----------------------------------------
4911 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004912 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004913 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004914 endif
4915
Bram Moolenaar97d62492012-11-15 21:28:22 +01004916 " --------------------------------------
4917 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4918 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004919 if dorestore
4920 " dorestore is zero'd when a local file was hidden or bufhidden;
4921 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004922 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004923 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004924 if dolockout && dorestore
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004925 if filewritable(dirname)
Bram Moolenaar13600302014-05-22 18:26:40 +02004926 setl ma noro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004927 else
Bram Moolenaar13600302014-05-22 18:26:40 +02004928 setl ma ro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004929 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004930 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004931 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004932 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004933
Bram Moolenaar446cb832008-06-24 21:56:24 +00004934 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004935endfun
4936
4937" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004938" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4939" for thin, long, and wide: cursor placed just after banner
4940" for tree, keeps cursor on current filename
4941fun! s:NetrwBrowseUpDir(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004942 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4943 " this test needed because occasionally this function seems to be incorrectly called
4944 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004945 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004946 " directories.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004947 return
4948 endif
4949
Bram Moolenaara6878372014-03-22 21:02:50 +01004950 norm! 0
4951 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01004952 let curline= getline(".")
4953 let swwline= winline() - 1
4954 if exists("w:netrw_treetop")
4955 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02004956 elseif exists("b:netrw_curdir")
4957 let w:netrw_treetop= b:netrw_curdir
4958 else
4959 let w:netrw_treetop= getcwd()
4960 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01004961 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004962 let curfile = getline(".")
4963 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01004964 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004965 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004966 else
Tom Benham64a536d2024-11-07 21:15:03 +01004967 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004968 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004969 if w:netrw_treetop == '/'
4970 keepj call search('^\M'.curfile,"w")
4971 elseif curfile == '../'
4972 keepj call search('^\M'.curfile,"wb")
4973 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004974 while 1
4975 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
4976 let treepath= s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004977 if treepath == curpath
4978 break
4979 endif
4980 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01004981 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004982
Bram Moolenaara6878372014-03-22 21:02:50 +01004983 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004984 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004985 if exists("b:netrw_curdir")
4986 let curdir= b:netrw_curdir
4987 else
4988 let curdir= expand(getcwd())
4989 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004990 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004991 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004992 else
Tom Benham64a536d2024-11-07 21:15:03 +01004993 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004994 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004995 call s:RestorePosn(s:netrw_posn)
4996 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01004997 let curdir= '\<'. escape(curdir, '~'). '/'
4998 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01004999 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01005000endfun
5001
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005002func s:redir()
5003 " set up redirection (avoids browser messages)
5004 " by default if not set, g:netrw_suppress_gx_mesg is true
5005 if get(g:, 'netrw_suppress_gx_mesg', 1)
5006 if &srr =~# "%s"
5007 return printf(&srr, has("win32") ? "nul" : "/dev/null")
5008 else
5009 return &srr .. (has("win32") ? "nul" : "/dev/null")
5010 endif
5011 endif
5012 return ''
5013endfunc
5014
5015if has('unix')
5016 if has('win32unix')
5017 " Cygwin provides cygstart
5018 if executable('cygstart')
5019 fun! netrw#Launch(args)
5020 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
5021 endfun
5022 elseif !empty($MSYSTEM) && executable('start')
5023 " MSYS2/Git Bash comes by default without cygstart; see
5024 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
5025 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
5026 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
5027 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
5028 fun! netrw#Launch(args)
5029 exe 'silent !start "" //b' a:args s:redir() | redraw!
5030 endfun
5031 else
5032 " imitate /usr/bin/start script for other environments and hope for the best
5033 fun! netrw#Launch(args)
5034 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
5035 endfun
5036 endif
5037 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
5038 fun! netrw#Launch(args)
5039 let args = a:args
5040 exe 'silent !' ..
5041 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
Konfekt460799d2024-11-14 21:42:27 +01005042 \ 'cmd.exe /c start /b ' .. args :
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005043 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5044 \ | redraw!
5045 endfun
5046 else
5047 fun! netrw#Launch(args)
5048 exe ':silent ! nohup' a:args s:redir() '&' | redraw!
5049 endfun
5050 endif
5051elseif has('win32')
5052 fun! netrw#Launch(args)
5053 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5054 \ 'start "" /b' a:args s:redir() | redraw!
5055 endfun
5056else
5057 fun! netrw#Launch(dummy)
5058 echom 'No common launcher found'
5059 endfun
5060endif
5061
5062" Git Bash
5063if has('win32unix')
5064 " (cyg)start suffices
5065 let s:os_viewer = ''
5066" Windows / WSL
5067elseif executable('explorer.exe')
5068 let s:os_viewer = 'explorer.exe'
5069" Linux / BSD
5070elseif executable('xdg-open')
5071 let s:os_viewer = 'xdg-open'
5072" MacOS
5073elseif executable('open')
5074 let s:os_viewer = 'open'
5075endif
5076
5077fun! s:viewer()
5078 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5079 " extract any viewing options. Assumes that they're set apart by spaces.
5080 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5081 if g:netrw_browsex_viewer =~ '\s'
5082 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5083 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5084 let oviewer = ''
5085 let cnt = 1
5086 while !executable(viewer) && viewer != oviewer
5087 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5088 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5089 let cnt = cnt + 1
5090 let oviewer = viewer
5091 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5092 endwhile
5093 else
5094 let viewer = g:netrw_browsex_viewer
5095 let viewopt = ""
5096 endif
5097 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5098 return viewer .. ' ' .. viewopt
5099 else
5100 if !exists('s:os_viewer')
5101 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5102 else
5103 return s:os_viewer
5104 endif
5105 endif
5106endfun
5107
5108fun! netrw#Open(file) abort
5109 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5110endf
5111
5112if !exists('g:netrw_regex_url')
5113 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5114endif
5115
Bram Moolenaara6878372014-03-22 21:02:50 +01005116" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005117" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005118" given filename; typically this means given their extension.
5119" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005120fun! netrw#BrowseX(fname,remote)
Konfekt460799d2024-11-14 21:42:27 +01005121 if a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
Bram Moolenaar91359012019-11-30 17:57:03 +01005122 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005123 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005124 endif
5125
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005126 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5127 let remote = a:remote
5128 else
5129 let remote = 0
5130 endif
5131
Bram Moolenaar97d62492012-11-15 21:28:22 +01005132 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005133 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005134
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005135 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5136 let awkeep = &aw
5137 set noaw
5138
Bram Moolenaar5c736222010-01-06 20:54:52 +01005139 " special core dump handler
5140 if a:fname =~ '/core\(\.\d\+\)\=$'
5141 if exists("g:Netrw_corehandler")
5142 if type(g:Netrw_corehandler) == 2
5143 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005144 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005145 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005146 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005147 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005148 if type(Fncref) == 2
5149 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005150 endif
5151 endfor
5152 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005153 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005154 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005155 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005156 return
5157 endif
5158 endif
5159
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 " set up the filename
5161 " (lower case the extension, make a local copy of a remote file)
5162 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005163 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005165 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005166 if exten =~ "[\\/]"
5167 let exten= ""
5168 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005169
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005170 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005172 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005173 call netrw#NetRead(3,a:fname)
5174 " attempt to rename tempfile
5175 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005176 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005177 if s:netrw_tmpfile != newname && newname != ""
5178 if rename(s:netrw_tmpfile,newname) == 0
5179 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005180 let fname= newname
5181 else
5182 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005183 let fname= s:netrw_tmpfile
5184 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005185 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005186 let fname= s:netrw_tmpfile
5187 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005188 else
5189 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005190 " special ~ handler for local
5191 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005192 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005193 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005194 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005195
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005196 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5197 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005198
Bram Moolenaar446cb832008-06-24 21:56:24 +00005199 " cleanup: remove temporary file,
5200 " delete current buffer if success with handler,
5201 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005202 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005203 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005204" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005205" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005206" endif
5207
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005208 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005209 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005210 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005211 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005212 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005213 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005214 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005215 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005216 let @@ = ykeep
5217 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005218endfun
5219
5220" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005221" netrw#GX: gets word under cursor for gx support {{{2
5222" See also: netrw#BrowseXVis
5223" netrw#BrowseX
5224fun! netrw#GX()
5225" call Dfunc("netrw#GX()")
5226 if &ft == "netrw"
5227 let fname= s:NetrwGetWord()
5228 else
Konfekt3d7e5672024-10-27 22:16:49 +01005229 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005230 endif
5231" call Dret("netrw#GX <".fname.">")
5232 return fname
5233endfun
5234
Konfekt3d7e5672024-10-27 22:16:49 +01005235fun! s:GetURL() abort
5236 let URL = ''
5237 if exists('*Netrw_get_URL_' .. &filetype)
5238 let URL = call('Netrw_get_URL_' .. &filetype, [])
5239 endif
5240 if !empty(URL) | return URL | endif
5241 " URLs end in letter, digit or forward slash
5242 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5243 if !empty(URL) | return URL | endif
5244
5245 " Is it a file in the current work dir ...
5246 let file = expand("<cfile>")
5247 if filereadable(file) | return file | endif
5248 " ... or in that of the current buffer?
5249 let path = fnamemodify(expand('%'), ':p')
5250 if isdirectory(path)
5251 let dir = path
5252 elseif filereadable(path)
5253 let dir = fnamemodify(path, ':h')
5254 endif
5255 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5256
5257 return ''
5258endf
5259
Bram Moolenaar85850f32019-07-19 22:05:51 +02005260" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005261" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5262fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005263 let dict={}
5264 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005265 norm! gv"ay
5266 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005267 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005268 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005269endfun
5270
5271" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005272" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5273" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5274" to become an unlisted buffer, so in that case don't bwipe it.
5275fun! s:NetrwBufRename(newname)
5276" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5277" call Dredir("ls!","s:NetrwBufRename (before rename)")
5278 let oldbufname= bufname(bufnr("%"))
5279" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5280
5281 if oldbufname != a:newname
5282" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5283 let b:junk= 1
5284" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5285 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005286" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005287 let oldbufnr= bufnr(oldbufname)
5288" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5289" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5290 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5291" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5292 exe "bwipe! ".oldbufnr
5293" else " Decho
5294" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005295" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5296" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5297" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005298 endif
5299" call Dredir("ls!","s:NetrwBufRename (after rename)")
5300" else " Decho
5301" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5302 endif
5303
5304" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5305endfun
5306
5307" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005308" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005309fun! netrw#CheckIfRemote(...)
5310" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5311 if a:0 > 0
5312 let curfile= a:1
5313 else
5314 let curfile= expand("%")
5315 endif
5316" call Decho("curfile<".curfile.">")
5317 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005318" call Dret("netrw#CheckIfRemote 1")
5319 return 1
5320 else
5321" call Dret("netrw#CheckIfRemote 0")
5322 return 0
5323 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005324endfun
5325
5326" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005327" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5328fun! s:NetrwChgPerm(islocal,curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005329 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005330 call inputsave()
5331 let newperm= input("Enter new permission: ")
5332 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005333 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5334 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005335 call system(chgperm)
5336 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005337 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005338 endif
5339 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005340 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005341 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005342 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005343endfun
5344
5345" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005346" s:CheckIfKde: checks if kdeinit is running {{{2
5347" Returns 0: kdeinit not running
5348" 1: kdeinit is running
5349fun! s:CheckIfKde()
5350" call Dfunc("s:CheckIfKde()")
5351 " seems kde systems often have gnome-open due to dependencies, even though
5352 " gnome-open's subsidiary display tools are largely absent. Kde systems
5353 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5354 if !exists("s:haskdeinit")
5355 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005356 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005357 if v:shell_error
5358 let s:haskdeinit = 0
5359 endif
5360 else
5361 let s:haskdeinit= 0
5362 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005363" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005364 endif
5365
5366" call Dret("s:CheckIfKde ".s:haskdeinit)
5367 return s:haskdeinit
5368endfun
5369
5370" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005371" s:NetrwClearExplore: clear explore variables (if any) {{{2
5372fun! s:NetrwClearExplore()
5373" call Dfunc("s:NetrwClearExplore()")
5374 2match none
5375 if exists("s:explore_match") |unlet s:explore_match |endif
5376 if exists("s:explore_indx") |unlet s:explore_indx |endif
5377 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5378 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5379 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5380 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5381 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5382 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5383 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5384" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005385" call Dret("s:NetrwClearExplore")
5386endfun
5387
5388" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005389" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5390fun! s:NetrwEditBuf(bufnum)
5391" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5392 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5393" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5394 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5395 else
5396" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005397 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005398 endif
5399" call Dret("s:NetrwEditBuf")
5400endfun
5401
5402" ---------------------------------------------------------------------
5403" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5404" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5405fun! s:NetrwEditFile(cmd,opt,fname)
5406" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5407 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5408" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5409 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5410 else
5411" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005412 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5413 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5414 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005415 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5416 endif
5417" call Dret("s:NetrwEditFile")
5418endfun
5419
5420" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005421" s:NetrwExploreListUniq: {{{2
5422fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005423 " this assumes that the list is already sorted
5424 let newexplist= []
5425 for member in a:explist
5426 if !exists("uniqmember") || member != uniqmember
5427 let uniqmember = member
5428 let newexplist = newexplist + [ member ]
5429 endif
5430 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01005431 return newexplist
5432endfun
5433
5434" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005435" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5436fun! s:NetrwForceChgDir(islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005437 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005438 if a:newdir !~ '/$'
5439 " ok, looks like force is needed to get directory-style treatment
5440 if a:newdir =~ '@$'
5441 let newdir= substitute(a:newdir,'@$','/','')
5442 elseif a:newdir =~ '[*=|\\]$'
5443 let newdir= substitute(a:newdir,'.$','/','')
5444 else
5445 let newdir= a:newdir.'/'
5446 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005447 else
5448 " should already be getting treatment as a directory
5449 let newdir= a:newdir
5450 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005451 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005452 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005453 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005454endfun
5455
5456" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005457" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005458" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5459" expr : this is the expression to follow the directory. Will use s:ComposePath()
5460" pare =1: remove the current directory from the resulting glob() filelist
5461" =0: leave the current directory in the resulting glob() filelist
5462fun! s:NetrwGlob(direntry,expr,pare)
5463" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005464 if netrw#CheckIfRemote()
5465 keepalt 1sp
5466 keepalt enew
5467 let keep_liststyle = w:netrw_liststyle
5468 let w:netrw_liststyle = s:THINLIST
5469 if s:NetrwRemoteListing() == 0
5470 keepj keepalt %s@/@@
5471 let filelist= getline(1,$)
5472 q!
5473 else
5474 " remote listing error -- leave treedict unchanged
5475 let filelist= w:netrw_treedict[a:direntry]
5476 endif
5477 let w:netrw_liststyle= keep_liststyle
5478 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005479 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005480 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005481 " escape [ so it is not detected as wildcard character, see :h wildcard
5482 let path= substitute(path, '[', '[[]', 'g')
5483 endif
5484 if v:version > 704 || (v:version == 704 && has("patch656"))
5485 let filelist= glob(path,0,1,1)
5486 else
5487 let filelist= glob(path,0,1)
5488 endif
5489 if a:pare
5490 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5491 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005492 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005493 return filelist
5494endfun
5495
5496" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005497" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5498fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005499 if a:newfile =~ '[/@*=|\\]$'
5500 let newfile= substitute(a:newfile,'.$','','')
5501 else
5502 let newfile= a:newfile
5503 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005504 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005505 call s:NetrwBrowseChgDir(a:islocal,newfile,0)
Bram Moolenaarff034192013-04-24 18:51:19 +02005506 else
Tom Benham64a536d2024-11-07 21:15:03 +01005507 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02005508 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005509endfun
5510
5511" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005512" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5513" and switches the hiding mode. The actual hiding is done by
5514" s:NetrwListHide().
5515" g:netrw_hide= 0: show all
5516" 1: show not-hidden files
5517" 2: show hidden files only
5518fun! s:NetrwHide(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005519 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005520 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005521
5522 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005523
5524 " hide the files in the markfile list
5525 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005526 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5527 " remove fname from hiding list
5528 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5529 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5530 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005531 else
5532 " append fname to hiding list
5533 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5534 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5535 else
5536 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5537 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005538 endif
5539 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005540 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005541 let g:netrw_hide= 1
5542
5543 else
5544
5545 " switch between show-all/show-not-hidden/show-hidden
5546 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005547 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005549 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005550 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551 return
5552 endif
5553 endif
5554
Tom Benham64a536d2024-11-07 21:15:03 +01005555 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005556 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005557 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005558endfun
5559
5560" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005561" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5562fun! s:NetrwHideEdit(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005563 let ykeep= @@
5564 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005565 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005566
5567 " get new hiding list from user
5568 call inputsave()
5569 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5570 call inputrestore()
5571 let g:netrw_list_hide= newhide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005572
5573 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01005574 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005575
5576 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005577 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005578 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005579endfun
5580
5581" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005582" s:NetrwHidden: invoked by "gh" {{{2
5583fun! s:NetrwHidden(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005584 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005585 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005586 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005587
5588 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005589 " remove .file pattern from hiding list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005590 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005591 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005592 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5593 else
5594 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5595 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005596 if g:netrw_list_hide =~ '^,'
5597 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5598 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005599
5600 " refresh screen and return to saved position
Tom Benham64a536d2024-11-07 21:15:03 +01005601 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005602 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005603 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005604endfun
5605
5606" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005607" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5608fun! s:NetrwHome()
5609 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005610 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005611 else
5612 " go to vim plugin home
5613 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005614 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005615 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005616 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005617 let home= basehome."/.vim"
5618 break
5619 endif
5620 endfor
5621 if home == ""
5622 " just pick the first directory
5623 let home= substitute(&rtp,',.*$','','')
5624 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005625 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005626 let home= substitute(home,'/','\\','g')
5627 endif
5628 endif
5629 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005630 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005631" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005632 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005633" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005634 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005635 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005636" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005637 call mkdir(home)
5638 endif
5639 endif
5640 let g:netrw_home= home
5641 return home
5642endfun
5643
5644" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005645" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5646fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005647 if exists("s:netrwdrag")
5648 return
5649 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005650 if &ft != "netrw"
5651 return
5652 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005653
Bram Moolenaar97d62492012-11-15 21:28:22 +01005654 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005655 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005656 while getchar(0) != 0
5657 "clear the input stream
5658 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005659 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005660 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005661 let mouse_lnum = v:mouse_lnum
5662 let wlastline = line('w$')
5663 let lastline = line('$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005664 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5665 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005666 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005667 return
5668 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005669 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005670 " 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 +01005671 " without this test when its disabled.
5672 " May 26, 2014: edit file, :Lex, resize window -- causes refresh. Reinstated a modified test. See if problems develop.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005673 if v:mouse_col > virtcol('.')
5674 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005675 return
5676 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005677
Bram Moolenaar446cb832008-06-24 21:56:24 +00005678 if a:islocal
5679 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005680 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005681 endif
5682 else
5683 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005684 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005685 endif
5686 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005687 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005688endfun
5689
5690" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005691" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5692fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005693 if &ft != "netrw"
5694 return
5695 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005696 call s:NetrwMarkFileTgt(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005697endfun
5698
5699" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005700" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5701" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005702" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005703" a:islocal=2 : <c-r> used, remote
5704" a:islocal=3 : <c-r> used, local
5705fun! s:NetrwServerEdit(islocal,fname)
5706" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5707 let islocal = a:islocal%2 " =0: remote =1: local
5708 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5709
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005710 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005711 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005712 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005713 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005714 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005715 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5716 unlet s:netrw_browse_split_{winnr()}
5717 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005718 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005719 return
5720 endif
5721
5722 if has("clientserver") && executable("gvim")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005723
5724 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005725 let srvrname = g:netrw_browse_split[0]
5726 let tabnum = g:netrw_browse_split[1]
5727 let winnum = g:netrw_browse_split[2]
5728
5729 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005730 if !ctrlr
5731 " user must have closed the server window and the user did not use <c-r>, but
5732 " used something like <cr>.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005733 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005734 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005735 endif
5736 let g:netrw_browse_split= 0
5737 if exists("s:netrw_browse_split_".winnr())
5738 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5739 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005740 call s:NetrwBrowseChgDir(islocal,a:fname,0)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005741 return
5742
5743 elseif has("win32") && executable("start")
5744 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005745 call system("start gvim --servername ".srvrname)
5746
5747 else
5748 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005749 call system("gvim --servername ".srvrname)
5750 endif
5751 endif
5752
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005753 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5754 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005755 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005756 else
5757
5758 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5759
5760 if !ctrlr
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005761 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005762 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005763 endif
5764 let g:netrw_browse_split= 0
Tom Benham64a536d2024-11-07 21:15:03 +01005765 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005766 return
5767
5768 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005769 if has("win32") && executable("start")
5770 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005771 call system("start gvim --servername ".g:netrw_servername)
5772 else
5773 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005774 call system("gvim --servername ".g:netrw_servername)
5775 endif
5776 endif
5777 endif
5778
5779 while 1
5780 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005781 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005782 break
5783 catch /^Vim\%((\a\+)\)\=:E241/
5784 sleep 200m
5785 endtry
5786 endwhile
5787
5788 if exists("g:netrw_browse_split")
5789 if type(g:netrw_browse_split) != 3
5790 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5791 endif
5792 unlet g:netrw_browse_split
5793 endif
5794 let g:netrw_browse_split= [g:netrw_servername,1,1]
5795 endif
5796
5797 else
5798 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5799 endif
5800
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005801endfun
5802
5803" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005804" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5805fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005806 if &ft != "netrw"
5807 return
5808 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005809" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005810
Bram Moolenaar8d043172014-01-23 14:24:41 +01005811 let s:ngw= s:NetrwGetWord()
5812 call s:NetrwMarkFile(a:islocal,s:ngw)
5813
5814" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005815endfun
5816
5817" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005818" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5819" Used to mark multiple files.
5820fun! s:NetrwSLeftdrag(islocal)
5821" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5822 if !exists("s:netrwdrag")
5823 let s:netrwdrag = winnr()
5824 if a:islocal
5825 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005826 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005827 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005828 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005829 endif
5830 let ngw = s:NetrwGetWord()
5831 if !exists("s:ngw") || s:ngw != ngw
5832 call s:NetrwMarkFile(a:islocal,ngw)
5833 endif
5834 let s:ngw= ngw
5835" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5836endfun
5837
5838" ---------------------------------------------------------------------
5839" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5840fun! s:NetrwSLeftrelease(islocal)
5841" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5842 if exists("s:netrwdrag")
5843 nunmap <s-leftrelease>
5844 let ngw = s:NetrwGetWord()
5845 if !exists("s:ngw") || s:ngw != ngw
5846 call s:NetrwMarkFile(a:islocal,ngw)
5847 endif
5848 if exists("s:ngw")
5849 unlet s:ngw
5850 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005851 unlet s:netrwdrag
5852 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005853" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005854endfun
5855
5856" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01005857" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
5858" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00005859fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005860" 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 +02005861" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005862 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005863
5864 " 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 +02005865 " How-it-works: take the hiding command, convert it into a range.
5866 " Duplicate characters don't matter.
5867 " Remove all such characters from the '/~@#...890' string.
5868 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005869" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005870 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01005871 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005872" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005873
5874 while listhide != ""
5875 if listhide =~ ','
5876 let hide = substitute(listhide,',.*$','','e')
5877 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5878 else
5879 let hide = listhide
5880 let listhide = ""
5881 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005882" 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 +01005883 if g:netrw_sort_by =~ '^[ts]'
5884 if hide =~ '^\^'
5885" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
5886 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
5887 elseif hide =~ '^\\(\^'
5888 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
5889 endif
5890" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
5891 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005892
5893 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005894" 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 +00005895 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005896" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005897 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005898 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005899" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005900 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005901 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005902" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005903 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02005904
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005906 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005907" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005908 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005909" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005910 endif
5911
Bram Moolenaaradc21822011-04-01 18:03:16 +02005912 " remove any blank lines that have somehow remained.
5913 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005914 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005915
Bram Moolenaar97d62492012-11-15 21:28:22 +01005916 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005917" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005918endfun
5919
5920" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005921" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005922" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005923fun! s:NetrwMakeDir(usrhost)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005924
Bram Moolenaar97d62492012-11-15 21:28:22 +01005925 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005926 " get name of new directory from user. A bare <CR> will skip.
5927 " if its currently a directory, also request will be skipped, but with
5928 " a message.
5929 call inputsave()
5930 let newdirname= input("Please give directory name: ")
5931 call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005932
5933 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005934 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005935 return
5936 endif
5937
5938 if a:usrhost == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005939
5940 " Local mkdir:
5941 " sanity checks
5942 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005943 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005944 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005945 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005946 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005947 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005948 return
5949 endif
5950 if s:FileReadable(fullnewdir)
5951 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005952 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005954 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005955 return
5956 endif
5957
5958 " requested new local directory is neither a pre-existing file or
5959 " directory, so make it!
5960 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005961 if has("unix")
5962 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5963 else
5964 call mkdir(fullnewdir,"p")
5965 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005966 else
5967 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005968 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005969 return
5970 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005971 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005972 if v:shell_error != 0
5973 let @@= ykeep
5974 call netrw#ErrorMsg(s:ERROR,"consider setting g:netrw_localmkdir<".g:netrw_localmkdir."> to something that works",80)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005975 return
5976 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005977 if !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02005978 if s:NetrwLcd(netrw_origdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005979 return
5980 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005981 endif
5982 endif
5983
5984 if v:shell_error == 0
5985 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005986 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005987 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005988 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005989 elseif !exists("g:netrw_quiet")
5990 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5991 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005992
5993 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005994 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005995 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5996 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005997 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005998 if v:shell_error == 0
5999 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006000 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006001 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006002 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006003 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006004 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006005 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006006
6007 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01006008 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006009 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006010 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006011 let remotepath= b:netrw_fname
6012 else
6013 let remotepath= ""
6014 endif
6015 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006016 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006017 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01006018
Bram Moolenaar446cb832008-06-24 21:56:24 +00006019 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01006020 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006021 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01006022 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01006023 let remotepath= b:netrw_fname
6024 else
6025 let remotepath= ""
6026 endif
6027 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01006028 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006029 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006030 endif
6031
Bram Moolenaar97d62492012-11-15 21:28:22 +01006032 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01006033endfun
6034
6035" ---------------------------------------------------------------------
6036" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
6037fun! s:TreeSqueezeDir(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006038 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6039 " its a tree-listing style
6040 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006041 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006042 let depth = strchars(substitute(curdepth,' ','','g'))
6043 let srch = -1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006044 if depth >= 2
6045 NetrwKeepj norm! 0
6046 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6047 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006048 elseif depth == 1
6049 NetrwKeepj norm! 0
6050 let treedepthchr= substitute(s:treedepthstring,' ','','')
6051 let srch = search('^[^'.treedepthchr.']','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006052 endif
6053 if srch > 0
Tom Benham64a536d2024-11-07 21:15:03 +01006054 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006055 exe srch
6056 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006057 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006058endfun
6059
6060" ---------------------------------------------------------------------
6061" s:NetrwMaps: {{{2
6062fun! s:NetrwMaps(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006063
Bram Moolenaar85850f32019-07-19 22:05:51 +02006064 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006065 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006066" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006067 if !hasmapto("<Plug>NetrwReturn")
6068 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006069 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6070 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006071 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6072 endif
6073 endif
6074 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006075 endif
6076
Bram Moolenaar85850f32019-07-19 22:05:51 +02006077 " generate default <Plug> maps {{{3
6078 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006079 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006080 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6081 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6082 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6083 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6084 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6085 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6086 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6087 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6088 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6089 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006090
Bram Moolenaara6878372014-03-22 21:02:50 +01006091 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02006092 " local normal-mode maps {{{3
6093 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6094 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6095 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6096 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6097 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6098 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6099 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006100 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006101 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6102 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6103 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6104" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006105 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6106 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6107 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006108 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006109 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006110 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6111 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6112 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6113 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006114 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6115 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6116 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6117 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6118 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6119 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6120 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6121 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6122 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6123 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6124 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6125 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6126 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006127 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006128 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006129 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6130 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6131 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6132 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6133 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006134 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006135 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006136 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006137 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006138 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6139 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6140 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006141 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006142 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006143 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6144 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006145 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006146 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006147 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6148 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6149 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006150 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,0),0)"<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006151 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006152
Tom Benham64a536d2024-11-07 21:15:03 +01006153 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,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006154 if !hasmapto('<Plug>NetrwHideEdit')
6155 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006156 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006157 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006158 if !hasmapto('<Plug>NetrwRefresh')
6159 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006160 endif
Tom Benham64a536d2024-11-07 21:15:03 +01006161 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 : './',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006162 if s:didstarstar || !mapcheck("<s-down>","n")
6163 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006164 endif
6165 if s:didstarstar || !mapcheck("<s-up>","n")
6166 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006167 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006168 if !hasmapto('<Plug>NetrwTreeSqueeze')
6169 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006170 endif
6171 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006172 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6173 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006174 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6175 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6176 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6177 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6178 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6179 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6180 imap <buffer> <leftmouse> <Plug>ILeftmouse
6181 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006182 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6183 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6184 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6185 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6186 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006187 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006188 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6189 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006190 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006191 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6192 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6193 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6194 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6195 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6196 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6197 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006198 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6199
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006200 " support user-specified maps
6201 call netrw#UserMaps(1)
6202
Bram Moolenaar85850f32019-07-19 22:05:51 +02006203 else
6204 " remote normal-mode maps {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006205 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006206 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6207 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6208 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6209 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6210 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6211 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6212 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006213 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
6214 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call <SID>NetrwBrowse(0,<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006215 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6216 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6217" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006218 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6219 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6220 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6221 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6222 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6223 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6224 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6225 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006226 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006227 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006228 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6229 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6230 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6231 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6232 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6233 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6234 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6235 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6236 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6237 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6238 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006239 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006240 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006241 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6242 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6243 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6244 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6245 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006246 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6247 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006248 nnoremap <buffer> <silent> <nowait> p :<c-u>call <SID>NetrwPreview(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1,1))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006249 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006250 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006251 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6252 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006253 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006254 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,'./',0))<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006255 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6256 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6257 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6258 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6259 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6260 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6261 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6262 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006263 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006264 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006265 if !hasmapto('<Plug>NetrwHideEdit')
6266 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006267 endif
6268 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6269 if !hasmapto('<Plug>NetrwRefresh')
6270 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006271 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006272 if !hasmapto('<Plug>NetrwTreeSqueeze')
6273 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006274 endif
6275 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006276
6277 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006278 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006279
Tom Benham64a536d2024-11-07 21:15:03 +01006280 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006281 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006282 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006283 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006284 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006285 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006286 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006287 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006288 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006289 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006290 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006291 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006292 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6293 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6294 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006295 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006296 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006297 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6298 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006299 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006300 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6301 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6302 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6303 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6304 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6305 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6306 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006307 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006308
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006309 " support user-specified maps
6310 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006311 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006312endfun
6313
6314" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006315" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006316" If -buffer, the command is only available from within netrw buffers
6317" Otherwise, the command is available from any window, so long as netrw
6318" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006319fun! s:NetrwCommands(islocal)
6320" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6321
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006322 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6323 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006324 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 +01006325 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006326 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006327 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006328 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006329 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006330 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006331
6332" call Dret("s:NetrwCommands")
6333endfun
6334
6335" ---------------------------------------------------------------------
6336" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6337" glob()ing only works with local files
6338fun! s:NetrwMarkFiles(islocal,...)
6339" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006340 let curdir = s:NetrwGetCurdir(a:islocal)
6341 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006342 while i <= a:0
6343 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006344 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006345 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006346 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006347 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006348 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006349 else
6350 let mffiles= [a:{i}]
6351 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006352" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006353 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006354" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006355 call s:NetrwMarkFile(a:islocal,mffile)
6356 endfor
6357 let i= i + 1
6358 endwhile
6359" call Dret("s:NetrwMarkFiles")
6360endfun
6361
6362" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006363" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006364fun! s:NetrwMarkTarget(...)
Bram Moolenaara6878372014-03-22 21:02:50 +01006365 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006366 let curdir = s:NetrwGetCurdir(1)
6367 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006368 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006369 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6370 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006371 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006372 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006373 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6374 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006375 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006376 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006377 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006378endfun
6379
6380" ---------------------------------------------------------------------
6381" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6382" mark and unmark files. If a markfile list exists,
6383" then the rename and delete functions will use it instead
6384" of whatever may happen to be under the cursor at that
6385" moment. When the mouse and gui are available,
6386" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006387"
6388" Creates two lists
6389" s:netrwmarkfilelist -- holds complete paths to all marked files
6390" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6391"
6392" Creates a marked file match string
6393" s:netrwmarfilemtch_# -- used with 2match to display marked files
6394"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006395" Creates a buffer version of islocal
6396" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006397fun! s:NetrwMarkFile(islocal,fname)
6398" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006399" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006400
6401 " sanity check
6402 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006403" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006404 return
6405 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006406 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006407
Bram Moolenaar97d62492012-11-15 21:28:22 +01006408 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006410 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006411 if a:fname =~ '\a$'
6412 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6413 else
6414 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6415 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006416
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006417 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006418 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006419" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6420" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6421" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006422 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006423
6424 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006425 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006426" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006427 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006428 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006429
6430 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006431 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006432" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006433 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6434 if s:netrwmarkfilelist_{curbufnr} == []
6435 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006436" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006437 call s:NetrwUnmarkList(curbufnr,curdir)
6438 else
6439 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006440" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006441 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006442 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006443 for fname in s:netrwmarkfilelist_{curbufnr}
6444 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006445 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006446 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006447 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006448 endif
6449 let first= 0
6450 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006451" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006452 endif
6453 endif
6454
6455 else
6456 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006457" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006458
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006459" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006460 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006461 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6462" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006463
6464 " build initial markfile matching pattern
6465 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006466 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006467 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006468 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006469 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006470" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006471 endif
6472
6473 " handle global markfilelist
6474 if exists("s:netrwmarkfilelist")
6475 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6476 if index(s:netrwmarkfilelist,dname) == -1
6477 " append new filename to global markfilelist
6478 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006479" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006480 else
6481 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006482" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6483" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006484 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006485" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006486 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006487" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006488 unlet s:netrwmarkfilelist
6489 endif
6490 endif
6491 else
6492 " initialize new global-directory markfilelist
6493 let s:netrwmarkfilelist= []
6494 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006495" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006496 endif
6497
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006498 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006499 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6500 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6501" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6502 if exists("g:did_drchip_netrwlist_syntax")
6503 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6504 endif
6505 else
6506" " call Decho("2match none",'~'.expand("<slnum>"))
6507 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006508 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006509 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006510 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006511" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6512" 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 +00006513endfun
6514
6515" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006516" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6517" mA: move the argument list to marked file list (tomflist=1)
6518" Uses the global marked file list
6519fun! s:NetrwMarkFileArgList(islocal,tomflist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006520 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006521 let curdir = s:NetrwGetCurdir(a:islocal)
6522 let curbufnr = bufnr("%")
6523
6524 if a:tomflist
6525 " mA: move argument list to marked file list
6526 while argc()
6527 let fname= argv(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006528 exe "argdel ".fnameescape(fname)
6529 call s:NetrwMarkFile(a:islocal,fname)
6530 endwhile
6531
6532 else
6533 " ma: move marked file list to argument list
6534 if exists("s:netrwmarkfilelist")
6535
6536 " for every filename in the marked list
6537 for fname in s:netrwmarkfilelist
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006538 exe "argadd ".fnameescape(fname)
6539 endfor " for every file in the marked list
6540
6541 " unmark list and refresh
6542 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006543 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006544 NetrwKeepj call winrestview(svpos)
6545 endif
6546 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006547endfun
6548
6549" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006550" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6551" compress/decompress files using the programs
6552" in g:netrw_compress and g:netrw_uncompress,
6553" using g:netrw_compress_suffix to know which to
6554" do. By default:
6555" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006556" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006557fun! s:NetrwMarkFileCompress(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006558 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006559 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006560 let curbufnr = bufnr("%")
6561
Bram Moolenaarff034192013-04-24 18:51:19 +02006562 " sanity check
6563 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006564 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006565 return
6566 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006567
Bram Moolenaar446cb832008-06-24 21:56:24 +00006568 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006569
6570 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006571 for fname in s:netrwmarkfilelist_{curbufnr}
Christian Brabandtcacfccf2024-11-23 13:28:01 +01006572 let sfx= substitute(fname,'^.\{-}\(\.[[:alnum:]]\+\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006573 if exists("g:netrw_decompress['".sfx."']")
6574 " fname has a suffix indicating that its compressed; apply associated decompression routine
6575 let exe= g:netrw_decompress[sfx]
Bram Moolenaarff034192013-04-24 18:51:19 +02006576 let exe= netrw#WinPath(exe)
6577 if a:islocal
6578 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006579 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006580 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006581 call system(exe." ".fname)
6582 if v:shell_error
6583 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006584 endif
6585 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006586 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6587 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006588 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006589
Bram Moolenaarff034192013-04-24 18:51:19 +02006590 endif
6591 unlet sfx
6592
Bram Moolenaar446cb832008-06-24 21:56:24 +00006593 if exists("exe")
6594 unlet exe
6595 elseif a:islocal
6596 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006597 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006598 if v:shell_error
6599 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6600 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006601 else
6602 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006603 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006604 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006605 endfor " for every file in the marked list
6606
Bram Moolenaar446cb832008-06-24 21:56:24 +00006607 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006608 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006609 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006610 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006611endfun
6612
6613" ---------------------------------------------------------------------
6614" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6615" If no marked files, then set up directory as the
6616" target. Currently does not support copying entire
6617" directories. Uses the local-buffer marked file list.
6618" Returns 1=success (used by NetrwMarkFileMove())
6619" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006620fun! s:NetrwMarkFileCopy(islocal,...)
6621" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6622
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006623 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006624 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006625 if b:netrw_curdir !~ '/$'
6626 if !exists("b:netrw_curdir")
6627 let b:netrw_curdir= curdir
6628 endif
6629 let b:netrw_curdir= b:netrw_curdir."/"
6630 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006631
Bram Moolenaarff034192013-04-24 18:51:19 +02006632 " sanity check
6633 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006634 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006635" call Dret("s:NetrwMarkFileCopy")
6636 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006637 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006638" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006639
Bram Moolenaar446cb832008-06-24 21:56:24 +00006640 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006641 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006642" call Dret("s:NetrwMarkFileCopy 0")
6643 return 0
6644 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006645" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006646
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006647 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006648 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006649" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006650 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006651 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6652" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6653 return
6654 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006655
6656 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02006657 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006658 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6659 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006660" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006661 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006662 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6663 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006664" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006665 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006666 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006667 let oldname = a:1
6668 else
6669 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006670" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006671 let s:recursive= 1
6672 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6673 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6674 if ret == 0
6675 break
6676 endif
6677 endfor
6678 unlet s:recursive
6679 call s:NetrwUnmarkList(curbufnr,curdir)
6680" call Dret("s:NetrwMarkFileCopy ".ret)
6681 return ret
6682 endif
6683
6684 call inputsave()
6685 let newname= input("Copy ".oldname." to : ",oldname,"file")
6686 call inputrestore()
6687 if newname == ""
6688" call Dret("s:NetrwMarkFileCopy 0")
6689 return 0
6690 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006691 let args= s:ShellEscape(oldname)
6692 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006693 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006694 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6695 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006696 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02006697 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02006698 let args= substitute(args,'/','\\','g')
6699 let tgt = substitute(tgt, '/','\\','g')
6700 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006701 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6702 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6703 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6704 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6705" call Decho("args <".args.">",'~'.expand("<slnum>"))
6706" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006707 if isdirectory(s:NetrwFile(args))
6708" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006709 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006710" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02006711 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006712 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6713 " contents to a target. One must append the source directory name to the target to get xcopy to
6714 " do the right thing.
6715 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006716" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006717 endif
6718 else
6719 let copycmd= g:netrw_localcopycmd
6720 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006721 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006722 let copycmd = substitute(copycmd,'\s.*$','','')
6723 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006724 let copycmd = netrw#WinPath(copycmd).copycmdargs
6725 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006726 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006727 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006728" call Decho("args <".args.">",'~'.expand("<slnum>"))
6729" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6730" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6731" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006732 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006733 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02006734 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02006735 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 +01006736 else
6737 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6738 endif
6739" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006740 return 0
6741 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006742
6743 elseif a:islocal && !s:netrwmftgt_islocal
6744 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006745" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006746 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006747
6748 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006749 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006750" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006751 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006752
6753 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006754 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006755" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006756 let curdir = getcwd()
6757 let tmpdir = s:GetTempfile("")
6758 if tmpdir !~ '/'
6759 let tmpdir= curdir."/".tmpdir
6760 endif
6761 if exists("*mkdir")
6762 call mkdir(tmpdir)
6763 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006764 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006765 if v:shell_error != 0
6766 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 +01006767" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006768 return
6769 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006770 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006771 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006772 if s:NetrwLcd(tmpdir)
6773" call Dret("s:NetrwMarkFileCopy : lcd failure")
6774 return
6775 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006776 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006777 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006778 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006779 if getcwd() == tmpdir
6780 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006781 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006782 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02006783 if s:NetrwLcd(curdir)
6784" call Dret("s:NetrwMarkFileCopy : lcd failure")
6785 return
6786 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01006787 if delete(tmpdir,"d")
6788 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006789 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006790 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006791 if s:NetrwLcd(curdir)
6792" call Dret("s:NetrwMarkFileCopy : lcd failure")
6793 return
6794 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006795 endif
6796 endif
6797 endif
6798
6799 " -------
6800 " cleanup
6801 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006802" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006803 " remove markings from local buffer
6804 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006805" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
6806" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
6807" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
6808" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
6809" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
6810" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
6811 if exists("s:recursive")
6812" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
6813 else
6814" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006815 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006816 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006817 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006818 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006819 else
6820 " refresh local and targets for fast browsing
6821 if !exists("s:recursive")
6822 " remove markings from local buffer
6823" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
6824 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
6825 endif
6826
6827 " refresh buffers
6828 if s:netrwmftgt_islocal
6829" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
6830 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6831 endif
6832 if a:islocal && s:netrwmftgt != curdir
6833" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
6834 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
6835 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006836 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006837
Bram Moolenaar446cb832008-06-24 21:56:24 +00006838" call Dret("s:NetrwMarkFileCopy 1")
6839 return 1
6840endfun
6841
6842" ---------------------------------------------------------------------
6843" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6844" invoke vim's diff mode on the marked files.
6845" Either two or three files can be so handled.
6846" Uses the global marked file list.
6847fun! s:NetrwMarkFileDiff(islocal)
6848" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6849 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006850
Bram Moolenaarff034192013-04-24 18:51:19 +02006851 " sanity check
6852 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006853 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006854" call Dret("s:NetrwMarkFileDiff")
6855 return
6856 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006857 let curdir= s:NetrwGetCurdir(a:islocal)
6858" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006859
Bram Moolenaara6878372014-03-22 21:02:50 +01006860 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006861 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006862 for fname in s:netrwmarkfilelist
6863 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006864 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006865" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006866 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006867 diffthis
6868 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09006869 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006870" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006871 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006872 diffthis
6873 else
6874 break
6875 endif
6876 endfor
6877 call s:NetrwUnmarkList(curbufnr,curdir)
6878 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006879
Bram Moolenaar446cb832008-06-24 21:56:24 +00006880" call Dret("s:NetrwMarkFileDiff")
6881endfun
6882
6883" ---------------------------------------------------------------------
6884" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6885" Uses global markfilelist
6886fun! s:NetrwMarkFileEdit(islocal)
6887" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6888
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006889 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006890 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006891
6892 " sanity check
6893 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006894 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006895" call Dret("s:NetrwMarkFileEdit")
6896 return
6897 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006898" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006899
Bram Moolenaar446cb832008-06-24 21:56:24 +00006900 if exists("s:netrwmarkfilelist_{curbufnr}")
6901 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006902 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006903 " unmark markedfile list
6904" call s:NetrwUnmarkList(curbufnr,curdir)
6905 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006906" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02006907 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006908 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006909 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006910
Bram Moolenaar446cb832008-06-24 21:56:24 +00006911" call Dret("s:NetrwMarkFileEdit")
6912endfun
6913
6914" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006915" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02006916fun! s:NetrwMarkFileQFEL(islocal,qfel)
6917" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6918 call s:NetrwUnmarkAll()
6919 let curbufnr= bufnr("%")
6920
6921 if !empty(a:qfel)
6922 for entry in a:qfel
6923 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006924" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006925 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006926" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006927 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6928 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6929 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6930 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006931" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006932 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6933 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006934" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006935 endif
6936 endfor
6937 echo "(use me to edit marked files)"
6938 else
6939 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6940 endif
6941
6942" call Dret("s:NetrwMarkFileQFEL")
6943endfun
6944
6945" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006946" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6947" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6948" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6949fun! s:NetrwMarkFileExe(islocal,enbloc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006950 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006951 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006952 let curbufnr = bufnr("%")
6953
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006954 if a:enbloc == 0
6955 " individually apply command to files, one at a time
6956 " sanity check
6957 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6958 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006959 return
6960 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006961
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006962 if exists("s:netrwmarkfilelist_{curbufnr}")
6963 " get the command
6964 call inputsave()
6965 let cmd= input("Enter command: ","","file")
6966 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006967 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006968 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006969 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006970
6971 " apply command to marked files, individually. Substitute: filename -> %
6972 " If no %, then append a space and the filename to the command
6973 for fname in s:netrwmarkfilelist_{curbufnr}
6974 if a:islocal
6975 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09006976 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006977 endif
6978 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006979 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006980 endif
6981 if cmd =~ '%'
6982 let xcmd= substitute(cmd,'%',fname,'g')
6983 else
6984 let xcmd= cmd.' '.fname
6985 endif
6986 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006987 let ret= system(xcmd)
6988 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006989 let ret= s:RemoteSystem(xcmd)
6990 endif
6991 if v:shell_error < 0
6992 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6993 break
6994 else
yasudac75dad02024-08-22 21:06:32 +02006995 if ret !=# ''
6996 echo "\n"
6997 " skip trailing new line
6998 echo ret[0:-2]
6999 else
7000 echo ret
7001 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007002 endif
7003 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007004
7005 " unmark marked file list
7006 call s:NetrwUnmarkList(curbufnr,curdir)
7007
7008 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007009 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007010 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007011 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007012 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007013 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007014
7015 else " apply command to global list of files, en bloc
7016
7017 call inputsave()
7018 let cmd= input("Enter command: ","","file")
7019 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007020 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007021 return
7022 endif
7023 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007024 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007025 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007026 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007027 endif
7028 if a:islocal
7029 call system(cmd)
7030 if v:shell_error < 0
7031 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
7032 endif
7033 else
7034 let ret= s:RemoteSystem(cmd)
7035 endif
7036 call s:NetrwUnmarkAll()
7037
7038 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007039 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007040 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007041
7042 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007043endfun
7044
7045" ---------------------------------------------------------------------
7046" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7047" as the marked file(s) (toggles suffix presence)
7048" Uses the local marked file list.
7049fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007050 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007051 let curbufnr = bufnr("%")
7052
7053 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7054 if exists("s:netrwmarkfilelist_{curbufnr}")
7055
7056 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007057 " construct suffix pattern
7058 if fname =~ '\.'
7059 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7060 else
7061 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7062 endif
7063 " determine if its in the hiding list or not
7064 let inhidelist= 0
7065 if g:netrw_list_hide != ""
7066 let itemnum = 0
7067 let hidelist= split(g:netrw_list_hide,',')
7068 for hidepat in hidelist
7069 if sfxpat == hidepat
7070 let inhidelist= 1
7071 break
7072 endif
7073 let itemnum= itemnum + 1
7074 endfor
7075 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007076 if inhidelist
7077 " remove sfxpat from list
7078 call remove(hidelist,itemnum)
7079 let g:netrw_list_hide= join(hidelist,",")
7080 elseif g:netrw_list_hide != ""
7081 " append sfxpat to non-empty list
7082 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7083 else
7084 " set hiding list to sfxpat
7085 let g:netrw_list_hide= sfxpat
7086 endif
7087 endfor
7088
7089 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007090 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007091 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007092 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007093 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007094 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007095endfun
7096
7097" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007098" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007099" Uses the local marked-file list.
7100fun! s:NetrwMarkFileVimCmd(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007101 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007102 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007103 let curbufnr = bufnr("%")
7104
Bram Moolenaarff034192013-04-24 18:51:19 +02007105 " sanity check
7106 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007107 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007108 return
7109 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007110
Bram Moolenaar15146672011-10-20 22:22:38 +02007111 if exists("s:netrwmarkfilelist_{curbufnr}")
7112 " get the command
7113 call inputsave()
7114 let cmd= input("Enter vim command: ","","file")
7115 call inputrestore()
Bram Moolenaar15146672011-10-20 22:22:38 +02007116 if cmd == ""
Bram Moolenaar15146672011-10-20 22:22:38 +02007117 return
7118 endif
7119
7120 " apply command to marked files. Substitute: filename -> %
7121 " If no %, then append a space and the filename to the command
7122 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007123 if a:islocal
7124 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007125 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02007126 exe cmd
7127 exe "sil! keepalt wq!"
7128 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007129 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007130 endif
7131 endfor
7132
7133 " unmark marked file list
7134 call s:NetrwUnmarkList(curbufnr,curdir)
7135
7136 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007137 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007138 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007139 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007140 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007141 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007142endfun
7143
7144" ---------------------------------------------------------------------
7145" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7146" as the marked file(s) (toggles suffix presence)
7147" Uses the local marked file list.
7148fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007149 let svpos = winsaveview()
Bram Moolenaar15146672011-10-20 22:22:38 +02007150 let curbufnr = bufnr("%")
7151
7152 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7153 if exists("s:netrwmarkfilelist_{curbufnr}")
7154
7155 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007156 " construct suffix pattern
7157 if fname =~ '\.'
7158 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7159 else
7160 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7161 endif
7162 " determine if its in the hiding list or not
7163 let inhidelist= 0
7164 if g:netrw_list_hide != ""
7165 let itemnum = 0
7166 let hidelist= split(g:netrw_list_hide,',')
7167 for hidepat in hidelist
7168 if sfxpat == hidepat
7169 let inhidelist= 1
7170 break
7171 endif
7172 let itemnum= itemnum + 1
7173 endfor
7174 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007175 if inhidelist
7176 " remove sfxpat from list
7177 call remove(hidelist,itemnum)
7178 let g:netrw_list_hide= join(hidelist,",")
7179 elseif g:netrw_list_hide != ""
7180 " append sfxpat to non-empty list
7181 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7182 else
7183 " set hiding list to sfxpat
7184 let g:netrw_list_hide= sfxpat
7185 endif
7186 endfor
7187
7188 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007189 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007190 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007191 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007192 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007193 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007194endfun
7195
7196" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007197" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7198" Uses the global markfilelist
7199fun! s:NetrwMarkFileGrep(islocal)
7200" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007201 let svpos = winsaveview()
7202" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007203 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007204 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007205
7206 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007207" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007208 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007209" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007210 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007211 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007212" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007213 let netrwmarkfilelist= "*"
7214 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007215
Bram Moolenaarff034192013-04-24 18:51:19 +02007216 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007217" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007218 call inputsave()
7219 let pat= input("Enter pattern: ","")
7220 call inputrestore()
7221 let patbang = ""
7222 if pat =~ '^!'
7223 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007224 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007225 endif
7226 if pat =~ '^\i'
7227 let pat = escape(pat,'/')
7228 let pat = '/'.pat.'/'
7229 else
7230 let nonisi = pat[0]
7231 endif
7232
7233 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007234" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007235 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007236 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007237 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007238 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007239" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7240 return
7241 endtry
7242 echo "(use :cn, :cp to navigate, :Rex to return)"
7243
7244 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007245" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7246 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007247
7248 if exists("nonisi")
7249 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007250" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007251 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007252 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007253 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007254 endif
7255
7256" call Dret("s:NetrwMarkFileGrep")
7257endfun
7258
7259" ---------------------------------------------------------------------
7260" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7261" uses the global marked file list
7262" s:netrwmfloc= 0: target directory is remote
7263" = 1: target directory is local
7264fun! s:NetrwMarkFileMove(islocal)
7265" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007266 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007267 let curbufnr = bufnr("%")
7268
7269 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007270 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007271 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007272" call Dret("s:NetrwMarkFileMove")
7273 return
7274 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007275" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007276
Bram Moolenaar446cb832008-06-24 21:56:24 +00007277 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007278 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007279" call Dret("s:NetrwMarkFileCopy 0")
7280 return 0
7281 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007282" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007283
7284 if a:islocal && s:netrwmftgt_islocal
7285 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007286" call Decho("move from local to local",'~'.expand("<slnum>"))
7287" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007288 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007289 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7290" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7291 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007293 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007294" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007295 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007296 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007297" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007298 if g:netrw_localmovecmd =~ '\s'
7299 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7300 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7301 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007302" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007303 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007304 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007305" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007306 endif
7307 else
7308 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007309" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007310 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007311 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007312 if g:netrw_keepdir
7313 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7314 let fname= b:netrw_curdir."/".fname
7315 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007316 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007317 let fname= substitute(fname,'/','\\','g')
7318 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007319" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007320 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007321 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007322 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007323 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 +01007324 else
7325 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7326 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007327 break
7328 endif
7329 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007330
7331 elseif a:islocal && !s:netrwmftgt_islocal
7332 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007333" call Decho("move from local to remote",'~'.expand("<slnum>"))
7334" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007335 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007336 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007337" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007338 for fname in mflist
7339 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7340 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7341 endfor
7342 unlet mflist
7343
7344 elseif !a:islocal && s:netrwmftgt_islocal
7345 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007346" call Decho("move from remote to local",'~'.expand("<slnum>"))
7347" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007348 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007349 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007350" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007351 for fname in mflist
7352 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7353 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7354 endfor
7355 unlet mflist
7356
7357 elseif !a:islocal && !s:netrwmftgt_islocal
7358 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007359" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7360" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007361 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007362 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007363" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007364 for fname in mflist
7365 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7366 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7367 endfor
7368 unlet mflist
7369 endif
7370
7371 " -------
7372 " cleanup
7373 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007374" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007375
7376 " remove markings from local buffer
7377 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7378
7379 " refresh buffers
7380 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007381" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007382 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007383 endif
7384 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007385" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007386 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007387 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007388 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007389" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007390 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007391 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007392
Bram Moolenaar446cb832008-06-24 21:56:24 +00007393" call Dret("s:NetrwMarkFileMove")
7394endfun
7395
7396" ---------------------------------------------------------------------
7397" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7398" using the hardcopy command. Local marked-file list only.
7399fun! s:NetrwMarkFilePrint(islocal)
7400" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7401 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007402
7403 " sanity check
7404 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007405 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007406" call Dret("s:NetrwMarkFilePrint")
7407 return
7408 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007409" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7410 let curdir= s:NetrwGetCurdir(a:islocal)
7411
Bram Moolenaar446cb832008-06-24 21:56:24 +00007412 if exists("s:netrwmarkfilelist_{curbufnr}")
7413 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007414 call s:NetrwUnmarkList(curbufnr,curdir)
7415 for fname in netrwmarkfilelist
7416 if a:islocal
7417 if g:netrw_keepdir
7418 let fname= s:ComposePath(curdir,fname)
7419 endif
7420 else
7421 let fname= curdir.fname
7422 endif
7423 1split
7424 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007425" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007426 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007427" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007428 hardcopy
7429 q
7430 endfor
7431 2match none
7432 endif
7433" call Dret("s:NetrwMarkFilePrint")
7434endfun
7435
7436" ---------------------------------------------------------------------
7437" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7438" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007439" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007440fun! s:NetrwMarkFileRegexp(islocal)
7441" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7442
7443 " get the regular expression
7444 call inputsave()
7445 let regexp= input("Enter regexp: ","","file")
7446 call inputrestore()
7447
7448 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007449 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007450" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007451 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007452" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007453 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007454 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007455 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007456 else
7457 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007458 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007459 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007460" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007461
7462 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007463 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007464 if fname =~ '^'.fnameescape(curdir)
7465" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7466 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7467 else
7468" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7469 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7470 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007471 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007472
7473 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007474" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007475
7476 " convert displayed listing into a filelist
7477 let eikeep = &ei
7478 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007479 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007480 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007481" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007482 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007483 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007484 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007485 sil NetrwKeepj norm! "ap
7486 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007487 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007488 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007489 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007490 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007491 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007492 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007493 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007494 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007495 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007496 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007497 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7498 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007499 call histdel("/",-1)
7500 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007501 endif
7502 " convert regexp into the more usual glob-style format
7503 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007504" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007505 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007506 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007507 let filelist= getline(1,line("$"))
7508 q!
7509 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007510 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007511 endfor
7512 unlet filelist
7513 let @a = areg
7514 let &ei = eikeep
7515 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007516 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007517
7518" call Dret("s:NetrwMarkFileRegexp")
7519endfun
7520
7521" ---------------------------------------------------------------------
7522" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7523" Uses the local marked file list.
7524fun! s:NetrwMarkFileSource(islocal)
7525" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7526 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007527
7528 " sanity check
7529 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007530 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007531" call Dret("s:NetrwMarkFileSource")
7532 return
7533 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007534" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7535 let curdir= s:NetrwGetCurdir(a:islocal)
7536
Bram Moolenaar446cb832008-06-24 21:56:24 +00007537 if exists("s:netrwmarkfilelist_{curbufnr}")
7538 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007539 call s:NetrwUnmarkList(curbufnr,curdir)
7540 for fname in netrwmarkfilelist
7541 if a:islocal
7542 if g:netrw_keepdir
7543 let fname= s:ComposePath(curdir,fname)
7544 endif
7545 else
7546 let fname= curdir.fname
7547 endif
7548 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007549" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007550 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007551 endfor
7552 2match none
7553 endif
7554" call Dret("s:NetrwMarkFileSource")
7555endfun
7556
7557" ---------------------------------------------------------------------
7558" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7559" Uses the global markfilelist
7560fun! s:NetrwMarkFileTag(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007561 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007562 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007563 let curbufnr = bufnr("%")
7564
Bram Moolenaarff034192013-04-24 18:51:19 +02007565 " sanity check
7566 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007567 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007568 return
7569 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007570
Bram Moolenaar446cb832008-06-24 21:56:24 +00007571 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007572 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007573 call s:NetrwUnmarkAll()
7574
7575 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007576
Bram Moolenaar85850f32019-07-19 22:05:51 +02007577 call system(g:netrw_ctags." ".netrwmarkfilelist)
7578 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007579 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7580 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007581
Bram Moolenaar446cb832008-06-24 21:56:24 +00007582 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007583 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007584 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007585 let curdir= b:netrw_curdir
7586 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007587 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007588 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007589 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007590 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007591 wq!
7592 endif
7593 2match none
Tom Benham64a536d2024-11-07 21:15:03 +01007594 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007595 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007596 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007597endfun
7598
7599" ---------------------------------------------------------------------
7600" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007601" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007602" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007603" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007604" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007605fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007606 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007607 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007608 let hadtgt = exists("s:netrwmftgt")
7609 if !exists("w:netrw_bannercnt")
7610 let w:netrw_bannercnt= b:netrw_bannercnt
7611 endif
7612
7613 " set up target
7614 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007615 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7616 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007617 unlet s:netrwmftgt s:netrwmftgt_islocal
7618 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007619 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007620 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007621 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007622 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007623 return
7624 else
7625 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007626 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007627
7628 else
7629 " get word under cursor.
7630 " * If directory, use it for the target.
7631 " * If file, use b:netrw_curdir for the target
7632 let curword= s:NetrwGetWord()
7633 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007634 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007635 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007636 elseif !a:islocal && tgtdir =~ '/$'
7637 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007638 else
7639 let s:netrwmftgt = curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007640 endif
7641 endif
7642 if a:islocal
7643 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7644 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007645 endif
7646 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007647 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007648 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7649 endif
7650 let s:netrwmftgt_islocal= a:islocal
7651
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007652 " need to do refresh so that the banner will be updated
7653 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007654 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007655 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007656 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007657" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007658 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Tom Benham64a536d2024-11-07 21:15:03 +01007659 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007660 else
Tom Benham64a536d2024-11-07 21:15:03 +01007661 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007662 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007663 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007664 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007665 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007666 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007667endfun
7668
7669" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007670" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7671fun! s:NetrwGetCurdir(islocal)
7672" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7673
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007674 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007675 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7676" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7677 elseif !exists("b:netrw_curdir")
7678 let b:netrw_curdir= getcwd()
7679" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7680 endif
7681
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007682" 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 +01007683 if b:netrw_curdir !~ '\<\a\{3,}://'
7684 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007685" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007686 if g:netrw_keepdir == 0
7687 call s:NetrwLcd(curdir)
7688 endif
7689 endif
7690
7691" call Dret("s:NetrwGetCurdir <".curdir.">")
7692 return b:netrw_curdir
7693endfun
7694
7695" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007696" s:NetrwOpenFile: query user for a filename and open it {{{2
7697fun! s:NetrwOpenFile(islocal)
7698" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007699 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007700 call inputsave()
7701 let fname= input("Enter filename: ")
7702 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02007703" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
7704
7705 " determine if Lexplore is in use
7706 if exists("t:netrw_lexbufnr")
7707 " check if t:netrw_lexbufnr refers to a netrw window
7708" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
7709 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
7710 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
7711" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
7712 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
7713 exe "NetrwKeepj e ".fnameescape(fname)
7714 let @@= ykeep
7715" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
7716 endif
7717 endif
7718
7719 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00007720 if fname !~ '[/\\]'
7721 if exists("b:netrw_curdir")
7722 if exists("g:netrw_quiet")
7723 let netrw_quiet_keep = g:netrw_quiet
7724 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007725 let g:netrw_quiet = 1
7726 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007727 let s:rexposn_{bufnr("%")}= winsaveview()
7728" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007729 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007730 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007731 else
7732 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7733 endif
7734 if exists("netrw_quiet_keep")
7735 let g:netrw_quiet= netrw_quiet_keep
7736 else
7737 unlet g:netrw_quiet
7738 endif
7739 endif
7740 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007741 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007742 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007743 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007744" call Dret("s:NetrwOpenFile")
7745endfun
7746
7747" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007748" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
7749" For the mapping to this function be made via
7750" netrwPlugin, you'll need to have had
7751" g:netrw_usetab set to non-zero.
7752fun! netrw#Shrink()
7753" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
7754 let curwin = winnr()
7755 let wiwkeep = &wiw
7756 set wiw=1
7757
7758 if &ft == "netrw"
7759 if winwidth(0) > g:netrw_wiw
7760 let t:netrw_winwidth= winwidth(0)
7761 exe "vert resize ".g:netrw_wiw
7762 wincmd l
7763 if winnr() == curwin
7764 wincmd h
7765 endif
7766" call Decho("vert resize 0",'~'.expand("<slnum>"))
7767 else
7768 exe "vert resize ".t:netrw_winwidth
7769" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
7770 endif
7771
7772 elseif exists("t:netrw_lexbufnr")
7773 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
7774 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
7775 let t:netrw_winwidth= winwidth(0)
7776 exe "vert resize ".g:netrw_wiw
7777 wincmd l
7778 if winnr() == curwin
7779 wincmd h
7780 endif
7781" call Decho("vert resize 0",'~'.expand("<slnum>"))
7782 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
7783 exe "vert resize ".t:netrw_winwidth
7784" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01007785 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007786 call netrw#Lexplore(0,0)
7787 endif
7788
7789 else
7790 call netrw#Lexplore(0,0)
7791 endif
7792 let wiw= wiwkeep
7793
7794" call Dret("netrw#Shrink")
7795endfun
7796
7797" ---------------------------------------------------------------------
7798" s:NetSortSequence: allows user to edit the sorting sequence {{{2
7799fun! s:NetSortSequence(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007800 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007801 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007802 call inputsave()
7803 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
7804 call inputrestore()
7805
7806 " refresh the listing
7807 let g:netrw_sort_sequence= newsortseq
Tom Benham64a536d2024-11-07 21:15:03 +01007808 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007809 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007810 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007811endfun
7812
7813" ---------------------------------------------------------------------
7814" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
7815" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02007816" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817fun! s:NetrwUnmarkList(curbufnr,curdir)
7818" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7819
7820 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007821 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007822 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7823 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7824 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7825 call remove(s:netrwmarkfilelist,idx) " remove from global list
7826 endfor
7827 if s:netrwmarkfilelist == []
7828 unlet s:netrwmarkfilelist
7829 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007830
Bram Moolenaar446cb832008-06-24 21:56:24 +00007831 " getting rid of the local marked-file lists is easy
7832 unlet s:netrwmarkfilelist_{a:curbufnr}
7833 endif
7834 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7835 unlet s:netrwmarkfilemtch_{a:curbufnr}
7836 endif
7837 2match none
7838" call Dret("s:NetrwUnmarkList")
7839endfun
7840
7841" ---------------------------------------------------------------------
7842" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7843fun! s:NetrwUnmarkAll()
7844" call Dfunc("s:NetrwUnmarkAll()")
7845 if exists("s:netrwmarkfilelist")
7846 unlet s:netrwmarkfilelist
7847 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007848 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007849 2match none
7850" call Dret("s:NetrwUnmarkAll")
7851endfun
7852
7853" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007854" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007855fun! s:NetrwUnmarkAll2()
7856" call Dfunc("s:NetrwUnmarkAll2()")
7857 redir => netrwmarkfilelist_let
7858 let
7859 redir END
7860 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007861 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00007862 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7863 for flist in netrwmarkfilelist_list
7864 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7865 unlet s:netrwmarkfilelist_{curbufnr}
7866 unlet s:netrwmarkfilemtch_{curbufnr}
7867 endfor
7868" call Dret("s:NetrwUnmarkAll2")
7869endfun
7870
7871" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007872" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
7873"
7874" Marked files are in two types of lists:
7875" s:netrwmarkfilelist -- holds complete paths to all marked files
7876" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
7877"
7878" Marked files suitable for use with 2match are in:
7879" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880fun! s:NetrwUnMarkFile(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007881 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007882 let curbufnr = bufnr("%")
7883
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007884 " unmark marked file list
7885 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
7886 if exists("s:netrwmarkfilelist")
7887" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007888 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007889 endif
7890
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007891 let ibuf= 1
7892 while ibuf < bufnr("$")
7893 if exists("s:netrwmarkfilelist_".ibuf)
7894 unlet s:netrwmarkfilelist_{ibuf}
7895 unlet s:netrwmarkfilemtch_{ibuf}
7896 endif
7897 let ibuf = ibuf + 1
7898 endwhile
7899 2match none
7900
Tom Benham64a536d2024-11-07 21:15:03 +01007901" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007902call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007903endfun
7904
7905" ---------------------------------------------------------------------
7906" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7907fun! s:NetrwMenu(domenu)
7908
7909 if !exists("g:NetrwMenuPriority")
7910 let g:NetrwMenuPriority= 80
7911 endif
7912
Bram Moolenaaradc21822011-04-01 18:03:16 +02007913 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007914" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7915
7916 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007917" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007918 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007919 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7920 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7921 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7922 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7923 if g:netrw_dirhistmax > 0
7924 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7925 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7926 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7927 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7928 else
7929 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7930 endif
7931 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7932 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7933 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7934 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7935 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7936 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7937 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7938 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7939 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7940 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7941 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7942 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7943 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7944 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7945 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 +01007946 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 +02007947 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7948 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7949 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7950 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7951 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7952 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7953 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7954 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7955 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7956 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7957 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7958 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7959 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7960 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7961 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7962 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7963 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7964 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7965 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7966 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7967 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7968 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7969 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7970 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7971 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7972 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7973 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7974 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7975 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7976 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>'
7977 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>'
7978 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>'
7979 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7980 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>'
7981 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>'
7982 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 +01007983 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 +02007984 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7985 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007987 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7988 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007989
7990 elseif !a:domenu
7991 let s:netrwcnt = 0
7992 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007993 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007994 exe curwin."wincmd w"
7995
7996 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007997" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007998 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007999" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008000 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00008001 endif
8002 endif
8003" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008004 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005 endif
8006
8007endfun
8008
8009" ---------------------------------------------------------------------
8010" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
8011" Used by the O maps (as <SID>NetrwObtain())
8012fun! s:NetrwObtain(islocal)
8013" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
8014
Bram Moolenaar97d62492012-11-15 21:28:22 +01008015 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008016 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008017 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01008018 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00008019 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
8020 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02008021 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00008022 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008023 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008024
8025" call Dret("NetrwObtain")
8026endfun
8027
8028" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008029" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
8030" If there's only one window, then the window will first be split.
8031" Returns:
8032" choice = 0 : didn't have to choose
8033" choice = 1 : saved modified file in window first
8034" choice = 2 : didn't save modified file, opened window
8035" choice = 3 : cancel open
8036fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008037 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008038 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008039 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008040
8041 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008042 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008043 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008044 let curword = s:NetrwGetWord()
8045 let choice = 0
8046 let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it (s:NetrwTreeDir() will unlet s:prevwinopen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008047 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008048 let curdir = s:treedir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008049
Bram Moolenaar8d043172014-01-23 14:24:41 +01008050 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008051 if lastwinnr == 1
8052 " if only one window, open a new one first
Bram Moolenaar85850f32019-07-19 22:05:51 +02008053 " g:netrw_preview=0: preview window shown in a horizontally split window
8054 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008055 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008056 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008057 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008058 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008059 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008060 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008061 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008062 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008063 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008064 let didsplit = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008065
8066 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008067 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008068 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008069 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008070 wincmd p
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008071
Bram Moolenaar71badf92023-04-22 22:40:14 +01008072 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8073 " whoops -- user trying to open file in the Lexplore window.
8074 " Use Lexplore's opening-file window instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01008075" exe g:netrw_chgwin."wincmd w"
8076 wincmd p
Tom Benham64a536d2024-11-07 21:15:03 +01008077 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008078 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008079
8080 " prevwinnr: the window number of the "prev" window
8081 " prevbufnr: the buffer number of the buffer in the "prev" window
8082 " bnrcnt : the qty of windows open on the "prev" buffer
8083 let prevwinnr = winnr()
8084 let prevbufnr = bufnr("%")
8085 let prevbufname = bufname("%")
8086 let prevmod = &mod
8087 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008088 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008089
8090 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008091 " and it doesn't appear in any other extant window, then ask the
8092 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008093 if prevmod
Bram Moolenaar8d043172014-01-23 14:24:41 +01008094 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008095 exe prevwinnr."wincmd w"
8096
8097 if bnrcnt == 1 && &hidden == 0
8098 " only one copy of the modified buffer in a window, and
8099 " hidden not set, so overwriting will lose the modified file. Ask first...
8100 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008101 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008102
8103 if choice == 1
8104 " Yes -- write file & then browse
8105 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008106 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008107 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008108 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008109 exe origwin."wincmd w"
8110 let &ei = eikeep
8111 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008112 return choice
8113 endif
8114
8115 elseif choice == 2
8116 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar8d043172014-01-23 14:24:41 +01008117 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008118
8119 else
8120 " Cancel -- don't do this
Bram Moolenaar8d043172014-01-23 14:24:41 +01008121 exe origwin."wincmd w"
8122 let &ei= eikeep
8123 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008124 return choice
8125 endif
8126 endif
8127 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008128 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008129 endif
8130
8131 " restore b:netrw_curdir (window split/enew may have lost it)
8132 let b:netrw_curdir= curdir
8133 if a:islocal < 2
8134 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01008135 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008136 else
Tom Benham64a536d2024-11-07 21:15:03 +01008137 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008138 endif
8139 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008140 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008141 return choice
8142endfun
8143
8144" ---------------------------------------------------------------------
8145" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8146" Always assumed to be local -> remote
8147" call s:NetrwUpload(filename, target)
8148" call s:NetrwUpload(filename, target, fromdirectory)
8149fun! s:NetrwUpload(fname,tgt,...)
8150" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8151
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008152 if a:tgt =~ '^\a\{3,}://'
8153 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008154 else
8155 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8156 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008157" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008158
8159 if a:0 > 0
8160 let fromdir= a:1
8161 else
8162 let fromdir= getcwd()
8163 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008164" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008165
8166 if type(a:fname) == 1
8167 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008168" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008169 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008170" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8171 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8172" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008173 if a:tgt =~ '/$'
8174 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008175" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008176 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008177 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008178" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008179 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181 endif
8182 q!
8183
8184 elseif type(a:fname) == 3
8185 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008186" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008187 let curdir= getcwd()
8188 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008189 if s:NetrwLcd(fromdir)
8190" call Dret("s:NetrwUpload : lcd failure")
8191 return
8192 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008193 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195 if exists("g:netrw_port") && g:netrw_port != ""
8196 let useport= " ".g:netrw_scpport." ".g:netrw_port
8197 else
8198 let useport= ""
8199 endif
8200 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8201 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008202 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 +02008203 if s:NetrwLcd(curdir)
8204" call Dret("s:NetrwUpload : lcd failure")
8205 return
8206 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008207
8208 elseif a:tgt =~ '^ftp:'
8209 call s:NetrwMethod(a:tgt)
8210
8211 if b:netrw_method == 2
8212 " handle uploading a list of files via ftp+.netrc
8213 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008214 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008215" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008216
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008217 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008218" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008219
8220 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008221 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008222" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008223 endif
8224
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008225 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008226" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008227
Bram Moolenaaradc21822011-04-01 18:03:16 +02008228 if tgtdir == ""
8229 let tgtdir= '/'
8230 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008231 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008232" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008233
8234 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008235 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8236" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008237 endfor
8238
8239 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008240 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 +00008241 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008242" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8243 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008244 endif
8245 " 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 +01008246 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008247 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008248 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8249 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8250 else
8251 bw!|q
8252 endif
8253
8254 elseif b:netrw_method == 3
8255 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8256 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008257 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008258 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008259 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008260
8261 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008262 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008263" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008264 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008265 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008266" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008267 endif
8268
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008269 if exists("g:netrw_uid") && g:netrw_uid != ""
8270 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008271 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008272" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008273 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008274 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008275 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008276" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008277 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008278 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008279" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008280 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008281 endif
8282
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008283 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008284" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008285
8286 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008287 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008288" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008289 endif
8290
8291 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008292 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008293" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008294 endif
8295
8296 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008297 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008298" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008299 endfor
8300
8301 " perform ftp:
8302 " -i : turns off interactive prompting from ftp
8303 " -n unix : DON'T use <.netrc>, even though it exists
8304 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008305 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008306 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008307 " 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 +01008308 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008309 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008310 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8311 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008312 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008313 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8314 let &debug = debugkeep
8315 let mod = 1
8316 else
8317 bw!|q
8318 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008319 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008320" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008321 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008322 endif
8323 else
8324 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8325 endif
8326 endif
8327
8328" call Dret("s:NetrwUpload")
8329endfun
8330
8331" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008332" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008333fun! s:NetrwPreview(path) range
8334" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008335" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8336" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008337 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008338 NetrwKeepj call s:NetrwOptionsSave("s:")
8339 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8340 NetrwKeepj call s:NetrwOptionsSafe(1)
8341 else
8342 NetrwKeepj call s:NetrwOptionsSafe(0)
8343 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008344 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008345" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008346 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008347" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8348 if g:netrw_preview
8349 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008350 let pvhkeep = &pvh
8351 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8352 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008353" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8354 else
8355 " horizontal split
8356 let pvhkeep = &pvh
8357 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8358 let &pvh = winheight(0) - winsz
8359" 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 +02008360 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008361 " g:netrw_preview g:netrw_alto
8362 " 1 : vert 1: top -- preview window is vertically split off and on the left
8363 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8364 " 0 : 1: top -- preview window is horizontally split off and on the top
8365 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8366 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008367 " 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 +02008368 " the BufEnter event set up in netrwPlugin.vim
8369" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8370 let eikeep = &ei
8371 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008372 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008373 let &ei= eikeep
8374" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008375 if exists("pvhkeep")
8376 let &pvh= pvhkeep
8377 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008378 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008379 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008380 endif
8381 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008382 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 +00008383 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008384 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008385 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008386" call Dret("NetrwPreview")
8387endfun
8388
8389" ---------------------------------------------------------------------
8390" s:NetrwRefresh: {{{2
8391fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008392" 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 +00008393 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008394 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008395" call Decho("setl ma noro",'~'.expand("<slnum>"))
8396" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008397 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008398 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8399 if !exists("w:netrw_treetop")
8400 if exists("b:netrw_curdir")
8401 let w:netrw_treetop= b:netrw_curdir
8402 else
8403 let w:netrw_treetop= getcwd()
8404 endif
8405 endif
8406 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8407 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008408
8409 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008410 let screenposn = winsaveview()
8411" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008412
8413" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8414" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8415 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008416 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008417 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008418 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008419 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008420 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008421
8422 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008423" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8424 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008425
8426 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008427 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8428 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8429" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8430 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8431 else
8432" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8433 2match none
8434 endif
8435 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008436
Bram Moolenaar97d62492012-11-15 21:28:22 +01008437" restore
8438 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008439" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008440endfun
8441
8442" ---------------------------------------------------------------------
8443" s:NetrwRefreshDir: refreshes a directory by name {{{2
8444" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008445" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008446fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008447 if g:netrw_fastbrowse == 0
8448 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008449 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008450
8451 if tgtwin > 0
8452 " tgtwin is being displayed, so refresh it
8453 let curwin= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454 exe tgtwin."wincmd w"
Tom Benham64a536d2024-11-07 21:15:03 +01008455 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008456 exe curwin."wincmd w"
8457
8458 elseif bufnr(a:dirname) > 0
8459 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008460 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008461 endif
8462
8463 elseif g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008464 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008465 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008466endfun
8467
8468" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008469" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8470" window number to do its editing in.
8471" Supports [count]C where the count, if present, is used to specify
8472" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008473fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008474" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008475 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008476" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008477 if a:1 == "" " :NetrwC win#
8478 let g:netrw_chgwin= winnr()
8479 else " :NetrwC
8480 let g:netrw_chgwin= a:1
8481 endif
8482 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008483 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008484 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008485 let g:netrw_chgwin= winnr()
8486 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008487 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008488" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008489endfun
8490
8491" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008492" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8493" What this function does is to compute a priority for the patterns
8494" in the g:netrw_sort_sequence. It applies a substitute to any
8495" "files" that satisfy each pattern, putting the priority / in
8496" front. An "*" pattern handles the default priority.
8497fun! s:NetrwSetSort()
8498" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008499 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008500 if w:netrw_liststyle == s:LONGLIST
8501 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8502 else
8503 let seqlist = g:netrw_sort_sequence
8504 endif
8505 " sanity check -- insure that * appears somewhere
8506 if seqlist == ""
8507 let seqlist= '*'
8508 elseif seqlist !~ '\*'
8509 let seqlist= seqlist.',*'
8510 endif
8511 let priority = 1
8512 while seqlist != ""
8513 if seqlist =~ ','
8514 let seq = substitute(seqlist,',.*$','','e')
8515 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8516 else
8517 let seq = seqlist
8518 let seqlist = ""
8519 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008520 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008521 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008522 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008523 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008524 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008525 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008526 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008527" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008528
8529 " sanity check
8530 if w:netrw_bannercnt > line("$")
8531 " apparently no files were left after a Hiding pattern was used
8532" call Dret("SetSort : no files left after hiding")
8533 return
8534 endif
8535 if seq == '*'
8536 let starpriority= spriority
8537 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008538 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008539 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008540 " sometimes multiple sorting patterns will match the same file or directory.
8541 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008542 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8543 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008544 endif
8545 let priority = priority + 1
8546 endwhile
8547 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008548 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8549 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008550 endif
8551
8552 " Following line associated with priority -- items that satisfy a priority
8553 " pattern get prefixed by ###/ which permits easy sorting by priority.
8554 " Sometimes files can satisfy multiple priority patterns -- only the latest
8555 " priority pattern needs to be retained. So, at this point, these excess
8556 " priority prefixes need to be removed, but not directories that happen to
8557 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008558 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8559 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008560 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008561
8562" call Dret("SetSort")
8563endfun
8564
Bram Moolenaarff034192013-04-24 18:51:19 +02008565" ---------------------------------------------------------------------
8566" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8567" Implements [count]Tb (bookhist<b>)
8568" [count]Th (bookhist<h>)
8569" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008570fun! s:NetrwSetTgt(islocal,bookhist,choice)
8571" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008572
8573 if a:bookhist == 'b'
8574 " supports choosing a bookmark as a target using a qb-generated list
8575 let choice= a:choice - 1
8576 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008577 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008578 else
8579 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8580 endif
8581
8582 elseif a:bookhist == 'h'
8583 " supports choosing a history stack entry as a target using a qb-generated list
8584 let choice= (a:choice % g:netrw_dirhistmax) + 1
8585 if exists("g:netrw_dirhist_".choice)
8586 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008587 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008588 else
8589 echomsg "Sorry, history#".a:choice." not available!"
8590 endif
8591 endif
8592
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008593 " refresh the display
8594 if !exists("b:netrw_curdir")
8595 let b:netrw_curdir= getcwd()
8596 endif
8597 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8598
Bram Moolenaarff034192013-04-24 18:51:19 +02008599" call Dret("s:NetrwSetTgt")
8600endfun
8601
Bram Moolenaar446cb832008-06-24 21:56:24 +00008602" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02008603" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008604fun! s:NetrwSortStyle(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008605 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008606 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008607
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008608 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 +01008609 NetrwKeepj norm! 0
Tom Benham64a536d2024-11-07 21:15:03 +01008610 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008611 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008612endfun
8613
8614" ---------------------------------------------------------------------
8615" s:NetrwSplit: mode {{{2
8616" =0 : net and o
8617" =1 : net and t
8618" =2 : net and v
8619" =3 : local and o
8620" =4 : local and t
8621" =5 : local and v
8622fun! s:NetrwSplit(mode)
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 call s:SaveWinVars()
8626
8627 if a:mode == 0
8628 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008629 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008630 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008631 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008632 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008633 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008634 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008635 unlet s:didsplit
8636
8637 elseif a:mode == 1
8638 " remote and t
Tom Benham64a536d2024-11-07 21:15:03 +01008639 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008640 tabnew
8641 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008642 NetrwKeepj call s:RestoreWinVars()
8643 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008644 unlet s:didsplit
8645
8646 elseif a:mode == 2
8647 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008648 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008649 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008650 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008651 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008652 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008653 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008654 unlet s:didsplit
8655
8656 elseif a:mode == 3
8657 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008658 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008659 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008660 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008661 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008662 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008663 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008664 unlet s:didsplit
8665
8666 elseif a:mode == 4
8667 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008668 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008669 let eikeep = &ei
8670 let netrw_winnr = winnr()
8671 let netrw_line = line(".")
8672 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008673 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008674 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008675 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008676 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8677 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008678 let &ei = eikeep
8679 let netrw_curdir = s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008680 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008681 let b:netrw_curdir = netrw_curdir
8682 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008683 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008684 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008685 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008686 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008687 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8688 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008689 let &ei= eikeep
8690 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008691 unlet s:didsplit
8692
8693 elseif a:mode == 5
8694 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008695 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008696 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008697 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008698 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008699 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008700 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008701 unlet s:didsplit
8702
8703 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008704 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008705 endif
8706
Bram Moolenaar97d62492012-11-15 21:28:22 +01008707 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008708endfun
8709
8710" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008711" s:NetrwTgtMenu: {{{2
8712fun! s:NetrwTgtMenu()
8713 if !exists("s:netrw_menucnt")
8714 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008715 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008716" call Dfunc("s:NetrwTgtMenu()")
8717
8718 " the following test assures that gvim is running, has menus available, and has menus enabled.
8719 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8720 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008721" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008722 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8723 endif
8724 if !exists("s:netrw_initbookhist")
8725 call s:NetrwBookHistRead()
8726 endif
8727
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008728 " try to cull duplicate entries
8729 let tgtdict={}
8730
Bram Moolenaarff034192013-04-24 18:51:19 +02008731 " target bookmarked places
8732 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008733" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008734 let cnt= 1
8735 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008736 if has_key(tgtdict,bmd)
8737 let cnt= cnt + 1
8738 continue
8739 endif
8740 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008741 let ebmd= escape(bmd,g:netrw_menu_escape)
8742 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008743" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008744 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 +02008745 let cnt= cnt + 1
8746 endfor
8747 endif
8748
8749 " target directory browsing history
8750 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008751" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008752 let histcnt = 1
8753 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02008754 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008755 if exists("g:netrw_dirhist_{histcnt}")
8756 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008757 if has_key(tgtdict,histentry)
8758 let histcnt = histcnt + 1
8759 continue
8760 endif
8761 let tgtdict[histentry] = histcnt
8762 let ehistentry = escape(histentry,g:netrw_menu_escape)
8763" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008764 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 +02008765 endif
8766 let histcnt = histcnt + 1
8767 endwhile
8768 endif
8769 endif
8770" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008771endfun
8772
8773" ---------------------------------------------------------------------
8774" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8775" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008776fun! s:NetrwTreeDir(islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008777
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008778 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008779 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8780 let treedir= s:treedir
8781 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008782 unlet s:prevwinopen
Bram Moolenaar8d043172014-01-23 14:24:41 +01008783 return treedir
8784 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008785 if exists("s:prevwinopen")
8786 unlet s:prevwinopen
8787 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008788
Bram Moolenaar8d043172014-01-23 14:24:41 +01008789 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8790 let b:netrw_curdir= getcwd()
8791 endif
8792 let treedir = b:netrw_curdir
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008793 let s:treecurpos= winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008794
8795 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar5c736222010-01-06 20:54:52 +01008796
8797 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008798 let curline= substitute(getline('.'),"\t -->.*$",'','')
8799 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008800 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008801 elseif curline =~ '@$'
Tom Benham64a536d2024-11-07 21:15:03 +01008802 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008803 else
8804 let treedir= ""
8805 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806
8807 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008808 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008809 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008810 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008811 return b:netrw_curdir
8812 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008813
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008814 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
8815" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
8816" let newdir = w:netrw_treetop.'/'.potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008817 if a:islocal && curline =~ '@$'
8818 if isdirectory(s:NetrwFile(potentialdir))
Tom Benham64a536d2024-11-07 21:15:03 +01008819 let treedir = potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008820 let w:netrw_treetop = treedir
8821 endif
8822 else
8823 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
8824 let treedir = s:NetrwTreePath(w:netrw_treetop)
8825 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008826 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008827
8828 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008829 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008830 return treedir
8831endfun
8832
8833" ---------------------------------------------------------------------
8834" s:NetrwTreeDisplay: recursive tree display {{{2
8835fun! s:NetrwTreeDisplay(dir,depth)
Tom Benham64a536d2024-11-07 21:15:03 +01008836 " ensure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008837 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008838
8839 " install ../ and shortdir
8840 if a:depth == ""
8841 call setline(line("$")+1,'../')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008842 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008843 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008844 if a:dir == w:netrw_treetop
8845 let shortdir= a:dir
8846 else
8847 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8848 endif
8849 call setline(line("$")+1,a:depth.shortdir)
8850 else
8851 let shortdir= substitute(a:dir,'^.*/','','e')
8852 call setline(line("$")+1,a:depth.shortdir.'/')
8853 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008854 " append a / to dir if its missing one
8855 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008856
8857 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008858 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008859
Bram Moolenaar85850f32019-07-19 22:05:51 +02008860 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
8861 if g:netrw_hide == 1
8862 " hide given patterns
8863 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008864 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02008865 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008866 endfor
8867
8868 elseif g:netrw_hide == 2
8869 " show given patterns (only)
8870 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008871 let entries=[]
8872 for entry in w:netrw_treedict[dir]
8873 for pat in listhide
8874 if entry =~ pat
8875 call add(entries,entry)
8876 break
8877 endif
8878 endfor
8879 endfor
8880 let w:netrw_treedict[dir]= entries
8881 endif
8882 if depth != ""
8883 " always remove "." and ".." entries when there's depth
8884 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008885 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008886 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008887 call filter(w:netrw_treedict[dir],'v:val !~ "\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008888 endif
8889
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008890 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008891 if dir =~ '/$'
8892 let direntry= substitute(dir.entry,'[@/]$','','e')
8893 else
8894 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
8895 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008896 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008897 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008898 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008899 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
8900 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Tom Benham64a536d2024-11-07 21:15:03 +01008901 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008902 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008903 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008904 endif
8905 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008906endfun
8907
8908" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008909" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
8910fun! s:NetrwRefreshTreeDict(dir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008911 if !exists("w:netrw_treedict")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008912 return
8913 endif
8914
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008915 for entry in w:netrw_treedict[a:dir]
8916 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008917
8918 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008919 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Tom Benham64a536d2024-11-07 21:15:03 +01008920 let filelist = s:NetrwLocalListingList(direntry,0)
8921 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008922
8923 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008924 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Tom Benham64a536d2024-11-07 21:15:03 +01008925 let filelist = s:NetrwLocalListingList(direntry.'/',0)
8926 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008927
8928 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008929 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008930 let liststar = s:NetrwGlob(direntry.'/','*',1)
8931 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008932
8933 else
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008934 endif
8935 endfor
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008936endfun
8937
8938" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008939" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008940" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008941fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008942 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00008943
8944 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008945 if !exists("w:netrw_treetop")
8946 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008947 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01008948 " use \V in case the directory contains specials chars like '$' or '~'
8949 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
8950 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008951 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008952 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008953 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008954 if exists("w:netrw_treetop")
8955 let s:netrw_treetop= w:netrw_treetop
8956 else
8957 let w:netrw_treetop= getcwd()
8958 let s:netrw_treetop= w:netrw_treetop
8959 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008960
Bram Moolenaar446cb832008-06-24 21:56:24 +00008961 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008962 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00008963 let w:netrw_treedict= {}
8964 endif
8965
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008966 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01008967 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008968 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008969 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008970
8971 " if past banner, record word
8972 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8973 let fname= expand("<cword>")
8974 else
8975 let fname= ""
8976 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008977
8978 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008979 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008980
8981 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8982 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008983 1d
8984 endwhile
8985
Bram Moolenaar13600302014-05-22 18:26:40 +02008986 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008987
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008988 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008989 endif
8990endfun
8991
8992" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008993" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01008994" Normally, treetop is w:netrw_treetop, but a
8995" user of the function ( netrw#SetTreetop() )
8996" wipes that out prior to calling this function
8997fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008998" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
8999 if line(".") < w:netrw_bannercnt + 2
9000 let treedir= a:treetop
9001 if treedir !~ '/$'
9002 let treedir= treedir.'/'
9003 endif
9004" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
9005 return treedir
9006 endif
9007
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009008 let svpos = winsaveview()
9009" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009010 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009011" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009012 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009013" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
9014 let curline= getline('.')
9015" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
9016 if curline =~ '/$'
9017" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
9018 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9019" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
9020 elseif curline =~ '@\s\+-->'
9021" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
9022 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
9023 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
9024" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009025 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009026" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009027 let treedir= ""
9028 endif
9029 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009030" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
9031" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009032 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
9033 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
9034 let treedir= dirname.treedir
9035 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009036" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009037 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009038" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009039 if a:treetop =~ '/$'
9040 let treedir= a:treetop.treedir
9041 else
9042 let treedir= a:treetop.'/'.treedir
9043 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009044" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009045 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009046" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009047" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9048 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009049" call Dret("s:NetrwTreePath <".treedir.">")
9050 return treedir
9051endfun
9052
9053" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009054" s:NetrwWideListing: {{{2
9055fun! s:NetrwWideListing()
9056
9057 if w:netrw_liststyle == s:WIDELIST
9058" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9059 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009060 " cpf: characters per filename
9061 " fpl: filenames per line
9062 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009063 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009064 let dict={}
9065 " save the unnamed register and register 0-9 and a
9066 let dict.a=[getreg('a'), getregtype('a')]
9067 for i in range(0, 9)
9068 let dict[i] = [getreg(i), getregtype(i)]
9069 endfor
9070 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009071" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009072 let b:netrw_cpf= 0
9073 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009074 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009075 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9076 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009077 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009078 " restore stored registers
9079 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009080" call Dret("NetrwWideListing")
9081 return
9082 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009083 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009084 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009085" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009086
9087 " determine qty files per line (fpl)
9088 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9089 if w:netrw_fpl <= 0
9090 let w:netrw_fpl= 1
9091 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009092" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009093
9094 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009095 " fpc: files per column of wide listing
9096 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009097 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009098 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9099 let newcolstart = w:netrw_bannercnt + fpc
9100 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009101" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009102 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009103" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009104 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009105 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009106 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009107 while line("$") >= newcolstart
9108 if newcolend > line("$") | let newcolend= line("$") | endif
9109 let newcolqty= newcolend - newcolstart
9110 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009111 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009112 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009113 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009114 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009115 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009116 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009117 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009118 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009119 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009120 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009121" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009122 if @* != keepregstar | sil! let @* = keepregstar | endif
9123 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009124 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009125 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9126 NetrwKeepj call histdel("/",-1)
9127 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9128 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009129" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009130 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009131 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009132" 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 +00009133" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009134 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009135 else
9136 if hasmapto("w","n")
9137 sil! nunmap <buffer> w
9138 endif
9139 if hasmapto("b","n")
9140 sil! nunmap <buffer> b
9141 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009142 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009143endfun
9144
9145" ---------------------------------------------------------------------
9146" s:PerformListing: {{{2
9147fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009148" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9149" 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 +02009150" 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>"))
9151 sil! NetrwKeepj %d _
9152" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009153
Bram Moolenaar15146672011-10-20 22:22:38 +02009154 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009155" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009156 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009157
Bram Moolenaar85850f32019-07-19 22:05:51 +02009158 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009159 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009160" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009161
9162" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009163" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009164" endif " Decho
9165
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009166" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009167 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9168 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009169" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9170 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009171 endif
9172
9173 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009174 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009175
9176 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009177 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009178" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009179 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009180 if exists("g:netrw_pchk")
9181 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9182 " failure detections.
9183 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009184 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009185 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9186 endif
9187 if exists("g:netrw_pchk")
9188 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9189 else
9190 let curdir= b:netrw_curdir
9191 endif
9192 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9193 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9194 else
9195 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009196 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009197 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009198 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009199 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009200" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009201 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009202 let w:netrw_bannercnt= 1
9203 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009204" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9205" 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 +00009206
Bram Moolenaar85850f32019-07-19 22:05:51 +02009207 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009208 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009209 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009210 let sortby= sortby." reversed"
9211 endif
9212
9213 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009214 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009215" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009216 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009217" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009218 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009219 NetrwKeepj put ='\" Sorted by '.sortby
9220 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009221 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9222 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009223" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009224 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009225 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009226 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9227 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009228 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009229" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009230" 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 +00009231 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009232
Bram Moolenaar85850f32019-07-19 22:05:51 +02009233 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009234 if g:netrw_banner
9235 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009236" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009237 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009238 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009239 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009240 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009241 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009242 endif
9243 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009244 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009245" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009246 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009247 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009248 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249
9250 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009251 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009252" 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 +01009253 if g:netrw_list_hide != "" && g:netrw_hide
9254 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009255 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009256 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009257 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009258 endif
9259 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009260 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009261 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009262
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009263" 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 +01009264 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009265" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009266 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009267" 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 +01009268 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009269 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009270" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009271" 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 +00009272 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009273
9274 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009275 if g:netrw_banner
9276 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009277 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009278" 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 +01009279" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009280" 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 +01009281 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009282
Bram Moolenaar446cb832008-06-24 21:56:24 +00009283 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009284" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009285 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009286 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009287 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009288 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009289 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009290" 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 +01009291" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9292 return
9293 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009294 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009295
9296 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009297 if !exists("w:netrw_bannercnt")
9298 let w:netrw_bannercnt= 0
9299 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9301" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9302" 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 +01009303
Bram Moolenaar5c736222010-01-06 20:54:52 +01009304 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009305" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009306" 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 +00009307 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009308 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009309 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009310 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009311" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009312
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009313 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009314 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009315" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009316 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009317
Bram Moolenaar5c736222010-01-06 20:54:52 +01009318 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009319" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009320 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009321 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009322 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009323 else
9324 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009325 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009326 endif
9327 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009328
Bram Moolenaar446cb832008-06-24 21:56:24 +00009329 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009330" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009331 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9332 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009334 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009335 " exten: sort by extension
9336 " The histdel(...,-1) calls remove the last search from the search history
9337" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009338 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9339 NetrwKeepj call histdel("/",-1)
9340 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9341 NetrwKeepj call histdel("/",-1)
9342 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9343 NetrwKeepj call histdel("/",-1)
9344 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9345" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009346 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009347 " normal direction sorting
9348 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9349 else
9350 " reverse direction sorting
9351 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9352 endif
9353 endif
9354 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9355 NetrwKeepj call histdel("/",-1)
9356
Bram Moolenaar446cb832008-06-24 21:56:24 +00009357 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009358 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009359" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009360 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009362 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009363 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009365 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009366 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009367" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009368 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9369 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009370 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009371 endif
9372
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009373 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009374" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009375 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009376 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009377 call histdel("/",-1)
9378 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009379 endif
9380 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009381" 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 +00009382
9383 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009384" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9385" 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 +01009386 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009387" 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 +01009388 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389" 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 +00009390
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009391 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009392 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009393" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +01009394 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009395 endif
9396
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009397 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009398 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009399" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9400 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009401 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009402" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9403 else
9404" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9405" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9406" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9407" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009408 endif
9409
9410 " record previous current directory
9411 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009412" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009413
9414 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009415" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9416" 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 +01009417 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009418" 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 +02009419 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009420" 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 +00009421
9422 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009423" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009424 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009425" 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 +01009426 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009427" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009428 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9429 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009430" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009431" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009432
Bram Moolenaar8d043172014-01-23 14:24:41 +01009433 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009434" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9435" 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 +01009436" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9437 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009438 unlet s:treecurpos
9439 endif
9440
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009441" 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>"))
9442" 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 +00009443" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9444endfun
9445
9446" ---------------------------------------------------------------------
9447" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009448fun! s:SetupNetrwStatusLine(statline)
9449" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9450
9451 if !exists("s:netrw_setup_statline")
9452 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009453" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009454
9455 if !exists("s:netrw_users_stl")
9456 let s:netrw_users_stl= &stl
9457 endif
9458 if !exists("s:netrw_users_ls")
9459 let s:netrw_users_ls= &laststatus
9460 endif
9461
9462 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +02009463 let dict={}
9464 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +00009465 redir @a
9466 try
9467 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009468 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009469 if &bg == "dark"
9470 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9471 else
9472 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9473 endif
9474 endtry
9475 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +02009476 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009477 endif
9478
9479 " set up status line (may use User9 highlighting)
9480 " insure that windows have a statusline
9481 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +09009482 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009483 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009484" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009485 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009486
9487" call Dret("SetupNetrwStatusLine : stl=".&stl)
9488endfun
9489
Bram Moolenaar85850f32019-07-19 22:05:51 +02009490" =========================================
9491" Remote Directory Browsing Support: {{{1
9492" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009493
9494" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009495" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9496" This function assumes that a long listing will be received. Size, time,
9497" and reverse sorts will be requested of the server but not otherwise
9498" enforced here.
9499fun! s:NetrwRemoteFtpCmd(path,listcmd)
9500" 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 +01009501" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009502 " sanity check: {{{3
9503 if !exists("w:netrw_method")
9504 if exists("b:netrw_method")
9505 let w:netrw_method= b:netrw_method
9506 else
9507 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9508" call Dret("NetrwRemoteFtpCmd")
9509 return
9510 endif
9511 endif
9512
9513 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9514 let ffkeep= &ff
9515 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009516" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009517
9518 " clear off any older non-banner lines " {{{3
9519 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009520" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9521 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009522
9523 ".........................................
9524 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9525 " ftp + <.netrc>: Method #2
9526 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009527 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009528 endif
9529 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009530 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009531" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009532 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009533 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009534" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009535 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009536" 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>"))
9537 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 +01009538 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009539" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9540 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 +01009541 endif
9542
9543 ".........................................
9544 elseif w:netrw_method == 3 " {{{3
9545 " ftp + machine,id,passwd,filename: Method #3
9546 setl ff=unix
9547 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009548 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009549 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009550 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009551 endif
9552
9553 " handle userid and password
9554 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009555" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009556 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9557 call NetUserPass("ftp:".host)
9558 endif
9559 if exists("g:netrw_uid") && g:netrw_uid != ""
9560 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009561 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009562 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009563 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009564 endif
9565 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009566 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009567 endif
9568 endif
9569
9570 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009571 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009572 endif
9573 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009574 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009575" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009576 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009577 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009578
9579 " perform ftp:
9580 " -i : turns off interactive prompting from ftp
9581 " -n unix : DON'T use <.netrc>, even though it exists
9582 " -n win32: quit being obnoxious about password
9583 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009584" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009585 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009586" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009587" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9588" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009589 endif
9590
9591 ".........................................
9592 elseif w:netrw_method == 9 " {{{3
9593 " sftp username@machine: Method #9
9594 " s:netrw_sftp_cmd
9595 setl ff=unix
9596
9597 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +09009598 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009599" call Dret("NetrwRemoteFtpCmd")
9600 return
9601
9602 ".........................................
9603 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009604 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009605 endif
9606
9607 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +02009608 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009609 sil! NetrwKeepj %s/\r$//e
9610 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009611 endif
9612 if a:listcmd == "dir"
9613 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009614 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9615 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9616 NetrwKeepj call histdel("/",-1)
9617 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009618 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 +01009619 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9620 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009621 endif
9622 endif
9623
9624 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9625 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009626 exe 'NetrwKeepj '.w:netrw_bannercnt
9627 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009628 endif
9629 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009630 exe 'NetrwKeepj '.w:netrw_bannercnt
9631 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009632 endif
9633
9634 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +09009635 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009636" call Dret("NetrwRemoteFtpCmd")
9637endfun
9638
9639" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009640" s:NetrwRemoteListing: {{{2
9641fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009642" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009643
Bram Moolenaara6878372014-03-22 21:02:50 +01009644 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9645 let w:netrw_bannercnt= s:bannercnt
9646 endif
9647 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +09009648 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009649 endif
9650
Bram Moolenaar446cb832008-06-24 21:56:24 +00009651 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009652
Bram Moolenaar446cb832008-06-24 21:56:24 +00009653 " sanity check:
9654 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009655" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009656 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009657" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009658 if !exists("g:netrw_quiet")
9659 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9660 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009661 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009662" call Dret("s:NetrwRemoteListing -1")
9663 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009664 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009665
Bram Moolenaar8d043172014-01-23 14:24:41 +01009666 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009667" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009668 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009669 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009670 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 +00009671 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009672 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 +00009673 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009674 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009675
Bram Moolenaar85850f32019-07-19 22:05:51 +02009676 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009677" call Dret("s:NetrwRemoteListing -1")
9678 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009679 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009680" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009681
Bram Moolenaar446cb832008-06-24 21:56:24 +00009682 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009683" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009684 let w:netrw_method= b:netrw_method
9685 endif
9686
Bram Moolenaar13600302014-05-22 18:26:40 +02009687 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009688 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009689" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009690 let s:method = "ftp"
9691 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009692 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009693 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009694 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009695 let listcmd= g:netrw_ftp_sizelist_cmd
9696 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009697" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009698 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009699" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009700
Bram Moolenaara6878372014-03-22 21:02:50 +01009701 " report on missing file or directory messages
9702 if search('[Nn]o such file or directory\|Failed to change directory')
9703 let mesg= getline(".")
9704 if exists("w:netrw_bannercnt")
9705 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009706 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009707 setl noma
9708 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009709 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009710 call netrw#ErrorMsg(s:WARNING,mesg,96)
9711" call Dret("s:NetrwRemoteListing : -1")
9712 return -1
9713 endif
9714
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009715 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 +00009716 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009717" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009718 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009719
9720 " cleanup
9721 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009722 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9723 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009724 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009725 sil! NetrwKeepj %s/\r$//e
9726 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009727
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009728 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009729 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009730 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009731 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009732" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009733 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009734" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009735 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009736 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009737 exe "sil! NetrwKeepj ".line1
9738 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009739
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009740" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009741 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009742" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009743 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9744 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009745 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009746" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009747 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9748 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9749 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9750 NetrwKeepj call histdel("/",-1)
9751 NetrwKeepj call histdel("/",-1)
9752 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009753 endif
9754 endif
9755
Bram Moolenaar13600302014-05-22 18:26:40 +02009756 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009757 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009758" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009759 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009760" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009761 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009762" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
9763 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009764 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009765 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9766 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9767 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9768 NetrwKeepj call histdel("/",-1)
9769 NetrwKeepj call histdel("/",-1)
9770 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009771 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009772 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9773 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009774 endif
9775 else
9776 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009777" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009778 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009779 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009780" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
9781 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
9782" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009783 endif
9784 endif
9785
9786 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009787 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009788" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009789 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9790 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009791 endif
9792 endif
9793
9794 if w:netrw_liststyle == s:LONGLIST
9795 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009796" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009797
9798 if s:method == "ftp"
9799 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009800 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009801 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009802 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009803 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009804 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009805 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009806 sil! NetrwKeepj 1
9807 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009808 let line2= line(".")
9809 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009810 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009811 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009812 endif
9813 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009814 exe "sil! NetrwKeepj ".line1
9815 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009816 endif
9817
9818 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009819" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009820 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 +00009821 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009822" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009823 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009825 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9826 NetrwKeepj call histdel("/",-1)
9827 NetrwKeepj call histdel("/",-1)
9828 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009829 endif
9830 endif
9831
9832" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009833" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009834" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009835
9836" call Dret("s:NetrwRemoteListing 0")
9837 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009838endfun
9839
Bram Moolenaar446cb832008-06-24 21:56:24 +00009840" ---------------------------------------------------------------------
9841" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9842fun! s:NetrwRemoteRm(usrhost,path) range
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009843 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009844
9845 let all= 0
9846 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9847 " remove all marked files
9848 for fname in s:netrwmarkfilelist_{bufnr("%")}
9849 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009850 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009851 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009852 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009853 let all= 1
9854 endif
9855 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009856 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009857
9858 else
9859 " remove files specified by range
9860
9861 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009862 let keepsol = &l:sol
9863 setl nosol
9864 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +00009865
9866 " remove multiple files and directories
9867 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009868 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009869 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009870 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009871 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009872 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009873 let all= 1
9874 endif
9875 let ctr= ctr + 1
9876 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009877 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +00009878 endif
9879
9880 " refresh the (remote) directory listing
Tom Benham64a536d2024-11-07 21:15:03 +01009881 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009882 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883endfun
9884
9885" ---------------------------------------------------------------------
9886" s:NetrwRemoteRmFile: {{{2
9887fun! s:NetrwRemoteRmFile(path,rmfile,all)
9888" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9889
9890 let all= a:all
9891 let ok = ""
9892
9893 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9894 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009895" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009896 if !all
9897 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009898" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009899 call inputsave()
9900 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9901 call inputrestore()
9902 echohl NONE
9903 if ok == ""
9904 let ok="no"
9905 endif
9906 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009907 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009908 let all= 1
9909 endif
9910 endif
9911
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009912 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009913" 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 +00009914 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009915" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009916 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009917 if path =~ '^\a\{3,}://'
9918 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009919 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009920 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009921 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9922 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009923" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009924 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009925" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009926 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009927 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009928 let ok="q"
9929 else
MiguelBarroc46c21b2024-01-31 20:07:17 +01009930 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009931" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
9932" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
9933" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009934 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009935 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009936 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009937 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009938 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009939" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009940 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009941 if v:shell_error != 0
9942 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09009943 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 +01009944 else
9945 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
9946 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009947 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009948 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009949 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009950" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009951 endif
9952 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009953 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009954" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009955 endif
9956
9957 else
9958 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009959" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009960 if !all
9961 call inputsave()
9962 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9963 call inputrestore()
9964 if ok == ""
9965 let ok="no"
9966 endif
9967 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009968 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009969 let all= 1
9970 endif
9971 endif
9972
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009973 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00009974 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009975 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009976 else
9977 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009978 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
9979" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009980 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009981" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982
9983 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009984" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
9985 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
9986" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009987 let ret= system(netrw_rmf_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009988" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009989
9990 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009991 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009992 endif
9993 endif
9994 endif
9995
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009996 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009997" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009998 endif
9999 endif
10000
10001" call Dret("s:NetrwRemoteRmFile ".ok)
10002 return ok
10003endfun
10004
10005" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010006" s:NetrwRemoteRename: rename a remote file or directory {{{2
10007fun! s:NetrwRemoteRename(usrhost,path) range
Bram Moolenaar446cb832008-06-24 21:56:24 +000010008
10009 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010010 let svpos = winsaveview()
10011" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010012 let ctr = a:firstline
10013 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
10014
10015 " rename files given by the markfilelist
10016 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10017 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +000010018 if exists("subfrom")
10019 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010020 else
10021 call inputsave()
10022 let newname= input("Moving ".oldname." to : ",oldname)
10023 call inputrestore()
10024 if newname =~ '^s/'
10025 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10026 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
10027 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +000010028 endif
10029 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010030
Bram Moolenaar446cb832008-06-24 21:56:24 +000010031 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010032 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010033 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010034 let oldname= s:ShellEscape(a:path.oldname)
10035 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010036 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010037 endif
10038
10039 endfor
10040 call s:NetrwUnMarkFile(1)
10041
10042 else
10043
10044 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010045 let keepsol= &l:sol
10046 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010047 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010048 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010049
10050 let oldname= s:NetrwGetWord()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010051
10052 call inputsave()
10053 let newname= input("Moving ".oldname." to : ",oldname)
10054 call inputrestore()
10055
10056 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10057 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10058 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010059 let oldname= s:ShellEscape(a:path.oldname)
10060 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010061 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010062 endif
10063
10064 let ctr= ctr + 1
10065 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010066 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010067 endif
10068
10069 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010070 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010071 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010072endfun
10073
Bram Moolenaar85850f32019-07-19 22:05:51 +020010074" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010075" Local Directory Browsing Support: {{{1
10076" ==========================================
10077
10078" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010079" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010080" Should accept: file://localhost/etc/fstab
10081" file:///etc/fstab
10082" file:///c:/WINDOWS/clock.avi
10083" file:///c|/WINDOWS/clock.avi
10084" file://localhost/c:/WINDOWS/clock.avi
10085" file://localhost/c|/WINDOWS/clock.avi
10086" file://c:/foo.txt
10087" file:///c:/foo.txt
10088" 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 +020010089fun! netrw#FileUrlEdit(fname)
10090" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010091 let fname = a:fname
10092 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010093" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010094 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010095" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010096 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010097 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010098 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010099" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010100 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010101" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010102 endif
10103 endif
10104 let fname2396 = netrw#RFC2396(fname)
10105 let fname2396e= fnameescape(fname2396)
10106 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010107 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010108" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010109 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010110" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010111 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10112 endif
10113 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010114
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10116" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010117 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010118 exe 'NetrwKeepj keepalt edit '.plainfname
10119 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10120
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010121" 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 +020010122" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010123 exe "sil doau BufReadPost ".fname2396e
10124endfun
10125
10126" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010127" netrw#LocalBrowseCheck: {{{2
10128fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010129 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010130 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10131 "
10132 " unfortunate interaction -- split window debugging can't be used here, must use
10133 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10134 " another call to LocalBrowseCheck() when attempts to write
10135 " to the DBG buffer are made.
10136 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010137 " The &ft == "netrw" test was installed because the BufEnter event
10138 " would hit when re-entering netrw windows, creating unexpected
10139 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010140" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010141" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010142" 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 +010010143 " getting E930: Cannot use :redir inside execute
10144"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010145" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10146" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010147
Bram Moolenaar97d62492012-11-15 21:28:22 +010010148 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010149 if isdirectory(s:NetrwFile(a:dirname))
10150" 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 +010010151
Bram Moolenaar97d62492012-11-15 21:28:22 +010010152 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010153" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10154" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010155 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010156
Bram Moolenaar446cb832008-06-24 21:56:24 +000010157 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010158" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010159 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010160
Bram Moolenaar5c736222010-01-06 20:54:52 +010010161 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010162" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010163 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010164 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010165 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010166" 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 +010010167" call Dret("netrw#LocalBrowseCheck")
10168 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010169 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010170
Bram Moolenaar85850f32019-07-19 22:05:51 +020010171 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010172 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10173 " AND IF the listing style is not a tree listing
10174 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010175" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010176 let ibuf = 1
10177 let buflast = bufnr("$")
10178 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010179 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10180 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010181 endif
10182 let ibuf= ibuf + 1
10183 endwhile
10184 endif
10185 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010186" 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>"))
10187" 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 +000010188 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010189" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010190endfun
10191
10192" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010193" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010194" performed any shell command. The idea is to cause all local-browsing
10195" buffers to be refreshed after a user has executed some shell command,
10196" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010197fun! s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010198 " determine which buffers currently reside in a tab
10199 if !exists("s:netrw_browselist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010200 return
10201 endif
10202 if !exists("w:netrw_bannercnt")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010203 return
10204 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010205 if !empty(getcmdwintype())
10206 " cannot move away from cmdline window, see :h E11
10207 return
10208 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010209 if exists("s:netrw_events") && s:netrw_events == 1
10210 " s:LocalFastBrowser gets called (indirectly) from a
10211 let s:netrw_events= 2
Bram Moolenaara6878372014-03-22 21:02:50 +010010212 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010213 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010214 let itab = 1
10215 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010216 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010217 while itab <= tabpagenr("$")
10218 let buftablist = buftablist + tabpagebuflist()
10219 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010220 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010221 endwhile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010222 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10223 " | refresh any netrw window
10224 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010225 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010226 let ibl = 0
10227 for ibuf in s:netrw_browselist
Bram Moolenaar446cb832008-06-24 21:56:24 +000010228 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10229 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010230 " (ibuf not shown in a current window AND
10231 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010232 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010233 call remove(s:netrw_browselist,ibl)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010234 continue
10235 elseif index(tabpagebuflist(),ibuf) != -1
10236 " refresh any netrw buffer
Bram Moolenaar446cb832008-06-24 21:56:24 +000010237 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010238 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010239 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10240 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10241 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10242 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010243 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10244 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10245 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010246 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010247 endif
10248 let ibl= ibl + 1
10249 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010250 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010251 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010252endfun
10253
10254" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010255" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10256"
10257" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010258" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010259" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10260" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010261" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010262"
10263" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10264" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010265" (re-using a buffer may not be as accurate)
10266"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010267" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010268" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10269" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10270" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10271" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010272fun! s:LocalFastBrowser()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010273
10274 " initialize browselist, a list of buffer numbers that the local browser has used
10275 if !exists("s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010276 let s:netrw_browselist= []
10277 endif
10278
10279 " append current buffer to fastbrowse list
10280 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaar97d62492012-11-15 21:28:22 +010010281 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010282 endif
10283
10284 " enable autocmd events to handle refreshing/removing local browser buffers
10285 " If local browse buffer is currently showing: refresh it
10286 " If local browse buffer is currently hidden : wipe it
10287 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10288 " =1 : medium speed, re-use directory listing for remote only
10289 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10291 let s:netrw_events= 1
10292 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010293 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010294 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010295 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010296 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010297 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010298 endif
10299 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010300
10301 " user must have changed fastbrowse to its fast setting, so remove
10302 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010303 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara6878372014-03-22 21:02:50 +010010304 unlet s:netrw_events
10305 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010306 au!
10307 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010309 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010310endfun
10311
Tom Benham64a536d2024-11-07 21:15:03 +010010312fun! s:NetrwLocalListingList(dirname,setmaxfilenamelen)
Bram Moolenaara6878372014-03-22 21:02:50 +010010313 " get the list of files contained in the current directory
Tom Benham64a536d2024-11-07 21:15:03 +010010314 let dirname = a:dirname
10315 let dirnamelen = strlen(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010316 let filelist = s:NetrwGlob(dirname,"*",0)
10317 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010318
Nir Lichtman1e34b952024-05-08 19:19:34 +020010319 if g:netrw_cygwin == 0 && has("win32")
Tom Benham64a536d2024-11-07 21:15:03 +010010320 elseif index(filelist,'..') == -1 && dirname !~ '/'
Bram Moolenaara6878372014-03-22 21:02:50 +010010321 " include ../ in the glob() entry if its missing
Tom Benham64a536d2024-11-07 21:15:03 +010010322 let filelist= filelist+[s:ComposePath(dirname,"../")]
Bram Moolenaara6878372014-03-22 21:02:50 +010010323 endif
10324
Tom Benham64a536d2024-11-07 21:15:03 +010010325 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010326 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10327 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara6878372014-03-22 21:02:50 +010010328 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010329
Tom Benham64a536d2024-11-07 21:15:03 +010010330 let resultfilelist = []
Bram Moolenaara6878372014-03-22 21:02:50 +010010331 for filename in filelist
Bram Moolenaara6878372014-03-22 21:02:50 +010010332
10333 if getftype(filename) == "link"
10334 " indicate a symbolic link
Bram Moolenaara6878372014-03-22 21:02:50 +010010335 let pfile= filename."@"
10336
10337 elseif getftype(filename) == "socket"
10338 " indicate a socket
Bram Moolenaara6878372014-03-22 21:02:50 +010010339 let pfile= filename."="
10340
10341 elseif getftype(filename) == "fifo"
10342 " indicate a fifo
Bram Moolenaara6878372014-03-22 21:02:50 +010010343 let pfile= filename."|"
10344
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010345 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010346 " indicate a directory
Bram Moolenaara6878372014-03-22 21:02:50 +010010347 let pfile= filename."/"
10348
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010349 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020010350 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010351 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10352 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010353 let pfile= filename."*"
10354 else
10355 " normal file
10356 let pfile= filename
10357 endif
10358 elseif executable(filename)
10359 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010360 let pfile= filename."*"
10361 else
10362 " normal file
10363 let pfile= filename
10364 endif
10365
10366 else
10367 " normal file
10368 let pfile= filename
10369 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010370
10371 if pfile =~ '//$'
10372 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010373 endif
10374 let pfile= strpart(pfile,dirnamelen)
10375 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010376
10377 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090010378 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
10379 let sz = getfsize(filename)
10380 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
10381 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010010382
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010383 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010384 let sz= s:NetrwHumanReadable(sz)
10385 endif
K.Takata8750e3c2023-11-22 18:20:01 +090010386 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090010387 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010388 endif
10389
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010390 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010391 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010392 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara6878372014-03-22 21:02:50 +010010393 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010394 let ft = printf("%018d",t)
Bram Moolenaara6878372014-03-22 21:02:50 +010010395 let ftpfile= ft.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010396 let resultfilelist += [ftpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010397
10398 elseif g:netrw_sort_by =~ "^s"
10399 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara6878372014-03-22 21:02:50 +010010400 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010401 let fsz = printf("%018d",sz)
Bram Moolenaara6878372014-03-22 21:02:50 +010010402 let fszpfile= fsz.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010403 let resultfilelist += [fszpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010404
10405 else
10406 " sort by name
Tom Benham64a536d2024-11-07 21:15:03 +010010407 let resultfilelist += [pfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010408 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010409 endfor
10410
10411 return resultfilelist
10412endfun
10413
10414" ---------------------------------------------------------------------
10415" s:LocalListing: does the job of "ls" for local directories {{{2
10416fun! s:LocalListing()
10417
10418 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1)
10419 for filename in filelist
10420 sil! NetrwKeepj put =filename
Bram Moolenaara6878372014-03-22 21:02:50 +010010421 endfor
10422
10423 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010424 sil! NetrwKeepj g/^$/d
10425 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010426 call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010427 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010428endfun
10429
10430" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010431" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10432fun! s:NetrwLocalExecute(cmd)
10433" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10434 let ykeep= @@
10435 " sanity check
10436 if !executable(a:cmd)
10437 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10438 let @@= ykeep
10439" call Dret("s:NetrwLocalExecute")
10440 return
10441 endif
10442
10443 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010444" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010445 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010446" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010447
10448 " strip any ansi escape sequences off
10449 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10450
10451 " show user the result(s)
10452 echomsg result
10453 let @@= ykeep
10454
10455" call Dret("s:NetrwLocalExecute")
10456endfun
10457
10458" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010459" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010460fun! s:NetrwLocalRename(path) range
Bram Moolenaar97d62492012-11-15 21:28:22 +010010461
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010462 if !exists("w:netrw_bannercnt")
10463 let w:netrw_bannercnt= b:netrw_bannercnt
10464 endif
10465
Bram Moolenaar97d62492012-11-15 21:28:22 +010010466 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010010467 let ykeep = @@
10468 let ctr = a:firstline
10469 let svpos = winsaveview()
10470 let all = 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010471
10472 " rename files given by the markfilelist
10473 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10474 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar97d62492012-11-15 21:28:22 +010010475 if exists("subfrom")
10476 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010477 else
10478 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010479 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010480 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010481 if newname =~ ''
10482 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10483 let newname = substitute(newname,'^.*','','')
10484 elseif newname =~ ''
10485 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10486 let newname = substitute(newname,'[^/]*','','')
10487 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010488 if newname =~ '^s/'
10489 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10490 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010491 let newname = substitute(oldname,subfrom,subto,'')
10492 endif
10493 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010010494 if !all && filereadable(newname)
10495 call inputsave()
10496 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
10497 call inputrestore()
10498 if response == "all"
10499 let all= 1
10500 elseif response != "y" && response != "yes"
10501 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010502 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar29634562020-01-09 21:46:04 +010010503 NetrwKeepj call winrestview(svpos)
10504 let @@= ykeep
Bram Moolenaar29634562020-01-09 21:46:04 +010010505 return
10506 endif
10507 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010508 call rename(oldname,newname)
10509 endfor
10510 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010511
Bram Moolenaar97d62492012-11-15 21:28:22 +010010512 else
10513
10514 " attempt to rename files/directories
10515 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010516 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010517
10518 " sanity checks
10519 if line(".") < w:netrw_bannercnt
10520 let ctr= ctr + 1
10521 continue
10522 endif
10523 let curword= s:NetrwGetWord()
10524 if curword == "./" || curword == "../"
10525 let ctr= ctr + 1
10526 continue
10527 endif
10528
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010529 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010530 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010531
10532 call inputsave()
10533 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10534 call inputrestore()
10535
10536 call rename(oldname,newname)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010537 let ctr= ctr + 1
10538 endwhile
10539 endif
10540
10541 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010542 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010543 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010544 let @@= ykeep
Bram Moolenaar97d62492012-11-15 21:28:22 +010010545endfun
10546
10547" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010548" s:NetrwLocalRm: {{{2
10549fun! s:NetrwLocalRm(path) range
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010550 if !exists("w:netrw_bannercnt")
10551 let w:netrw_bannercnt= b:netrw_bannercnt
10552 endif
10553
Bram Moolenaar446cb832008-06-24 21:56:24 +000010554 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010555 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010556 let ret = 0
10557 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010558 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010559
10560 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10561 " remove all marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562 for fname in s:netrwmarkfilelist_{bufnr("%")}
10563 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010564 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010566 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010567 let all= 1
10568 endif
10569 endfor
10570 call s:NetrwUnMarkFile(1)
10571
10572 else
10573 " remove (multiple) files and directories
Bram Moolenaar446cb832008-06-24 21:56:24 +000010574
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010575 let keepsol= &l:sol
10576 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010577 let ctr = a:firstline
10578 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010579 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010580
10581 " sanity checks
10582 if line(".") < w:netrw_bannercnt
10583 let ctr= ctr + 1
10584 continue
10585 endif
10586 let curword= s:NetrwGetWord()
10587 if curword == "./" || curword == "../"
10588 let ctr= ctr + 1
10589 continue
10590 endif
10591 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010592 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010593 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010594 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010595 let all= 1
10596 endif
10597 let ctr= ctr + 1
10598 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010599 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 endif
10601
10602 " refresh the directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010603 if bufname("%") != "NetrwMessage"
Tom Benham64a536d2024-11-07 21:15:03 +010010604 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010605 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010606 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010607 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010608endfun
10609
10610" ---------------------------------------------------------------------
10611" s:NetrwLocalRmFile: remove file fname given the path {{{2
10612" Give confirmation prompt unless all==1
10613fun! s:NetrwLocalRmFile(path,fname,all)
10614" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010615
Bram Moolenaar446cb832008-06-24 21:56:24 +000010616 let all= a:all
10617 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010618 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020010619 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010620" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010621
10622 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10623 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010624" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010625 if !all
10626 echohl Statement
10627 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010628 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010629 call inputrestore()
10630 echohl NONE
10631 if ok == ""
10632 let ok="no"
10633 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010634" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010635 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010636" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010637 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010638 let all= 1
10639 endif
10640 endif
10641
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010642 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010643 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010644" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010645 endif
10646
10647 else
10648 " attempt to remove directory
10649 if !all
10650 echohl Statement
10651 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010652 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010653 call inputrestore()
10654 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10655 if ok == ""
10656 let ok="no"
10657 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010658 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010659 let all= 1
10660 endif
10661 endif
10662 let rmfile= substitute(rmfile,'[\/]$','','e')
10663
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010664 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020010665 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010010666 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010667 endif
10668 endif
10669 endif
10670
10671" call Dret("s:NetrwLocalRmFile ".ok)
10672 return ok
10673endfun
10674
Bram Moolenaar85850f32019-07-19 22:05:51 +020010675" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010676" Support Functions: {{{1
10677
Bram Moolenaar488c6512005-08-11 20:09:58 +000010678" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010679" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10680" 0: marked file list of current buffer
10681" 1: marked file target
10682fun! netrw#Access(ilist)
10683 if a:ilist == 0
10684 if exists("s:netrwmarkfilelist_".bufnr('%'))
10685 return s:netrwmarkfilelist_{bufnr('%')}
10686 else
10687 return "no-list-buf#".bufnr('%')
10688 endif
10689 elseif a:ilist == 1
10690 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020010691 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010692endfun
10693
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010694" ---------------------------------------------------------------------
10695" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
10696fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010697 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010698endfun
10699
Bram Moolenaara6878372014-03-22 21:02:50 +010010700" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010701" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
10702" I expect this function to be used in
10703" :PChkAssert netrw#Expose("netrwmarkfilelist")
10704" for example.
10705fun! netrw#Expose(varname)
10706" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010707 if exists("s:".a:varname)
10708 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010709" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010710 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010711" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010712 if type(retval) == 3
10713 let retval = copy(retval)
10714 let i = 0
10715 while i < len(retval)
10716 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
10717 let i = i + 1
10718 endwhile
10719 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010720" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010721 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010722 else
10723" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010724 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010725 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010726" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010727 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010728 endif
10729
10730" call Dret("netrw#Expose ".string(retval))
10731 return retval
10732endfun
10733
10734" ---------------------------------------------------------------------
10735" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
10736fun! netrw#Modify(varname,newvalue)
10737" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
10738 exe "let s:".a:varname."= ".string(a:newvalue)
10739" call Dret("netrw#Modify")
10740endfun
10741
10742" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010743" netrw#RFC2396: converts %xx into characters {{{2
10744fun! netrw#RFC2396(fname)
10745" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090010746 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010010747" call Dret("netrw#RFC2396 ".fname)
10748 return fname
10749endfun
10750
10751" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010752" netrw#UserMaps: supports user-specified maps {{{2
10753" see :help function()
10754"
10755" g:Netrw_UserMaps is a List with members such as:
10756" [[keymap sequence, function reference],...]
10757"
10758" The referenced function may return a string,
10759" refresh : refresh the display
10760" -other- : this string will be executed
10761" or it may return a List of strings.
10762"
10763" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020010764" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010765" Related functions:
10766" netrw#Expose(varname) -- see s:varname variables
10767" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
10768" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
10769fun! netrw#UserMaps(islocal)
10770" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
10771" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
10772
10773 " set up usermaplist
10774 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
10775" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
10776 for umap in g:Netrw_UserMaps
10777" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
10778" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
10779 " if umap[0] is a string and umap[1] is a string holding a function name
10780 if type(umap[0]) == 1 && type(umap[1]) == 1
10781" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
10782 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
10783 else
10784 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
10785 endif
10786 endfor
10787 endif
10788" call Dret("netrw#UserMaps")
10789endfun
10790
10791" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010792" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10793fun! netrw#WinPath(path)
10794" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010795 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010796 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010797 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010798 " remove trailing slash (Win95)
10799 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10800 " remove escaped spaces
10801 let path = substitute(path, '\ ', ' ', 'g')
10802 " convert slashes to backslashes
10803 let path = substitute(path, '/', '\', 'g')
10804 else
10805 let path= a:path
10806 endif
10807" call Dret("netrw#WinPath <".path.">")
10808 return path
10809endfun
10810
10811" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020010812" s:StripTrailingSlash: removes trailing slashes from a path {{{2
10813fun! s:StripTrailingSlash(path)
10814 " remove trailing slash
10815 return substitute(a:path, '[/\\]$', '', 'g')
10816endfun
10817
Travis Sheltone34d0e32024-07-30 21:08:56 +020010818" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010819" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
10820" cb : bl2mf=0 add marked files to buffer list
10821" cB : bl2mf=1 use bufferlist to mark files
10822" (mnemonic: cb = copy (marked files) to buffer list)
10823fun! s:NetrwBadd(islocal,bl2mf)
10824" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
10825 if a:bl2mf
10826 " cB: add buffer list to marked files
10827 redir => bufl
10828 ls
10829 redir END
10830 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
10831 for fname in bufl
10832 call s:NetrwMarkFile(a:islocal,fname)
10833 endfor
10834 else
10835 " cb: add marked files to buffer list
10836 for fname in s:netrwmarkfilelist_{bufnr("%")}
10837" " call Decho("badd ".fname,'~'.expand("<slnum>"))
10838 exe "badd ".fnameescape(fname)
10839 endfor
10840 let curbufnr = bufnr("%")
10841 let curdir = s:NetrwGetCurdir(a:islocal)
10842 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
10843 endif
10844" call Dret("s:NetrwBadd")
10845endfun
10846
10847" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010848" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10849fun! s:ComposePath(base,subdir)
10850" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10851
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010852 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010853" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010854 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010855 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010856 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010857 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010858 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010859 endif
10860
Bram Moolenaar85850f32019-07-19 22:05:51 +020010861 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020010862 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010863" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010864 let ret= a:subdir
10865
Nir Lichtman1e34b952024-05-08 19:19:34 +020010866 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010867" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010868 if a:base =~ '[/\\]$'
10869 let ret= a:base.a:subdir
10870 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010871 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010010872 endif
10873
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010874 elseif a:base =~ '^\a\{3,}://'
10875" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010876 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10877 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10878 if a:subdir == '../'
10879 if curpath =~ '[^/]/[^/]\+/$'
10880 let curpath= substitute(curpath,'[^/]\+/$','','')
10881 else
10882 let curpath=""
10883 endif
10884 let ret= urlbase.curpath
10885 else
10886 let ret= urlbase.curpath.a:subdir
10887 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010888" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
10889" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
10890" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010891
10892 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010893" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010894 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10895 if a:base =~ '^//'
10896 " keeping initial '//' for the benefit of network share listing support
10897 let ret= '/'.ret
10898 endif
10899 let ret= simplify(ret)
10900 endif
10901
10902" call Dret("s:ComposePath ".ret)
10903 return ret
10904endfun
10905
10906" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010907" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10908" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10909fun! s:DeleteBookmark(fname)
10910" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10911 call s:MergeBookmarks()
10912
10913 if exists("g:netrw_bookmarklist")
10914 let indx= index(g:netrw_bookmarklist,a:fname)
10915 if indx == -1
10916 let indx= 0
10917 while indx < len(g:netrw_bookmarklist)
10918 if g:netrw_bookmarklist[indx] =~ a:fname
10919 call remove(g:netrw_bookmarklist,indx)
10920 let indx= indx - 1
10921 endif
10922 let indx= indx + 1
10923 endwhile
10924 else
10925 " remove exact match
10926 call remove(g:netrw_bookmarklist,indx)
10927 endif
10928 endif
10929
10930" call Dret("s:DeleteBookmark")
10931endfun
10932
10933" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010934" s:FileReadable: o/s independent filereadable {{{2
10935fun! s:FileReadable(fname)
10936" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10937
10938 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010939 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010941 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010942 endif
10943
10944" call Dret("s:FileReadable ".ret)
10945 return ret
10946endfun
10947
10948" ---------------------------------------------------------------------
10949" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10950" Places correct suffix on end of temporary filename,
10951" using the suffix provided with fname
10952fun! s:GetTempfile(fname)
10953" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10954
10955 if !exists("b:netrw_tmpfile")
10956 " get a brand new temporary filename
10957 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010958" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010959
Bram Moolenaarc236c162008-07-13 17:41:49 +000010960 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010961" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010962
Bram Moolenaar9964e462007-05-05 17:54:07 +000010963 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010964 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
10965" 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 +010010966 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010967" call Dret("s:GetTempfile getcwd<".getcwd().">")
10968 return ""
10969 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010970
Bram Moolenaar9964e462007-05-05 17:54:07 +000010971 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010972 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010973" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010974
Bram Moolenaar9964e462007-05-05 17:54:07 +000010975 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010976 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010977 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020010978 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010979 if !exists("+shellslash") || !&ssl
10980 let tmpfile = substitute(tmpfile,'/','\','g')
10981 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010982 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010983 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010984 endif
10985 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010986" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010987 else
10988 " re-use temporary filename
10989 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010990" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010991 endif
10992
10993 " use fname's suffix for the temporary file
10994 if a:fname != ""
10995 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010996" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010997 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010998 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010999 elseif a:fname =~ '.txz$'
11000 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011001 else
11002 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
11003 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011004" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011005 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011006" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011007 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011008" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011009 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
11010 endif
11011 endif
11012
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011013" 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 +000011014" call Dret("s:GetTempfile <".tmpfile.">")
11015 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000011016endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000011017
11018" ---------------------------------------------------------------------
11019" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000011020" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000011021fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011022" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020011023 if s:user == ""
11024 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
11025 else
11026 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
11027 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011028 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011029 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011030 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000011031 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000011032 else
11033 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
11034 endif
11035" call Dret("s:MakeSshCmd <".sshcmd.">")
11036 return sshcmd
11037endfun
11038
11039" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011040" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11041fun! s:MakeBookmark(fname)
11042" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11043
11044 if !exists("g:netrw_bookmarklist")
11045 let g:netrw_bookmarklist= []
11046 endif
11047
11048 if index(g:netrw_bookmarklist,a:fname) == -1
11049 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011050 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011051 call add(g:netrw_bookmarklist,a:fname.'/')
11052 elseif a:fname !~ '/'
11053 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11054 else
11055 call add(g:netrw_bookmarklist,a:fname)
11056 endif
11057 call sort(g:netrw_bookmarklist)
11058 endif
11059
11060" call Dret("s:MakeBookmark")
11061endfun
11062
11063" ---------------------------------------------------------------------
11064" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11065fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011066" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011067 " get bookmarks from .netrwbook file
11068 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011069 if filereadable(s:NetrwFile(savefile))
11070" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011071 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011072" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011073 NetrwKeepj call delete(savefile)
11074 endif
11075" call Dret("s:MergeBookmarks")
11076endfun
11077
11078" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011079" s:NetrwBMShow: {{{2
11080fun! s:NetrwBMShow()
11081" call Dfunc("s:NetrwBMShow()")
11082 redir => bmshowraw
11083 menu
11084 redir END
11085 let bmshowlist = split(bmshowraw,'\n')
11086 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011087 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011088 if bmshowfuncs != []
11089 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011090 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011091 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011092 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011093 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011094 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011095" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11096endfun
11097
11098" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011099" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011100fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011101 if !exists("w:netrw_liststyle")
11102 let w:netrw_liststyle= g:netrw_liststyle
11103 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011104" 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 +020011105
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011106" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11107
Bram Moolenaaradc21822011-04-01 18:03:16 +020011108 if &ft != "netrw"
11109 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11110 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011111" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011112
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011113 elseif g:netrw_cursor == 8
11114 if w:netrw_liststyle == s:WIDELIST
11115 setl cursorline
11116 setl cursorcolumn
11117 else
11118 setl cursorline
11119 endif
11120 elseif g:netrw_cursor == 7
11121 setl cursorline
11122 elseif g:netrw_cursor == 6
11123 if w:netrw_liststyle == s:WIDELIST
11124 setl cursorline
11125 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011126 elseif g:netrw_cursor == 4
11127 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011128" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011129 setl cursorline
11130 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011131
11132 elseif g:netrw_cursor == 3
11133 " thin-long-tree: cursorline, user's cursorcolumn
11134 " wide : cursorline, cursorcolumn
11135 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011136" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011137 setl cursorline
11138 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011139 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011140" 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 +020011141 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011142 endif
11143
11144 elseif g:netrw_cursor == 2
11145 " thin-long-tree: cursorline, user's cursorcolumn
11146 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011147" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011148 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011149
11150 elseif g:netrw_cursor == 1
11151 " thin-long-tree: user's cursorline, user's cursorcolumn
11152 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011153 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011154" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011155 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011156 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011157" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011158 endif
11159
11160 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011161 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011162" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011163 let &l:cursorline = s:netrw_usercul
11164 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011165 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011166
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011167" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011168" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011169endfun
11170
11171" ---------------------------------------------------------------------
11172" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11173fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011174" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011175 if exists("s:netrw_usercul")
11176 let &l:cursorline = s:netrw_usercul
11177 endif
11178 if exists("s:netrw_usercuc")
11179 let &l:cursorcolumn = s:netrw_usercuc
11180 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011181" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011182" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11183endfun
11184
Christian Brabandt62f7b552024-06-23 20:23:40 +020011185" s:RestoreRegister: restores all registers given in the dict {{{2
11186fun! s:RestoreRegister(dict)
11187 for [key, val] in items(a:dict)
11188 if key == 'unnamed'
11189 let key = ''
11190 endif
11191 call setreg(key, val[0], val[1])
11192 endfor
11193endfun
11194
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011195" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011196" s:NetrwDelete: Deletes a file. {{{2
11197" Uses Steve Hall's idea to insure that Windows paths stay
11198" acceptable. No effect on Unix paths.
11199" Examples of use: let result= s:NetrwDelete(path)
11200fun! s:NetrwDelete(path)
11201" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11202
Bram Moolenaar5c736222010-01-06 20:54:52 +010011203 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011204 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011205 if exists("+shellslash")
11206 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011207 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011208 let result = delete(path)
11209 let &shellslash = sskeep
11210 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011211" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011212 let result= delete(path)
11213 endif
11214 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011215" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011216 let result= delete(path)
11217 endif
11218 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011219 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011220 endif
11221
11222" call Dret("s:NetrwDelete ".result)
11223 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011224endfun
11225
11226" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011227" s:NetrwBufRemover: removes a buffer that: {{{2s
11228" has buffer-id > 1
11229" is unlisted
11230" is unnamed
11231" does not appear in any window
11232fun! s:NetrwBufRemover(bufid)
11233" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11234" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11235" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11236" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11237" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11238
yasuda4dbb2662023-10-04 20:50:35 +020011239 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011240" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011241 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011242 endif
11243
11244" call Dret("s:NetrwBufRemover")
11245endfun
11246
11247" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011248" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011249fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011250" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011251" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011252
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011253 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011254 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11255 " If so, delete it.
11256 call s:NetrwBufRemover(bufnr("$"))
11257
Bram Moolenaar446cb832008-06-24 21:56:24 +000011258 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011259" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011260 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11261 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11262 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11263 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11264 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11265 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11266 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11267 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11268 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11269 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11270 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11271 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11272 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11273 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11274 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11275 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11276
Bram Moolenaar85850f32019-07-19 22:05:51 +020011277 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011278" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011279 " when tree listing uses file TreeListing... a new buffer is made.
11280 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011281 " COMBAK: this causes a problem, see P43
11282" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011283 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011284 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011285 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011286" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011287 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011288
Bram Moolenaar446cb832008-06-24 21:56:24 +000011289 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011290" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011291 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11292 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11293 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11294 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11295 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11296 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11297 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11298 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11299 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11300 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11301 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11302 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11303 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11304 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11305 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11306 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11307
Bram Moolenaar5c736222010-01-06 20:54:52 +010011308 if a:0 > 0
11309 let b:netrw_curdir= a:1
11310 if b:netrw_curdir =~ '/$'
11311 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011312 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011313 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011314 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011315 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11316 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011317 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011318 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011319 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011320 endif
11321 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011322 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
11323 let &l:bexpr = "netrw#BalloonHelp()"
11324 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011325
Bram Moolenaar8d043172014-01-23 14:24:41 +010011326" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011327endfun
11328
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011329" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011330" s:NetrwExe: executes a string using "!" {{{2
11331fun! s:NetrwExe(cmd)
GuyBrushd7745ac2024-11-23 14:13:10 +010011332 if has("win32") && exepath(&shell) !~? '\v[\/]?(cmd|pwsh|powershell)(\.exe)?$' && !g:netrw_cygwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011333 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11334 set shell& shellcmdflag& shellxquote& shellxescape&
11335 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010011336 try
11337 exe a:cmd
11338 finally
11339 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11340 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011341 else
11342 exe a:cmd
11343 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011344 if v:shell_error
11345 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11346 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011347endfun
11348
11349" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011350" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11351fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011352 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011353" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011354 let curbuf = bufnr("%")
11355 let curwin = winnr()
11356 let iwin = 1
11357 while iwin <= winnr("$")
11358 exe iwin."wincmd w"
11359 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11360 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11361 let winvars= w:
11362 break
11363 endif
11364 let iwin= iwin + 1
11365 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011366 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011367 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011368" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011369 for k in keys(winvars)
11370 let w:{k}= winvars[k]
11371 endfor
11372 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011373" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011374 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011375endfun
11376
Bram Moolenaara6878372014-03-22 21:02:50 +010011377" ---------------------------------------------------------------------
11378" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011379" Returns: 0=success
11380" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011381fun! s:NetrwLcd(newdir)
11382" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011383" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011384
Bram Moolenaar85850f32019-07-19 22:05:51 +020011385 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011386 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011387 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011388 catch /^Vim\%((\a\+)\)\=:E344/
11389 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11390 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011391 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011392 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11393 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020011394 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010011395 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11396 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090011397 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011398 endif
11399 endif
11400 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011401 let err472= 1
11402 endtry
11403
11404 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011405 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11406 if exists("w:netrw_prvdir")
11407 let a:newdir= w:netrw_prvdir
11408 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011409 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011410" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011411 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011412" 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 +010011413 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011414 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011415" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11416 return -1
11417 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011418
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011419" call Decho("getcwd <".getcwd().">")
11420" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011421" call Dret("s:NetrwLcd 0")
11422 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011423endfun
11424
Bram Moolenaar9964e462007-05-05 17:54:07 +000011425" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011426" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11427" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11428fun! s:NetrwSaveWordPosn()
11429" call Dfunc("NetrwSaveWordPosn()")
11430 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11431" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11432endfun
11433
11434" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011435" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11436" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11437fun! s:NetrwHumanReadable(sz)
11438" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11439
11440 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011441 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011442 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11443 elseif a:sz >= 10000000
11444 let sz = printf("%d",a:sz/1000000)."m"
11445 elseif a:sz >= 1000000
11446 let sz = printf("%.1f",a:sz/1000000.0)."m"
11447 elseif a:sz >= 10000
11448 let sz = printf("%d",a:sz/1000)."k"
11449 elseif a:sz >= 1000
11450 let sz = printf("%.1f",a:sz/1000.0)."k"
11451 else
11452 let sz= a:sz
11453 endif
11454
11455 elseif g:netrw_sizestyle == 'H'
11456 if a:sz >= 1073741824
11457 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11458 elseif a:sz >= 10485760
11459 let sz = printf("%d",a:sz/1048576)."M"
11460 elseif a:sz >= 1048576
11461 let sz = printf("%.1f",a:sz/1048576.0)."M"
11462 elseif a:sz >= 10240
11463 let sz = printf("%d",a:sz/1024)."K"
11464 elseif a:sz >= 1024
11465 let sz = printf("%.1f",a:sz/1024.0)."K"
11466 else
11467 let sz= a:sz
11468 endif
11469
11470 else
11471 let sz= a:sz
11472 endif
11473
11474" call Dret("s:NetrwHumanReadable ".sz)
11475 return sz
11476endfun
11477
11478" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011479" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11480" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11481fun! s:NetrwRestoreWordPosn()
11482" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011483 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011484" call Dret("NetrwRestoreWordPosn")
11485endfun
11486
11487" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011488" s:RestoreBufVars: {{{2
11489fun! s:RestoreBufVars()
11490" call Dfunc("s:RestoreBufVars()")
11491
11492 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11493 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11494 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11495 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11496 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11497 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11498
11499" call Dret("s:RestoreBufVars")
11500endfun
11501
11502" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011503" s:RemotePathAnalysis: {{{2
11504fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011505" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011506
Bram Moolenaara6878372014-03-22 21:02:50 +010011507 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011508 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011509 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011510 let s:user = substitute(a:dirname,dirpat,'\3','')
11511 let s:machine = substitute(a:dirname,dirpat,'\4','')
11512 let s:port = substitute(a:dirname,dirpat,'\5','')
11513 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011514 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011515 if s:machine =~ '@'
11516 let dirpat = '^\(.*\)@\(.\{-}\)$'
11517 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11518 let s:machine = substitute(s:machine,dirpat,'\2','')
11519 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011520
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011521" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11522" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11523" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11524" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11525" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11526" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011527
11528" call Dret("s:RemotePathAnalysis")
11529endfun
11530
11531" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011532" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11533" Returns status
11534" Runs system() on
11535" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011536" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011537fun! s:RemoteSystem(cmd)
11538" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11539 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011540 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 +000011541 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011542 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011543 else
11544 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11545 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11546 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011547 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011548 else
11549 let cmd= cmd.' '
11550 endif
11551 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011552" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011553 let ret= system(cmd)
11554 endif
11555" call Dret("s:RemoteSystem ".ret)
11556 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011557endfun
11558
11559" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011560" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011561fun! s:RestoreWinVars()
11562" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011563 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011564 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11565 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11566 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11567 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11568 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11569 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11570 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11571 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11572 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11573 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11574 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11575 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011576 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11577 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011578 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11579 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11580 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11581" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011582endfun
11583
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011584" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011585" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11586"
11587" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11588" is true) and a command, :Rexplore, which call this function.
11589"
Bram Moolenaar85850f32019-07-19 22:05:51 +020011590" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011591"
11592" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011593fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011594 if exists("s:netrwdrag")
11595 return
11596 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011597" 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 +010011598" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11599" 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 +010011600
11601 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011602 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011603" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011604 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011605 unlet w:netrw_rexfile
11606" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011607 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011608" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011609" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11610" 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 +020011611 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011612
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011613 " ---------------------------
11614 " :Rex issued while in a file
11615 " ---------------------------
11616
Bram Moolenaara6878372014-03-22 21:02:50 +010011617 " record current file so :Rex can return to it from netrw
11618 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011619" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011620
11621 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011622" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011623 return
11624 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011625" 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 +020011626 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011627 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011628 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011629 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011630 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011631 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011632 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011633 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011634 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011635" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11636 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011637" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11638 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011639 if exists("s:rexposn_".bufnr('%'))
11640 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011641 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011642 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011643" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011644 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011645
Bram Moolenaar85850f32019-07-19 22:05:51 +020011646 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11647 if exists("s:explore_match")
11648 exe "2match netrwMarkFile /".s:explore_match."/"
11649 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011650 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011651
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011652" 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 +010011653" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011654endfun
11655
11656" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011657" s:SaveBufVars: save selected b: variables to s: variables {{{2
11658" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011659fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011660" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011661
11662 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11663 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11664 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11665 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11666 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11667 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11668
11669" call Dret("s:SaveBufVars")
11670endfun
11671
11672" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011673" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
11674fun! s:SavePosn(posndict)
11675" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
11676
Bram Moolenaar85850f32019-07-19 22:05:51 +020011677 if !exists("a:posndict[bufnr('%')]")
11678 let a:posndict[bufnr("%")]= []
11679 endif
11680" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11681 call add(a:posndict[bufnr("%")],winsaveview())
11682" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011683
11684" call Dret("s:SavePosn posndict")
11685 return a:posndict
11686endfun
11687
11688" ---------------------------------------------------------------------
11689" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
11690fun! s:RestorePosn(posndict)
11691" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011692 if exists("a:posndict")
11693 if has_key(a:posndict,bufnr("%"))
11694" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11695 let posnlen= len(a:posndict[bufnr("%")])
11696 if posnlen > 0
11697 let posnlen= posnlen - 1
11698" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
11699 call winrestview(a:posndict[bufnr("%")][posnlen])
11700 call remove(a:posndict[bufnr("%")],posnlen)
11701" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11702 endif
11703 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011704 endif
11705" call Dret("s:RestorePosn")
11706endfun
11707
11708" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011709" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011710fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011711" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011712 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11713 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11714 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11715 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11716 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11717 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11718 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11719 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11720 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11721 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11722 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11723 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11724 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11725 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11726 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11727 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11728 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11729 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11730" call Dret("s:SaveWinVars")
11731endfun
11732
11733" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011734" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011735" To allow separate windows to have their own activities, such as
11736" Explore **/pattern, several variables have been made window-oriented.
11737" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011738" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011739" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011740fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011741" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011742 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11743 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11744 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11745 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11746 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11747 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11748 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11749 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11750 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11751 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11752" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011753endfun
11754
11755" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011756" s:SetRexDir: set directory for :Rexplore {{{2
11757fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011758" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011759 let w:netrw_rexdir = a:dirname
11760 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011761 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011762" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
11763" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011764" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011765" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011766" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011767endfun
11768
11769" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011770" s:ShowLink: used to modify thin and tree listings to show links {{{2
11771fun! s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011772 if exists("b:netrw_curdir")
11773 norm! $?\a
Tom Benham64a536d2024-11-07 21:15:03 +010011774 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
11775 let basedir = s:NetrwTreePath(w:netrw_treetop)
11776 else
11777 let basedir = b:netrw_curdir.'/'
11778 endif
11779 let fname = basedir.s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011780 let resname = resolve(fname)
Tom Benham64a536d2024-11-07 21:15:03 +010011781 if resname =~ '^\M'.basedir
11782 let dirlen = strlen(basedir)
11783 let resname = strpart(resname,dirlen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011784 endif
11785 let modline = getline(".")."\t --> ".resname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011786 setl noro ma
11787 call setline(".",modline)
11788 setl ro noma nomod
11789 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011790endfun
11791
11792" ---------------------------------------------------------------------
11793" s:ShowStyle: {{{2
11794fun! s:ShowStyle()
11795 if !exists("w:netrw_liststyle")
11796 let liststyle= g:netrw_liststyle
11797 else
11798 let liststyle= w:netrw_liststyle
11799 endif
11800 if liststyle == s:THINLIST
11801 return s:THINLIST.":thin"
11802 elseif liststyle == s:LONGLIST
11803 return s:LONGLIST.":long"
11804 elseif liststyle == s:WIDELIST
11805 return s:WIDELIST.":wide"
11806 elseif liststyle == s:TREELIST
11807 return s:TREELIST.":tree"
11808 else
11809 return 'n/a'
11810 endif
11811endfun
11812
11813" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011814" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11815" Solution from Nicolai Weibull, vim docs (:help strlen()),
11816" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011817fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011818" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11819
11820 if v:version >= 703 && exists("*strdisplaywidth")
11821 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011822
Bram Moolenaar8d043172014-01-23 14:24:41 +010011823 elseif type(g:Align_xstrlen) == 1
11824 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11825 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011826
Bram Moolenaar8d043172014-01-23 14:24:41 +010011827 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011828 " number of codepoints (Latin a + combining circumflex is two codepoints)
11829 " (comment from TM, solution from NW)
11830 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011831
Bram Moolenaar8d043172014-01-23 14:24:41 +010011832 elseif g:Align_xstrlen == 2
11833 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011834 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11835 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011836 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011837
Bram Moolenaar8d043172014-01-23 14:24:41 +010011838 elseif g:Align_xstrlen == 3
11839 " virtual length (counting, for instance, tabs as anything between 1 and
11840 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011841 " preceded by lam, one otherwise, etc.)
11842 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011843 let modkeep= &l:mod
11844 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011845 call setline(line("."),a:x)
11846 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011847 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011848 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011849 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011850
Bram Moolenaar446cb832008-06-24 21:56:24 +000011851 else
11852 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011853 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011854 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011855" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011856 return ret
11857endfun
11858
11859" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011860" s:ShellEscape: shellescape(), or special windows handling {{{2
11861fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011862 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011863 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011864 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011865 let f = a:0 > 0 ? a:1 : 0
11866 return shellescape(a:s, f)
11867endfun
11868
11869" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011870" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000011871fun! s:TreeListMove(dir)
11872" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011873 let curline = getline('.')
11874 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11875 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11876 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
11877 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
11878 let treedepthchr = substitute(s:treedepthstring,' ','','g')
11879 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
11880" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
11881" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
11882" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
11883" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
11884" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
11885 " COMBAK : need to handle when on a directory
11886 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000011887 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011888 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011889 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011890 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011891" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011892 elseif a:dir == '[]' && nxtline != ''
11893 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011894" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011895 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
11896 if nl != 0
11897 NetrwKeepj norm! k
11898 else
11899 NetrwKeepj norm! G
11900 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011901" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011902 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011903 endif
11904
11905" call Dret("s:TreeListMove")
11906endfun
11907
11908" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011909" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11910" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11911" can't be called except via emenu. But due to locale, that menu line may not be called
11912" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11913fun! s:UpdateBuffersMenu()
11914" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011915 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011916 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011917 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011918 catch /^Vim\%((\a\+)\)\=:E/
11919 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011920 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011921 endtry
11922 endif
11923" call Dret("s:UpdateBuffersMenu")
11924endfun
11925
11926" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011927" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011928" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011929fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011930" call Dfunc("s:UseBufWinVars()")
11931 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011932 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11933 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11934 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11935 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11936 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11937 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11938 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11939 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11940 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 +000011941" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011942endfun
11943
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011944" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011945" s:UserMaps: supports user-defined UserMaps {{{2
11946" * calls a user-supplied funcref(islocal,curdir)
11947" * interprets result
11948" See netrw#UserMaps()
11949fun! s:UserMaps(islocal,funcname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011950 if !exists("b:netrw_curdir")
11951 let b:netrw_curdir= getcwd()
11952 endif
11953 let Funcref = function(a:funcname)
11954 let result = Funcref(a:islocal)
11955
11956 if type(result) == 1
11957 " if result from user's funcref is a string...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011958 if result == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011959 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011960 elseif result != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011961 exe result
11962 endif
11963
11964 elseif type(result) == 3
11965 " if result from user's funcref is a List...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011966 for action in result
11967 if action == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011968 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011969 elseif action != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011970 exe action
11971 endif
11972 endfor
11973 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011974endfun
11975
Bram Moolenaar85850f32019-07-19 22:05:51 +020011976" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011977" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011978" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000011979let &cpo= s:keepcpo
11980unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011981
Bram Moolenaar85850f32019-07-19 22:05:51 +020011982" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000011983" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011984" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985" vim:ts=8 fdm=marker