blob: 6799a3444b25f0abb0310779394c7fbb67ba1c3e [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)
Travis Sheltone34d0e32024-07-30 21:08:56 +020037" }}}
Christian Brabandtf9ca1392024-02-19 20:37:11 +010038" Former Maintainer: Charles E Campbell
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000039" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
Bram Moolenaare0fa3742016-02-20 15:47:01 +010040" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
Bram Moolenaar572cb562005-08-05 21:35:02 +000041" Permission is hereby granted to use and distribute this code,
42" with or without modifications, provided that this copyright
43" notice is copied with it. Like anything else that's free,
Bram Moolenaar1afcace2005-11-25 19:54:28 +000044" netrw.vim, netrwPlugin.vim, and netrwSettings.vim are provided
Bram Moolenaar446cb832008-06-24 21:56:24 +000045" *as is* and come with no warranty of any kind, either
Bram Moolenaar1afcace2005-11-25 19:54:28 +000046" expressed or implied. By using this plugin, you agree that
47" in no event will the copyright holder be liable for any damages
48" resulting from the use of this software.
Bram Moolenaar91359012019-11-30 17:57:03 +010049"
50" Note: the code here was started in 1999 under a much earlier version of vim. The directory browsing
51" code was written using vim v6, which did not have Lists (Lists were first offered with vim-v7).
52"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020053"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar071d4272004-06-13 20:20:40 +000054"
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000055" But be doers of the Word, and not only hearers, deluding your own selves {{{1
Bram Moolenaar071d4272004-06-13 20:20:40 +000056" (James 1:22 RSV)
57" =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Bram Moolenaar9964e462007-05-05 17:54:07 +000058" Load Once: {{{1
Bram Moolenaar1afcace2005-11-25 19:54:28 +000059if &cp || exists("g:loaded_netrw")
60 finish
61endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020062
63" Check that vim has patches that netrw requires.
64" Patches needed for v7.4: 1557, and 213.
65" (netrw will benefit from vim's having patch#656, too)
66let s:needspatches=[1557,213]
67if exists("s:needspatches")
68 for ptch in s:needspatches
69 if v:version < 704 || (v:version == 704 && !has("patch".ptch))
70 if !exists("s:needpatch{ptch}")
71 unsilent echomsg "***sorry*** this version of netrw requires vim v7.4 with patch#".ptch
72 endif
73 let s:needpatch{ptch}= 1
74 finish
75 endif
76 endfor
Bram Moolenaar13600302014-05-22 18:26:40 +020077endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020078
Bram Moolenaarb7398fe2023-05-14 18:50:25 +010079let g:loaded_netrw = "v173"
Bram Moolenaar446cb832008-06-24 21:56:24 +000080
Bram Moolenaar1afcace2005-11-25 19:54:28 +000081let s:keepcpo= &cpo
Bram Moolenaara6878372014-03-22 21:02:50 +010082setl cpo&vim
Bram Moolenaar85850f32019-07-19 22:05:51 +020083"DechoFuncName 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010084"DechoRemOn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010085"call Decho("doing autoload/netrw.vim version ".g:loaded_netrw,'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +000086
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +000087" ======================
88" Netrw Variables: {{{1
89" ======================
90
Bram Moolenaar071d4272004-06-13 20:20:40 +000091" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020092" netrw#ErrorMsg: {{{2
93" 0=note = s:NOTE
94" 1=warning = s:WARNING
95" 2=error = s:ERROR
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010096" Usage: netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,"some message",error-number)
97" netrw#ErrorMsg(s:NOTE | s:WARNING | s:ERROR,["message1","message2",...],error-number)
98" (this function can optionally take a list of messages)
Bram Moolenaar29634562020-01-09 21:46:04 +010099" Dec 2, 2019 : max errnum currently is 106
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200100fun! netrw#ErrorMsg(level,msg,errnum)
101" call Dfunc("netrw#ErrorMsg(level=".a:level." msg<".a:msg."> errnum=".a:errnum.") g:netrw_use_errorwindow=".g:netrw_use_errorwindow)
102
103 if a:level < g:netrw_errorlvl
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200104" call Dret("netrw#ErrorMsg : suppressing level=".a:level." since g:netrw_errorlvl=".g:netrw_errorlvl)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200105 return
106 endif
107
108 if a:level == 1
109 let level= "**warning** (netrw) "
110 elseif a:level == 2
111 let level= "**error** (netrw) "
112 else
113 let level= "**note** (netrw) "
114 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100115" call Decho("level=".level,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200116
Damienb4d11642024-08-15 22:00:45 +0200117 if g:netrw_use_errorwindow == 2 && exists("*popup_atcursor")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200118 " use popup window
119 if type(a:msg) == 3
120 let msg = [level]+a:msg
121 else
122 let msg= level.a:msg
123 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200124 let s:popuperr_id = popup_atcursor(msg,{})
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200125 let s:popuperr_text= ""
126 elseif g:netrw_use_errorwindow
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200127 " (default) netrw creates a one-line window to show error/warning
128 " messages (reliably displayed)
129
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100130 " record current window number
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200131 let s:winBeforeErr= winnr()
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100132" call Decho("s:winBeforeErr=".s:winBeforeErr,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200133
134 " getting messages out reliably is just plain difficult!
135 " This attempt splits the current window, creating a one line window.
136 if bufexists("NetrwMessage") && bufwinnr("NetrwMessage") > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100137" call Decho("write to NetrwMessage buffer",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200138 exe bufwinnr("NetrwMessage")."wincmd w"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100139" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200140 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100141 if type(a:msg) == 3
142 for msg in a:msg
143 NetrwKeepj call setline(line("$")+1,level.msg)
144 endfor
145 else
146 NetrwKeepj call setline(line("$")+1,level.a:msg)
147 endif
148 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200149 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100150" call Decho("create a NetrwMessage buffer window",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200151 bo 1split
152 sil! call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +0200153 sil! NetrwKeepj call s:NetrwOptionsSafe(1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200154 setl bt=nofile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100155 NetrwKeepj file NetrwMessage
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100156" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200157 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100158 if type(a:msg) == 3
159 for msg in a:msg
160 NetrwKeepj call setline(line("$")+1,level.msg)
161 endfor
162 else
163 NetrwKeepj call setline(line("$"),level.a:msg)
164 endif
165 NetrwKeepj $
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200166 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100167" call Decho("wrote msg<".level.a:msg."> to NetrwMessage win#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200168 if &fo !~ '[ta]'
169 syn clear
170 syn match netrwMesgNote "^\*\*note\*\*"
171 syn match netrwMesgWarning "^\*\*warning\*\*"
172 syn match netrwMesgError "^\*\*error\*\*"
173 hi link netrwMesgWarning WarningMsg
174 hi link netrwMesgError Error
175 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100176" call Decho("setl noma ro bh=wipe",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +0200177 setl ro nomod noma bh=wipe
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200178
179 else
180 " (optional) netrw will show messages using echomsg. Even if the
181 " message doesn't appear, at least it'll be recallable via :messages
182" redraw!
183 if a:level == s:WARNING
184 echohl WarningMsg
185 elseif a:level == s:ERROR
186 echohl Error
187 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100188
189 if type(a:msg) == 3
190 for msg in a:msg
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100191 unsilent echomsg level.msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100192 endfor
193 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100194 unsilent echomsg level.a:msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100195 endif
196
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100197" call Decho("echomsg ***netrw*** ".a:msg,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200198 echohl None
199 endif
200
201" call Dret("netrw#ErrorMsg")
202endfun
203
204" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100205" s:NetrwInit: initializes variables if they haven't been defined {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100206" Loosely, varname = value.
207fun s:NetrwInit(varname,value)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100208" call Decho("varname<".a:varname."> value=".a:value,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100209 if !exists(a:varname)
210 if type(a:value) == 0
211 exe "let ".a:varname."=".a:value
Bram Moolenaarff034192013-04-24 18:51:19 +0200212 elseif type(a:value) == 1 && a:value =~ '^[{[]'
213 exe "let ".a:varname."=".a:value
Bram Moolenaar5c736222010-01-06 20:54:52 +0100214 elseif type(a:value) == 1
215 exe "let ".a:varname."="."'".a:value."'"
216 else
217 exe "let ".a:varname."=".a:value
218 endif
219 endif
220endfun
221
222" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000223" Netrw Constants: {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +0200224call s:NetrwInit("g:netrw_dirhistcnt",0)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000225if !exists("s:LONGLIST")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100226 call s:NetrwInit("s:THINLIST",0)
227 call s:NetrwInit("s:LONGLIST",1)
228 call s:NetrwInit("s:WIDELIST",2)
229 call s:NetrwInit("s:TREELIST",3)
230 call s:NetrwInit("s:MAXLIST" ,4)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000231endif
232
Damien7c754112024-08-15 21:58:57 +0200233let s:NOTE = 0
234let s:WARNING = 1
235let s:ERROR = 2
236call s:NetrwInit("g:netrw_errorlvl", s:NOTE)
237
Bram Moolenaar9964e462007-05-05 17:54:07 +0000238" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +0200239" Default option values: {{{2
240let g:netrw_localcopycmdopt = ""
241let g:netrw_localcopydircmdopt = ""
242let g:netrw_localmkdiropt = ""
243let g:netrw_localmovecmdopt = ""
Bram Moolenaar85850f32019-07-19 22:05:51 +0200244
245" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000246" Default values for netrw's global protocol variables {{{2
Damienb4d11642024-08-15 22:00:45 +0200247if exists("*popup_atcursor")
248\ && has("syntax")
249\ && exists("g:syntax_on")
250\ && has("mouse")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200251 call s:NetrwInit("g:netrw_use_errorwindow",2)
252else
253 call s:NetrwInit("g:netrw_use_errorwindow",1)
254endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200255
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000256if !exists("g:netrw_dav_cmd")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100257 if executable("cadaver")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000258 let g:netrw_dav_cmd = "cadaver"
Bram Moolenaar5c736222010-01-06 20:54:52 +0100259 elseif executable("curl")
260 let g:netrw_dav_cmd = "curl"
261 else
262 let g:netrw_dav_cmd = ""
263 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000265if !exists("g:netrw_fetch_cmd")
266 if executable("fetch")
267 let g:netrw_fetch_cmd = "fetch -o"
268 else
269 let g:netrw_fetch_cmd = ""
270 endif
271endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100272if !exists("g:netrw_file_cmd")
273 if executable("elinks")
274 call s:NetrwInit("g:netrw_file_cmd","elinks")
275 elseif executable("links")
276 call s:NetrwInit("g:netrw_file_cmd","links")
277 endif
278endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000279if !exists("g:netrw_ftp_cmd")
280 let g:netrw_ftp_cmd = "ftp"
281endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200282let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200283if !exists("g:netrw_ftp_options")
284 let g:netrw_ftp_options= "-i -n"
285endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000286if !exists("g:netrw_http_cmd")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100287 if executable("wget")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100288 let g:netrw_http_cmd = "wget"
289 call s:NetrwInit("g:netrw_http_xcmd","-q -O")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100290 elseif executable("curl")
291 let g:netrw_http_cmd = "curl"
292 call s:NetrwInit("g:netrw_http_xcmd","-L -o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200293 elseif executable("elinks")
294 let g:netrw_http_cmd = "elinks"
295 call s:NetrwInit("g:netrw_http_xcmd","-source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000296 elseif executable("fetch")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100297 let g:netrw_http_cmd = "fetch"
298 call s:NetrwInit("g:netrw_http_xcmd","-o")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200299 elseif executable("links")
300 let g:netrw_http_cmd = "links"
301 call s:NetrwInit("g:netrw_http_xcmd","-http.extra-header ".shellescape("Accept-Encoding: identity", 1)." -source >")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000302 else
303 let g:netrw_http_cmd = ""
304 endif
305endif
Bram Moolenaar8d043172014-01-23 14:24:41 +0100306call s:NetrwInit("g:netrw_http_put_cmd","curl -T")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100307call s:NetrwInit("g:netrw_keepj","keepj")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100308call s:NetrwInit("g:netrw_rcp_cmd" , "rcp")
309call s:NetrwInit("g:netrw_rsync_cmd", "rsync")
Bram Moolenaar85850f32019-07-19 22:05:51 +0200310call s:NetrwInit("g:netrw_rsync_sep", "/")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200311if !exists("g:netrw_scp_cmd")
Christian Brabandt43f2edc2024-05-13 20:56:43 +0200312 if executable("scp")
313 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
314 elseif executable("pscp")
Nir Lichtmance2ad9f2024-05-09 20:20:36 +0200315 call s:NetrwInit("g:netrw_scp_cmd", 'pscp -q')
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200316 else
317 call s:NetrwInit("g:netrw_scp_cmd" , "scp -q")
318 endif
319endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100320call s:NetrwInit("g:netrw_sftp_cmd" , "sftp")
321call s:NetrwInit("g:netrw_ssh_cmd" , "ssh")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000322
Nir Lichtman1e34b952024-05-08 19:19:34 +0200323if has("win32")
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000324 \ && exists("g:netrw_use_nt_rcp")
325 \ && g:netrw_use_nt_rcp
326 \ && executable( $SystemRoot .'/system32/rcp.exe')
327 let s:netrw_has_nt_rcp = 1
328 let s:netrw_rcpmode = '-b'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000329else
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000330 let s:netrw_has_nt_rcp = 0
331 let s:netrw_rcpmode = ''
332endif
333
334" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000335" Default values for netrw's global variables {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +0000336" Cygwin Detection ------- {{{3
337if !exists("g:netrw_cygwin")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200338 if has("win32unix") && &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
339 let g:netrw_cygwin= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +0000340 else
341 let g:netrw_cygwin= 0
342 endif
343endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000344" Default values - a-c ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100345call s:NetrwInit("g:netrw_alto" , &sb)
346call s:NetrwInit("g:netrw_altv" , &spr)
347call s:NetrwInit("g:netrw_banner" , 1)
348call s:NetrwInit("g:netrw_browse_split", 0)
Bram Moolenaar13600302014-05-22 18:26:40 +0200349call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100350call s:NetrwInit("g:netrw_chgwin" , -1)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200351call s:NetrwInit("g:netrw_clipboard" , 1)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100352call s:NetrwInit("g:netrw_compress" , "gzip")
353call s:NetrwInit("g:netrw_ctags" , "ctags")
Bram Moolenaaradc21822011-04-01 18:03:16 +0200354if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
355 call netrw#ErrorMsg(s:NOTE,'g:netrw_cursorline is deprecated; use g:netrw_cursor instead',77)
356 let g:netrw_cursor= g:netrw_cursorline
Bram Moolenaar446cb832008-06-24 21:56:24 +0000357endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200358call s:NetrwInit("g:netrw_cursor" , 2)
359let s:netrw_usercul = &cursorline
360let s:netrw_usercuc = &cursorcolumn
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200361"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
Bram Moolenaar8d043172014-01-23 14:24:41 +0100362call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000363" Default values - d-g ---------- {{{3
Bram Moolenaarff034192013-04-24 18:51:19 +0200364call s:NetrwInit("s:didstarstar",0)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200365call s:NetrwInit("g:netrw_dirhistcnt" , 0)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +0200366call s:NetrwInit("g:netrw_decompress" , '{ ".gz" : "gunzip", ".bz2" : "bunzip2", ".zip" : "unzip", ".tar" : "tar -xf", ".xz" : "unxz" }')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100367call s:NetrwInit("g:netrw_dirhistmax" , 10)
368call s:NetrwInit("g:netrw_fastbrowse" , 1)
369call 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 +0000370if !exists("g:netrw_ftp_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000371 if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
372 let g:netrw_ftp_list_cmd = "ls -lF"
373 let g:netrw_ftp_timelist_cmd = "ls -tlF"
374 let g:netrw_ftp_sizelist_cmd = "ls -slF"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000375 else
Bram Moolenaar9964e462007-05-05 17:54:07 +0000376 let g:netrw_ftp_list_cmd = "dir"
377 let g:netrw_ftp_timelist_cmd = "dir"
378 let g:netrw_ftp_sizelist_cmd = "dir"
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000379 endif
380endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100381call s:NetrwInit("g:netrw_ftpmode",'binary')
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000382" Default values - h-lh ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100383call s:NetrwInit("g:netrw_hide",1)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000384if !exists("g:netrw_ignorenetrc")
385 if &shell =~ '\c\<\%(cmd\|4nt\)\.exe$'
386 let g:netrw_ignorenetrc= 1
387 else
388 let g:netrw_ignorenetrc= 0
389 endif
390endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100391call s:NetrwInit("g:netrw_keepdir",1)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000392if !exists("g:netrw_list_cmd")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000393 if g:netrw_scp_cmd =~ '^pscp' && executable("pscp")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100394 if exists("g:netrw_list_cmd_options")
395 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME: ".g:netrw_list_cmd_options
396 else
397 let g:netrw_list_cmd= g:netrw_scp_cmd." -ls USEPORT HOSTNAME:"
398 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000399 elseif executable(g:netrw_ssh_cmd)
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200400 " provide a scp-based default listing command
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100401 if exists("g:netrw_list_cmd_options")
402 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa ".g:netrw_list_cmd_options
403 else
404 let g:netrw_list_cmd= g:netrw_ssh_cmd." USEPORT HOSTNAME ls -FLa"
405 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000406 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100407" call Decho(g:netrw_ssh_cmd." is not executable",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000408 let g:netrw_list_cmd= ""
409 endif
410endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100411call s:NetrwInit("g:netrw_list_hide","")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000412" Default values - lh-lz ---------- {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200413if exists("g:netrw_local_copycmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200414 let g:netrw_localcopycmd= g:netrw_local_copycmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200415 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_copycmd is deprecated in favor of g:netrw_localcopycmd",84)
416endif
Bram Moolenaar97d62492012-11-15 21:28:22 +0100417if !exists("g:netrw_localcmdshell")
418 let g:netrw_localcmdshell= ""
419endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000420if !exists("g:netrw_localcopycmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200421 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000422 if g:netrw_cygwin
423 let g:netrw_localcopycmd= "cp"
424 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000425 let g:netrw_localcopycmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200426 let g:netrw_localcopycmdopt= " /c copy"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000427 endif
428 elseif has("unix") || has("macunix")
429 let g:netrw_localcopycmd= "cp"
430 else
431 let g:netrw_localcopycmd= ""
432 endif
433endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100434if !exists("g:netrw_localcopydircmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200435 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100436 if g:netrw_cygwin
Bram Moolenaar85850f32019-07-19 22:05:51 +0200437 let g:netrw_localcopydircmd = "cp"
438 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100439 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000440 let g:netrw_localcopydircmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200441 let g:netrw_localcopydircmdopt= " /c xcopy /e /c /h /i /k"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100442 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200443 elseif has("unix")
444 let g:netrw_localcopydircmd = "cp"
445 let g:netrw_localcopydircmdopt= " -R"
446 elseif has("macunix")
447 let g:netrw_localcopydircmd = "cp"
448 let g:netrw_localcopydircmdopt= " -R"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100449 else
Bram Moolenaar85850f32019-07-19 22:05:51 +0200450 let g:netrw_localcopydircmd= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100451 endif
452endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200453if exists("g:netrw_local_mkdir")
Bram Moolenaar97d62492012-11-15 21:28:22 +0100454 let g:netrw_localmkdir= g:netrw_local_mkdir
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200455 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_mkdir is deprecated in favor of g:netrw_localmkdir",87)
456endif
Nir Lichtman1e34b952024-05-08 19:19:34 +0200457if has("win32")
Bram Moolenaar13600302014-05-22 18:26:40 +0200458 if g:netrw_cygwin
459 call s:NetrwInit("g:netrw_localmkdir","mkdir")
460 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000461 let g:netrw_localmkdir = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200462 let g:netrw_localmkdiropt= " /c mkdir"
Bram Moolenaar13600302014-05-22 18:26:40 +0200463 endif
464else
465 call s:NetrwInit("g:netrw_localmkdir","mkdir")
466endif
Bram Moolenaar15146672011-10-20 22:22:38 +0200467call s:NetrwInit("g:netrw_remote_mkdir","mkdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200468if exists("g:netrw_local_movecmd")
Bram Moolenaarff034192013-04-24 18:51:19 +0200469 let g:netrw_localmovecmd= g:netrw_local_movecmd
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200470 call netrw#ErrorMsg(s:NOTE,"g:netrw_local_movecmd is deprecated in favor of g:netrw_localmovecmd",88)
471endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000472if !exists("g:netrw_localmovecmd")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200473 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000474 if g:netrw_cygwin
475 let g:netrw_localmovecmd= "mv"
476 else
Christian Brabandtcb0c1132023-11-21 18:48:16 +0000477 let g:netrw_localmovecmd = expand("$COMSPEC", v:true)
Bram Moolenaar85850f32019-07-19 22:05:51 +0200478 let g:netrw_localmovecmdopt= " /c move"
Bram Moolenaar446cb832008-06-24 21:56:24 +0000479 endif
480 elseif has("unix") || has("macunix")
481 let g:netrw_localmovecmd= "mv"
482 else
483 let g:netrw_localmovecmd= ""
484 endif
485endif
Bram Moolenaar29634562020-01-09 21:46:04 +0100486" following serves as an example for how to insert a version&patch specific test
487"if v:version < 704 || (v:version == 704 && !has("patch1107"))
488"endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100489call s:NetrwInit("g:netrw_liststyle" , s:THINLIST)
490" sanity checks
Bram Moolenaar9964e462007-05-05 17:54:07 +0000491if g:netrw_liststyle < 0 || g:netrw_liststyle >= s:MAXLIST
Bram Moolenaar9964e462007-05-05 17:54:07 +0000492 let g:netrw_liststyle= s:THINLIST
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000493endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000494if g:netrw_liststyle == s:LONGLIST && g:netrw_scp_cmd !~ '^pscp'
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000495 let g:netrw_list_cmd= g:netrw_list_cmd." -l"
496endif
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000497" Default values - m-r ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100498call s:NetrwInit("g:netrw_markfileesc" , '*./[\~')
499call s:NetrwInit("g:netrw_maxfilenamelen", 32)
500call s:NetrwInit("g:netrw_menu" , 1)
501call s:NetrwInit("g:netrw_mkdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mkdir")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200502call s:NetrwInit("g:netrw_mousemaps" , (exists("+mouse") && &mouse =~# '[anh]'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100503call s:NetrwInit("g:netrw_retmap" , 0)
504if has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin)
505 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Nir Lichtman1e34b952024-05-08 19:19:34 +0200506elseif has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100507 call s:NetrwInit("g:netrw_chgperm" , "cacls FILENAME /e /p PERM")
508else
509 call s:NetrwInit("g:netrw_chgperm" , "chmod PERM FILENAME")
Bram Moolenaar446cb832008-06-24 21:56:24 +0000510endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100511call s:NetrwInit("g:netrw_preview" , 0)
512call s:NetrwInit("g:netrw_scpport" , "-P")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100513call s:NetrwInit("g:netrw_servername" , "NETRWSERVER")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100514call s:NetrwInit("g:netrw_sshport" , "-p")
515call s:NetrwInit("g:netrw_rename_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME mv")
516call s:NetrwInit("g:netrw_rm_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm")
517call s:NetrwInit("g:netrw_rmdir_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rmdir")
Bram Moolenaara6878372014-03-22 21:02:50 +0100518call s:NetrwInit("g:netrw_rmf_cmd" , g:netrw_ssh_cmd." USEPORT HOSTNAME rm -f ")
519" Default values - q-s ---------- {{{3
520call s:NetrwInit("g:netrw_quickhelp",0)
521let s:QuickHelp= ["-:go up dir D:delete R:rename s:sort-by x:special",
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100522 \ "(create new) %:file d:directory",
523 \ "(windows split&open) o:horz v:vert p:preview",
524 \ "i:style qf:file info O:obtain r:reverse",
525 \ "(marks) mf:mark file mt:set target mm:move mc:copy",
526 \ "(bookmarks) mb:make mB:delete qb:list gb:go to",
527 \ "(history) qb:list u:go up U:go down",
528 \ "(targets) mt:target Tb:use bookmark Th:use history"]
Bram Moolenaar5c736222010-01-06 20:54:52 +0100529" g:netrw_sepchr: picking a character that doesn't appear in filenames that can be used to separate priority from filename
530call s:NetrwInit("g:netrw_sepchr" , (&enc == "euc-jp")? "\<Char-0x01>" : "\<Char-0xff>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100531if !exists("g:netrw_keepj") || g:netrw_keepj == "keepj"
532 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil keepj " : "keepj ")
533else
534 call s:NetrwInit("s:netrw_silentxfer" , (exists("g:netrw_silent") && g:netrw_silent != 0)? "sil " : " ")
535endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100536call s:NetrwInit("g:netrw_sort_by" , "name") " alternatives: date , size
537call s:NetrwInit("g:netrw_sort_options" , "")
538call s:NetrwInit("g:netrw_sort_direction", "normal") " alternative: reverse (z y x ...)
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000539if !exists("g:netrw_sort_sequence")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100540 if has("unix")
Bram Moolenaar15146672011-10-20 22:22:38 +0200541 let g:netrw_sort_sequence= '[\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100542 else
543 let g:netrw_sort_sequence= '[\/]$,\.h$,\.c$,\.cpp$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000544 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000545endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100546call s:NetrwInit("g:netrw_special_syntax" , 0)
547call s:NetrwInit("g:netrw_ssh_browse_reject", '^total\s\+\d\+$')
Bram Moolenaara6878372014-03-22 21:02:50 +0100548call s:NetrwInit("g:netrw_use_noswf" , 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +0100549call s:NetrwInit("g:netrw_sizestyle" ,"b")
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000550" Default values - t-w ---------- {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100551call s:NetrwInit("g:netrw_timefmt","%c")
Bram Moolenaarff034192013-04-24 18:51:19 +0200552if !exists("g:netrw_xstrlen")
553 if exists("g:Align_xstrlen")
554 let g:netrw_xstrlen= g:Align_xstrlen
555 elseif exists("g:drawit_xstrlen")
556 let g:netrw_xstrlen= g:drawit_xstrlen
557 elseif &enc == "latin1" || !has("multi_byte")
558 let g:netrw_xstrlen= 0
559 else
560 let g:netrw_xstrlen= 1
561 endif
562endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100563call s:NetrwInit("g:NetrwTopLvlMenu","Netrw.")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200564call s:NetrwInit("g:netrw_winsize",50)
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100565call s:NetrwInit("g:netrw_wiw",1)
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200566if g:netrw_winsize > 100|let g:netrw_winsize= 100|endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +0000567" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000568" Default values for netrw's script variables: {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +0100569call s:NetrwInit("g:netrw_fname_escape",' ?&;%')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200570if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +0200571 call s:NetrwInit("g:netrw_glob_escape",'*?`{[]$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200572else
Bram Moolenaarff034192013-04-24 18:51:19 +0200573 call s:NetrwInit("g:netrw_glob_escape",'*[]?`{~$\')
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200574endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200575call s:NetrwInit("g:netrw_menu_escape",'.&? \')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100576call s:NetrwInit("g:netrw_tmpfile_escape",' &;')
577call s:NetrwInit("s:netrw_map_escape","<|\n\r\\\<C-V>\"")
Bram Moolenaara6878372014-03-22 21:02:50 +0100578if has("gui_running") && (&enc == 'utf-8' || &enc == 'utf-16' || &enc == 'ucs-4')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100579 let s:treedepthstring= "│ "
580else
581 let s:treedepthstring= "| "
582endif
Bram Moolenaar85850f32019-07-19 22:05:51 +0200583call s:NetrwInit("s:netrw_posn",'{}')
Bram Moolenaar8299df92004-07-10 09:47:34 +0000584
585" BufEnter event ignored by decho when following variable is true
586" Has a side effect that doau BufReadPost doesn't work, so
587" files read by network transfer aren't appropriately highlighted.
588"let g:decho_bufenter = 1 "Decho
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589
Bram Moolenaaradc21822011-04-01 18:03:16 +0200590" ======================
591" Netrw Initialization: {{{1
592" ======================
Bram Moolenaar15146672011-10-20 22:22:38 +0200593if 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 +0100594" call Decho("installed beval events",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100595 let &l:bexpr = "netrw#BalloonHelp()"
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200596" call Decho("&l:bexpr<".&l:bexpr."> buf#".bufnr())
Bram Moolenaara6878372014-03-22 21:02:50 +0100597 au FileType netrw setl beval
Bram Moolenaar8d043172014-01-23 14:24:41 +0100598 au WinLeave * if &ft == "netrw" && exists("s:initbeval")|let &beval= s:initbeval|endif
599 au VimEnter * let s:initbeval= &beval
600"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100601" if v:version < 700 | call Decho("did not install beval events: v:version=".v:version." < 700","~".expand("<slnum>")) | endif
602" if !has("balloon_eval") | call Decho("did not install beval events: does not have balloon_eval","~".expand("<slnum>")) | endif
603" if exists("s:initbeval") | call Decho("did not install beval events: s:initbeval exists","~".expand("<slnum>")) | endif
604" if exists("g:netrw_nobeval") | call Decho("did not install beval events: g:netrw_nobeval exists","~".expand("<slnum>")) | endif
605" if !has("syntax") | call Decho("did not install beval events: does not have syntax highlighting","~".expand("<slnum>")) | endif
606" 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 +0200607endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +0200608au WinEnter * if &ft == "netrw"|call s:NetrwInsureWinVars()|endif
Bram Moolenaaradc21822011-04-01 18:03:16 +0200609
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200610if g:netrw_keepj =~# "keepj"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100611 com! -nargs=* NetrwKeepj keepj <args>
612else
613 let g:netrw_keepj= ""
614 com! -nargs=* NetrwKeepj <args>
615endif
616
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +0000617" ==============================
618" Netrw Utility Functions: {{{1
619" ==============================
620
Bram Moolenaaradc21822011-04-01 18:03:16 +0200621" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +0100622" netrw#BalloonHelp: {{{2
Bram Moolenaar8d043172014-01-23 14:24:41 +0100623if v:version >= 700 && has("balloon_eval") && has("syntax") && exists("g:syntax_on") && !exists("g:netrw_nobeval")
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100624" call Decho("loading netrw#BalloonHelp()",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100625 fun! netrw#BalloonHelp()
Bram Moolenaar8d043172014-01-23 14:24:41 +0100626 if &ft != "netrw"
627 return ""
628 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +0200629 if exists("s:popuperr_id") && popup_getpos(s:popuperr_id) != {}
630 " popup error window is still showing
631 " s:pouperr_id and s:popuperr_text are set up in netrw#ErrorMsg()
632 if exists("s:popuperr_text") && s:popuperr_text != "" && v:beval_text != s:popuperr_text
633 " text under mouse hasn't changed; only close window when it changes
634 call popup_close(s:popuperr_id)
635 unlet s:popuperr_text
636 else
637 let s:popuperr_text= v:beval_text
638 endif
639 let mesg= ""
640 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 +0100641 let mesg= ""
642 elseif v:beval_text == "Netrw" || v:beval_text == "Directory" || v:beval_text == "Listing"
643 let mesg = "i: thin-long-wide-tree gh: quick hide/unhide of dot-files qf: quick file info %:open new file"
644 elseif getline(v:beval_lnum) =~ '^"\s*/'
645 let mesg = "<cr>: edit/enter o: edit/enter in horiz window t: edit/enter in new tab v:edit/enter in vert window"
646 elseif v:beval_text == "Sorted" || v:beval_text == "by"
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100647 let mesg = 's: sort by name, time, file size, extension r: reverse sorting order mt: mark target'
Bram Moolenaar8d043172014-01-23 14:24:41 +0100648 elseif v:beval_text == "Sort" || v:beval_text == "sequence"
649 let mesg = "S: edit sorting sequence"
650 elseif v:beval_text == "Hiding" || v:beval_text == "Showing"
651 let mesg = "a: hiding-showing-all ctrl-h: editing hiding list mh: hide/show by suffix"
652 elseif v:beval_text == "Quick" || v:beval_text == "Help"
653 let mesg = "Help: press <F1>"
654 elseif v:beval_text == "Copy/Move" || v:beval_text == "Tgt"
655 let mesg = "mt: mark target mc: copy marked file to target mm: move marked file to target"
656 else
657 let mesg= ""
658 endif
659 return mesg
660 endfun
661"else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100662" if v:version < 700 |call Decho("did not load netrw#BalloonHelp(): vim version ".v:version." < 700 -","~".expand("<slnum>"))|endif
663" if !has("balloon_eval") |call Decho("did not load netrw#BalloonHelp(): does not have balloon eval","~".expand("<slnum>")) |endif
664" if !has("syntax") |call Decho("did not load netrw#BalloonHelp(): syntax disabled","~".expand("<slnum>")) |endif
665" if !exists("g:syntax_on") |call Decho("did not load netrw#BalloonHelp(): g:syntax_on n/a","~".expand("<slnum>")) |endif
666" 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 +0200667endif
668
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669" ------------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +0200670" netrw#Explore: launch the local browser in the directory of the current file {{{2
671" indx: == -1: Nexplore
672" == -2: Pexplore
673" == +: this is overloaded:
674" * If Nexplore/Pexplore is in use, then this refers to the
675" indx'th item in the w:netrw_explore_list[] of items which
676" matched the */pattern **/pattern *//pattern **//pattern
677" * If Hexplore or Vexplore, then this will override
678" g:netrw_winsize to specify the qty of rows or columns the
679" newly split window should have.
Bram Moolenaar8d043172014-01-23 14:24:41 +0100680" 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 +0200681" dosplit==1: the window will be split before running the local browser
682" style == 0: Explore style == 1: Explore!
683" == 2: Hexplore style == 3: Hexplore!
684" == 4: Vexplore style == 5: Vexplore!
685" == 6: Texplore
686fun! netrw#Explore(indx,dosplit,style,...)
Bram Moolenaarff034192013-04-24 18:51:19 +0200687 if !exists("b:netrw_curdir")
688 let b:netrw_curdir= getcwd()
Bram Moolenaarff034192013-04-24 18:51:19 +0200689 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100690
691 " record current file for Rexplore's benefit
692 if &ft != "netrw"
693 let w:netrw_rexfile= expand("%:p")
694 endif
695
696 " record current directory
Bram Moolenaarff034192013-04-24 18:51:19 +0200697 let curdir = simplify(b:netrw_curdir)
698 let curfiledir = substitute(expand("%:p"),'^\(.*[/\\]\)[^/\\]*$','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200699 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200700 let curdir= substitute(curdir,'\','/','g')
701 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100702
703 " using completion, directories with spaces in their names (thanks, Bill Gates, for a truly dumb idea)
704 " will end up with backslashes here. Solution: strip off backslashes that precede white space and
705 " try Explore again.
706 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100707 if a:1 =~ "\\\s" && !filereadable(s:NetrwFile(a:1)) && !isdirectory(s:NetrwFile(a:1))
Damien9d57ea52024-07-22 20:23:48 +0200708 let a1 = substitute(a:1, '\\\(\s\)', '\1', 'g')
709 if a1 != a:1
710 call netrw#Explore(a:indx, a:dosplit, a:style, a1)
711 return
712 endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100713 endif
714 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200715
716 " save registers
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200717 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +0100718" call Decho("(netrw#Explore) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +0100719 sil! let keepregstar = @*
720 sil! let keepregplus = @+
721 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200722 sil! let keepregslash= @/
723
Bram Moolenaar8d043172014-01-23 14:24:41 +0100724 " if dosplit
725 " -or- file has been modified AND file not hidden when abandoned
726 " -or- Texplore used
727 if a:dosplit || (&modified && &hidden == 0 && &bufhidden != "hide") || a:style == 6
Bram Moolenaarff034192013-04-24 18:51:19 +0200728 call s:SaveWinVars()
729 let winsz= g:netrw_winsize
730 if a:indx > 0
731 let winsz= a:indx
732 endif
733
734 if a:style == 0 " Explore, Sexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200735 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200736 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200737 exe "noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200738
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200739 elseif a:style == 1 " Explore!, Sexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200740 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200741 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200742 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200743
744 elseif a:style == 2 " Hexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200745 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200746 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200747 exe "keepalt noswapfile ".(g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200748
749 elseif a:style == 3 " Hexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200750 let winsz= (winsz > 0)? (winsz*winheight(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200751 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200752 exe "keepalt noswapfile ".(!g:netrw_alto ? "below " : "above ").winsz."wincmd s"
Bram Moolenaarff034192013-04-24 18:51:19 +0200753
754 elseif a:style == 4 " Vexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200755 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200756 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200757 exe "keepalt noswapfile ".(g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200758
759 elseif a:style == 5 " Vexplore!
Bram Moolenaarff034192013-04-24 18:51:19 +0200760 let winsz= (winsz > 0)? (winsz*winwidth(0))/100 : -winsz
Bram Moolenaar13600302014-05-22 18:26:40 +0200761 if winsz == 0|let winsz= ""|endif
Ivan Shapovalovc527d902024-08-02 19:43:12 +0200762 exe "keepalt noswapfile ".(!g:netrw_altv ? "rightbelow " : "leftabove ").winsz."wincmd v"
Bram Moolenaarff034192013-04-24 18:51:19 +0200763
764 elseif a:style == 6 " Texplore
765 call s:SaveBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200766 exe "keepalt tabnew ".fnameescape(curdir)
767 call s:RestoreBufVars()
768 endif
769 call s:RestoreWinVars()
Bram Moolenaarff034192013-04-24 18:51:19 +0200770 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100771 NetrwKeepj norm! 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200772
773 if a:0 > 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200774 if a:1 =~ '^\~' && (has("unix") || (exists("g:netrw_cygwin") && g:netrw_cygwin))
Bram Moolenaarff034192013-04-24 18:51:19 +0200775 let dirname= simplify(substitute(a:1,'\~',expand("$HOME"),''))
Bram Moolenaarff034192013-04-24 18:51:19 +0200776 elseif a:1 == '.'
Bram Moolenaarff034192013-04-24 18:51:19 +0200777 let dirname= simplify(exists("b:netrw_curdir")? b:netrw_curdir : getcwd())
778 if dirname !~ '/$'
779 let dirname= dirname."/"
780 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200781 elseif a:1 =~ '\$'
Bram Moolenaarff034192013-04-24 18:51:19 +0200782 let dirname= simplify(expand(a:1))
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200783 elseif a:1 !~ '^\*\{1,2}/' && a:1 !~ '^\a\{3,}://'
Bram Moolenaarff034192013-04-24 18:51:19 +0200784 let dirname= simplify(a:1)
Bram Moolenaarff034192013-04-24 18:51:19 +0200785 else
Bram Moolenaarff034192013-04-24 18:51:19 +0200786 let dirname= a:1
787 endif
788 else
789 " clear explore
Bram Moolenaarff034192013-04-24 18:51:19 +0200790 call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200791 return
792 endif
793
Bram Moolenaarff034192013-04-24 18:51:19 +0200794 if dirname =~ '\.\./\=$'
795 let dirname= simplify(fnamemodify(dirname,':p:h'))
796 elseif dirname =~ '\.\.' || dirname == '.'
797 let dirname= simplify(fnamemodify(dirname,':p'))
798 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200799
800 if dirname =~ '^\*//'
801 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200802 let pattern= substitute(dirname,'^\*//\(.*\)$','\1','')
803 let starpat= 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200804 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
805
806 elseif dirname =~ '^\*\*//'
807 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200808 let pattern= substitute(dirname,'^\*\*//','','')
809 let starpat= 2
Bram Moolenaarff034192013-04-24 18:51:19 +0200810
811 elseif dirname =~ '/\*\*/'
812 " handle .../**/.../filepat
Bram Moolenaarff034192013-04-24 18:51:19 +0200813 let prefixdir= substitute(dirname,'^\(.\{-}\)\*\*.*$','\1','')
Nir Lichtman1e34b952024-05-08 19:19:34 +0200814 if prefixdir =~ '^/' || (prefixdir =~ '^\a:/' && has("win32"))
Bram Moolenaarff034192013-04-24 18:51:19 +0200815 let b:netrw_curdir = prefixdir
816 else
817 let b:netrw_curdir= getcwd().'/'.prefixdir
818 endif
819 let dirname= substitute(dirname,'^.\{-}\(\*\*/.*\)$','\1','')
820 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200821
822 elseif dirname =~ '^\*/'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200823 " case starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200824 let starpat= 3
Bram Moolenaarff034192013-04-24 18:51:19 +0200825
826 elseif dirname=~ '^\*\*/'
827 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
828 let starpat= 4
Bram Moolenaarff034192013-04-24 18:51:19 +0200829
830 else
831 let starpat= 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200832 endif
833
834 if starpat == 0 && a:indx >= 0
835 " [Explore Hexplore Vexplore Sexplore] [dirname]
Bram Moolenaarff034192013-04-24 18:51:19 +0200836 if dirname == ""
837 let dirname= curfiledir
Bram Moolenaarff034192013-04-24 18:51:19 +0200838 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +0200839 if dirname =~# '^scp://' || dirname =~ '^ftp://'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200840 call netrw#Nread(2,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200841 else
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200842 if dirname == ""
843 let dirname= getcwd()
Nir Lichtman1e34b952024-05-08 19:19:34 +0200844 elseif has("win32") && !g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +0100845 " Windows : check for a drive specifier, or else for a remote share name ('\\Foo' or '//Foo',
Bram Moolenaara6878372014-03-22 21:02:50 +0100846 " depending on whether backslashes have been converted to forward slashes by earlier code).
847 if dirname !~ '^[a-zA-Z]:' && dirname !~ '^\\\\\w\+' && dirname !~ '^//\w\+'
Bram Moolenaare6ae6222013-05-21 21:01:10 +0200848 let dirname= b:netrw_curdir."/".dirname
849 endif
850 elseif dirname !~ '^/'
851 let dirname= b:netrw_curdir."/".dirname
852 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200853 call netrw#LocalBrowseCheck(dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200854 endif
855 if exists("w:netrw_bannercnt")
856 " done to handle P08-Ingelrest. :Explore will _Always_ go to the line just after the banner.
857 " If one wants to return the same place in the netrw window, use :Rex instead.
858 exe w:netrw_bannercnt
859 endif
860
Bram Moolenaarff034192013-04-24 18:51:19 +0200861
862 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
863 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
864 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
865 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
866 elseif a:indx <= 0
867 " Nexplore, Pexplore, Explore: handle starpat
Bram Moolenaarff034192013-04-24 18:51:19 +0200868 if !mapcheck("<s-up>","n") && !mapcheck("<s-down>","n") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +0200869 let s:didstarstar= 1
870 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
871 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
872 endif
873
874 if has("path_extra")
Bram Moolenaarff034192013-04-24 18:51:19 +0200875 if !exists("w:netrw_explore_indx")
876 let w:netrw_explore_indx= 0
877 endif
878
879 let indx = a:indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200880
881 if indx == -1
882 " Nexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200883 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100884 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 +0200885 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100886 if @* != keepregstar | sil! let @* = keepregstar | endif
887 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100888 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200889 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200890 return
891 endif
892 let indx= w:netrw_explore_indx
893 if indx < 0 | let indx= 0 | endif
894 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
895 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200896 while indx < w:netrw_explore_listlen && curfile == w:netrw_explore_list[indx]
897 let indx= indx + 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200898 endwhile
899 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200900
901 elseif indx == -2
902 " Pexplore
Bram Moolenaarff034192013-04-24 18:51:19 +0200903 if !exists("w:netrw_explore_list") " sanity check
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100904 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 +0200905 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100906 if @* != keepregstar | sil! let @* = keepregstar | endif
907 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100908 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200909 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200910 return
911 endif
912 let indx= w:netrw_explore_indx
913 if indx < 0 | let indx= 0 | endif
914 if indx >= w:netrw_explore_listlen | let indx= w:netrw_explore_listlen - 1 | endif
915 let curfile= w:netrw_explore_list[indx]
Bram Moolenaarff034192013-04-24 18:51:19 +0200916 while indx >= 0 && curfile == w:netrw_explore_list[indx]
917 let indx= indx - 1
Bram Moolenaarff034192013-04-24 18:51:19 +0200918 endwhile
919 if indx < 0 | let indx= 0 | endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200920
921 else
922 " Explore -- initialize
923 " build list of files to Explore with Nexplore/Pexplore
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100924 NetrwKeepj keepalt call s:NetrwClearExplore()
Bram Moolenaarff034192013-04-24 18:51:19 +0200925 let w:netrw_explore_indx= 0
926 if !exists("b:netrw_curdir")
927 let b:netrw_curdir= getcwd()
928 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200929
930 " switch on starpat to build the w:netrw_explore_list of files
931 if starpat == 1
932 " starpat=1: Explore *//pattern (current directory only search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200933 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100934 exe "NetrwKeepj noautocmd vimgrep /".pattern."/gj ".fnameescape(b:netrw_curdir)."/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200935 catch /^Vim\%((\a\+)\)\=:E480/
936 keepalt call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pattern.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +0200937 return
938 endtry
939 let w:netrw_explore_list = s:NetrwExploreListUniq(map(getqflist(),'bufname(v:val.bufnr)'))
940 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
941
942 elseif starpat == 2
943 " starpat=2: Explore **//pattern (recursive descent search for files containing pattern)
Bram Moolenaarff034192013-04-24 18:51:19 +0200944 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100945 exe "sil NetrwKeepj noautocmd keepalt vimgrep /".pattern."/gj "."**/*"
Bram Moolenaarff034192013-04-24 18:51:19 +0200946 catch /^Vim\%((\a\+)\)\=:E480/
947 keepalt call netrw#ErrorMsg(s:WARNING,'no files matched pattern<'.pattern.'>',45)
948 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200949 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100950 if @* != keepregstar | sil! let @* = keepregstar | endif
951 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100952 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200953 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200954 return
955 endtry
956 let s:netrw_curdir = b:netrw_curdir
957 let w:netrw_explore_list = getqflist()
958 let w:netrw_explore_list = s:NetrwExploreListUniq(map(w:netrw_explore_list,'s:netrw_curdir."/".bufname(v:val.bufnr)'))
959 if &hls | let keepregslash= s:ExplorePatHls(pattern) | endif
960
961 elseif starpat == 3
962 " starpat=3: Explore */filepat (search in current directory for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200963 let filepat= substitute(dirname,'^\*/','','')
964 let filepat= substitute(filepat,'^[%#<]','\\&','')
Bram Moolenaarff034192013-04-24 18:51:19 +0200965 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".filepat),'\n'))
966 if &hls | let keepregslash= s:ExplorePatHls(filepat) | endif
967
968 elseif starpat == 4
969 " starpat=4: Explore **/filepat (recursive descent search for filenames matching filepat)
Bram Moolenaarff034192013-04-24 18:51:19 +0200970 let w:netrw_explore_list= s:NetrwExploreListUniq(split(expand(b:netrw_curdir."/".dirname),'\n'))
971 if &hls | let keepregslash= s:ExplorePatHls(dirname) | endif
972 endif " switch on starpat to build w:netrw_explore_list
973
974 let w:netrw_explore_listlen = len(w:netrw_explore_list)
Bram Moolenaarff034192013-04-24 18:51:19 +0200975
976 if w:netrw_explore_listlen == 0 || (w:netrw_explore_listlen == 1 && w:netrw_explore_list[0] =~ '\*\*\/')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100977 keepalt NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no files matched",42)
Bram Moolenaar89a9c152021-08-29 21:55:35 +0200978 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +0100979 if @* != keepregstar | sil! let @* = keepregstar | endif
980 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +0100981 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200982 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +0200983 return
984 endif
985 endif " if indx ... endif
986
987 " NetrwStatusLine support - for exploring support
988 let w:netrw_explore_indx= indx
Bram Moolenaarff034192013-04-24 18:51:19 +0200989
990 " wrap the indx around, but issue a note
991 if indx >= w:netrw_explore_listlen || indx < 0
Bram Moolenaarff034192013-04-24 18:51:19 +0200992 let indx = (indx < 0)? ( w:netrw_explore_listlen - 1 ) : 0
993 let w:netrw_explore_indx= indx
Bram Moolenaar8feef4f2015-01-07 16:57:10 +0100994 keepalt NetrwKeepj call netrw#ErrorMsg(s:NOTE,"no more files match Explore pattern",43)
Bram Moolenaarff034192013-04-24 18:51:19 +0200995 endif
996
997 exe "let dirfile= w:netrw_explore_list[".indx."]"
Bram Moolenaarff034192013-04-24 18:51:19 +0200998 let newdir= substitute(dirfile,'/[^/]*$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +0200999
Bram Moolenaarff034192013-04-24 18:51:19 +02001000 call netrw#LocalBrowseCheck(newdir)
1001 if !exists("w:netrw_liststyle")
1002 let w:netrw_liststyle= g:netrw_liststyle
1003 endif
1004 if w:netrw_liststyle == s:THINLIST || w:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001005 keepalt NetrwKeepj call search('^'.substitute(dirfile,"^.*/","","").'\>',"W")
Bram Moolenaarff034192013-04-24 18:51:19 +02001006 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001007 keepalt NetrwKeepj call search('\<'.substitute(dirfile,"^.*/","","").'\>',"w")
Bram Moolenaarff034192013-04-24 18:51:19 +02001008 endif
1009 let w:netrw_explore_mtchcnt = indx + 1
1010 let w:netrw_explore_bufnr = bufnr("%")
1011 let w:netrw_explore_line = line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001012 keepalt NetrwKeepj call s:SetupNetrwStatusLine('%f %h%m%r%=%9*%{NetrwStatusLine()}')
Bram Moolenaarff034192013-04-24 18:51:19 +02001013
1014 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001015 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001016 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 +02001017 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001018 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001019 if @* != keepregstar | sil! let @* = keepregstar | endif
1020 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001021 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001022 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001023 return
1024 endif
1025
1026 else
Bram Moolenaarff034192013-04-24 18:51:19 +02001027 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && dirname =~ '/'
1028 sil! unlet w:netrw_treedict
1029 sil! unlet w:netrw_treetop
1030 endif
1031 let newdir= dirname
1032 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001033 NetrwKeepj call netrw#LocalBrowseCheck(getcwd())
Bram Moolenaarff034192013-04-24 18:51:19 +02001034 else
Tom Benham64a536d2024-11-07 21:15:03 +01001035 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,newdir,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02001036 endif
1037 endif
1038
1039 " visual display of **/ **// */ Exploration files
Bram Moolenaarff034192013-04-24 18:51:19 +02001040 if exists("w:netrw_explore_indx") && exists("b:netrw_curdir")
Bram Moolenaarff034192013-04-24 18:51:19 +02001041 if !exists("s:explore_prvdir") || s:explore_prvdir != b:netrw_curdir
Bram Moolenaar8d043172014-01-23 14:24:41 +01001042 " only update match list when current directory isn't the same as before
Bram Moolenaarff034192013-04-24 18:51:19 +02001043 let s:explore_prvdir = b:netrw_curdir
1044 let s:explore_match = ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01001045 let dirlen = strlen(b:netrw_curdir)
Bram Moolenaarff034192013-04-24 18:51:19 +02001046 if b:netrw_curdir !~ '/$'
1047 let dirlen= dirlen + 1
1048 endif
1049 let prvfname= ""
1050 for fname in w:netrw_explore_list
Bram Moolenaarff034192013-04-24 18:51:19 +02001051 if fname =~ '^'.b:netrw_curdir
1052 if s:explore_match == ""
1053 let s:explore_match= '\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1054 else
1055 let s:explore_match= s:explore_match.'\|\<'.escape(strpart(fname,dirlen),g:netrw_markfileesc).'\>'
1056 endif
1057 elseif fname !~ '^/' && fname != prvfname
1058 if s:explore_match == ""
1059 let s:explore_match= '\<'.escape(fname,g:netrw_markfileesc).'\>'
1060 else
1061 let s:explore_match= s:explore_match.'\|\<'.escape(fname,g:netrw_markfileesc).'\>'
1062 endif
1063 endif
1064 let prvfname= fname
1065 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02001066 if has("syntax") && exists("g:syntax_on") && g:syntax_on
1067 exe "2match netrwMarkFile /".s:explore_match."/"
1068 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001069 endif
1070 echo "<s-up>==Pexplore <s-down>==Nexplore"
1071 else
1072 2match none
1073 if exists("s:explore_match") | unlet s:explore_match | endif
1074 if exists("s:explore_prvdir") | unlet s:explore_prvdir | endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001075 endif
1076
Bram Moolenaara6878372014-03-22 21:02:50 +01001077 " since Explore may be used to initialize netrw's browser,
1078 " there's no danger of a late FocusGained event on initialization.
1079 " Consequently, set s:netrw_events to 2.
1080 let s:netrw_events= 2
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001081 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01001082 if @* != keepregstar | sil! let @* = keepregstar | endif
1083 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001084 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02001085 sil! let @/ = keepregslash
Bram Moolenaarff034192013-04-24 18:51:19 +02001086endfun
1087
1088" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01001089" netrw#Lexplore: toggle Explorer window, keeping it on the left of the current tab {{{2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001090" Uses g:netrw_chgwin : specifies the window where Lexplore files are to be opened
1091" t:netrw_lexposn : winsaveview() output (used on Lexplore window)
1092" t:netrw_lexbufnr: the buffer number of the Lexplore buffer (internal to this function)
1093" s:lexplore_win : window number of Lexplore window (serves to indicate which window is a Lexplore window)
1094" w:lexplore_buf : buffer number of Lexplore window (serves to indicate which window is a Lexplore window)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001095fun! netrw#Lexplore(count,rightside,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001096" call Dfunc("netrw#Lexplore(count=".a:count." rightside=".a:rightside.",...) a:0=".a:0." ft=".&ft)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001097 let curwin= winnr()
1098
Bram Moolenaara6878372014-03-22 21:02:50 +01001099 if a:0 > 0 && a:1 != ""
1100 " if a netrw window is already on the left-side of the tab
1101 " and a directory has been specified, explore with that
1102 " directory.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001103 let a1 = expand(a:1)
Bram Moolenaara6878372014-03-22 21:02:50 +01001104 exe "1wincmd w"
1105 if &ft == "netrw"
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001106 exe "Explore ".fnameescape(a1)
1107 exe curwin."wincmd w"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001108 let s:lexplore_win= curwin
1109 let w:lexplore_buf= bufnr("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001110 if exists("t:netrw_lexposn")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001111 unlet t:netrw_lexposn
1112 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001113 return
Bram Moolenaara6878372014-03-22 21:02:50 +01001114 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001115 exe curwin."wincmd w"
1116 else
1117 let a1= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01001118 endif
1119
Bram Moolenaar8d043172014-01-23 14:24:41 +01001120 if exists("t:netrw_lexbufnr")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001121 " check if t:netrw_lexbufnr refers to a netrw window
Bram Moolenaar8d043172014-01-23 14:24:41 +01001122 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001123 else
1124 let lexwinnr= 0
1125 endif
1126
1127 if lexwinnr > 0
1128 " close down netrw explorer window
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001129 exe lexwinnr."wincmd w"
1130 let g:netrw_winsize = -winwidth(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001131 let t:netrw_lexposn = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001132 close
1133 if lexwinnr < curwin
1134 let curwin= curwin - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +01001135 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001136 if lexwinnr != curwin
1137 exe curwin."wincmd w"
1138 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001139 unlet t:netrw_lexbufnr
1140
1141 else
1142 " open netrw explorer window
1143 exe "1wincmd w"
1144 let keep_altv = g:netrw_altv
1145 let g:netrw_altv = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001146 if a:count != 0
1147 let netrw_winsize = g:netrw_winsize
1148 let g:netrw_winsize = a:count
Bram Moolenaar8d043172014-01-23 14:24:41 +01001149 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001150 let curfile= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001151 exe (a:rightside? "botright" : "topleft")." vertical ".((g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize) . " new"
1152 if a:0 > 0 && a1 != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02001153 call netrw#Explore(0,0,0,a1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001154 exe "Explore ".fnameescape(a1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001155 elseif curfile =~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02001156 call netrw#Explore(0,0,0,substitute(curfile,'[^/\\]*$','',''))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001157 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02001158 call netrw#Explore(0,0,0,".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001159 endif
1160 if a:count != 0
1161 let g:netrw_winsize = netrw_winsize
1162 endif
1163 setlocal winfixwidth
Bram Moolenaar8d043172014-01-23 14:24:41 +01001164 let g:netrw_altv = keep_altv
1165 let t:netrw_lexbufnr = bufnr("%")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001166 " done to prevent build-up of hidden buffers due to quitting and re-invocation of :Lexplore.
1167 " Since the intended use of :Lexplore is to have an always-present explorer window, the extra
Bram Moolenaar71badf92023-04-22 22:40:14 +01001168 " effort to prevent mis-use of :Lex is warranted.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001169 set bh=wipe
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001170 if exists("t:netrw_lexposn")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001171 call winrestview(t:netrw_lexposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001172 unlet t:netrw_lexposn
1173 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01001174 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001175
1176 " set up default window for editing via <cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01001177 if exists("g:netrw_chgwin") && g:netrw_chgwin == -1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001178 if a:rightside
1179 let g:netrw_chgwin= 1
1180 else
1181 let g:netrw_chgwin= 2
1182 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001183 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001184
Bram Moolenaar8d043172014-01-23 14:24:41 +01001185endfun
1186
1187" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001188" netrw#Clean: remove netrw {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00001189" supports :NetrwClean -- remove netrw from first directory on runtimepath
1190" :NetrwClean! -- remove netrw from all directories on runtimepath
Bram Moolenaara6878372014-03-22 21:02:50 +01001191fun! netrw#Clean(sys)
1192" call Dfunc("netrw#Clean(sys=".a:sys.")")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001193
1194 if a:sys
1195 let choice= confirm("Remove personal and system copies of netrw?","&Yes\n&No")
1196 else
1197 let choice= confirm("Remove personal copy of netrw?","&Yes\n&No")
1198 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001199" call Decho("choice=".choice,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00001200 let diddel= 0
1201 let diddir= ""
1202
1203 if choice == 1
1204 for dir in split(&rtp,',')
1205 if filereadable(dir."/plugin/netrwPlugin.vim")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001206" call Decho("removing netrw-related files from ".dir,'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00001207 if s:NetrwDelete(dir."/plugin/netrwPlugin.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/plugin/netrwPlugin.vim",55) |endif
1208 if s:NetrwDelete(dir."/autoload/netrwFileHandlers.vim")|call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwFileHandlers.vim",55)|endif
1209 if s:NetrwDelete(dir."/autoload/netrwSettings.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrwSettings.vim",55) |endif
1210 if s:NetrwDelete(dir."/autoload/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/autoload/netrw.vim",55) |endif
1211 if s:NetrwDelete(dir."/syntax/netrw.vim") |call netrw#ErrorMsg(1,"unable to remove ".dir."/syntax/netrw.vim",55) |endif
1212 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 +00001213 let diddir= dir
1214 let diddel= diddel + 1
1215 if !a:sys|break|endif
1216 endif
1217 endfor
1218 endif
1219
1220 echohl WarningMsg
1221 if diddel == 0
1222 echomsg "netrw is either not installed or not removable"
1223 elseif diddel == 1
1224 echomsg "removed one copy of netrw from <".diddir.">"
1225 else
1226 echomsg "removed ".diddel." copies of netrw"
1227 endif
1228 echohl None
1229
Bram Moolenaara6878372014-03-22 21:02:50 +01001230" call Dret("netrw#Clean")
Bram Moolenaar446cb832008-06-24 21:56:24 +00001231endfun
1232
Bram Moolenaar5c736222010-01-06 20:54:52 +01001233" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01001234" netrw#MakeTgt: make a target out of the directory name provided {{{2
1235fun! netrw#MakeTgt(dname)
1236" call Dfunc("netrw#MakeTgt(dname<".a:dname.">)")
1237 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001238 let svpos = winsaveview()
1239" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001240 let s:netrwmftgt_islocal= (a:dname !~ '^\a\{3,}://')
1241" call Decho("s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001242 if s:netrwmftgt_islocal
1243 let netrwmftgt= simplify(a:dname)
1244 else
1245 let netrwmftgt= a:dname
1246 endif
1247 if exists("s:netrwmftgt") && netrwmftgt == s:netrwmftgt
1248 " re-selected target, so just clear it
1249 unlet s:netrwmftgt s:netrwmftgt_islocal
1250 else
1251 let s:netrwmftgt= netrwmftgt
1252 endif
1253 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001254 call s:NetrwRefresh((b:netrw_curdir !~ '\a\{3,}://'),b:netrw_curdir)
Bram Moolenaara6878372014-03-22 21:02:50 +01001255 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001256" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
1257 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001258" call Dret("netrw#MakeTgt")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001259endfun
1260
Bram Moolenaara6878372014-03-22 21:02:50 +01001261" ---------------------------------------------------------------------
1262" netrw#Obtain: {{{2
1263" netrw#Obtain(islocal,fname[,tgtdirectory])
Bram Moolenaarff034192013-04-24 18:51:19 +02001264" islocal=0 obtain from remote source
1265" =1 obtain from local source
1266" fname : a filename or a list of filenames
1267" tgtdir : optional place where files are to go (not present, uses getcwd())
Bram Moolenaara6878372014-03-22 21:02:50 +01001268fun! netrw#Obtain(islocal,fname,...)
1269" 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 +02001270 " NetrwStatusLine support - for obtaining support
1271
1272 if type(a:fname) == 1
1273 let fnamelist= [ a:fname ]
1274 elseif type(a:fname) == 3
1275 let fnamelist= a:fname
1276 else
1277 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 +01001278" call Dret("netrw#Obtain")
Bram Moolenaarff034192013-04-24 18:51:19 +02001279 return
1280 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001281" call Decho("fnamelist<".string(fnamelist).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001282 if a:0 > 0
1283 let tgtdir= a:1
1284 else
1285 let tgtdir= getcwd()
1286 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001287" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001288
1289 if exists("b:netrw_islocal") && b:netrw_islocal
1290 " obtain a file from local b:netrw_curdir to (local) tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001291" call Decho("obtain a file from local ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001292 if exists("b:netrw_curdir") && getcwd() != b:netrw_curdir
1293 let topath= s:ComposePath(tgtdir,"")
Nir Lichtman1e34b952024-05-08 19:19:34 +02001294 if has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02001295 " transfer files one at time
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001296" call Decho("transfer files one at a time",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001297 for fname in fnamelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001298" call Decho("system(".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001299 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001300 if v:shell_error != 0
1301 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 +01001302" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".s:ShellEscape(fname)." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001303 return
1304 endif
1305 endfor
1306 else
1307 " transfer files with one command
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001308" call Decho("transfer files with one command",'~'.expand("<slnum>"))
1309 let filelist= join(map(deepcopy(fnamelist),"s:ShellEscape(v:val)"))
1310" call Decho("system(".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath).")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001311 call system(g:netrw_localcopycmd.g:netrw_localcopycmdopt." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001312 if v:shell_error != 0
1313 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 +01001314" call Dret("s:NetrwObtain 0 : failed: ".g:netrw_localcopycmd." ".filelist." ".s:ShellEscape(topath))
Bram Moolenaarff034192013-04-24 18:51:19 +02001315 return
1316 endif
1317 endif
1318 elseif !exists("b:netrw_curdir")
1319 call netrw#ErrorMsg(s:ERROR,"local browsing directory doesn't exist!",36)
1320 else
1321 call netrw#ErrorMsg(s:WARNING,"local browsing directory and current directory are identical",37)
1322 endif
1323
1324 else
1325 " obtain files from remote b:netrw_curdir to local tgtdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001326" call Decho("obtain a file from remote ".b:netrw_curdir." to ".tgtdir,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001327 if type(a:fname) == 1
1328 call s:SetupNetrwStatusLine('%f %h%m%r%=%9*Obtaining '.a:fname)
1329 endif
1330 call s:NetrwMethod(b:netrw_curdir)
1331
1332 if b:netrw_method == 4
1333 " obtain file using scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001334" call Decho("obtain via scp (method#4)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001335 if exists("g:netrw_port") && g:netrw_port != ""
1336 let useport= " ".g:netrw_scpport." ".g:netrw_port
1337 else
1338 let useport= ""
1339 endif
1340 if b:netrw_fname =~ '/'
1341 let path= substitute(b:netrw_fname,'^\(.*/\).\{-}$','\1','')
1342 else
1343 let path= ""
1344 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001345 let filelist= join(map(deepcopy(fnamelist),'escape(s:ShellEscape(g:netrw_machine.":".path.v:val,1)," ")'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001346 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 +02001347
1348 elseif b:netrw_method == 2
1349 " obtain file using ftp + .netrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001350" call Decho("obtain via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001351 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001352 let tmpbufnr= bufnr("%")
1353 setl ff=unix
1354 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001355 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001356" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001357 endif
1358
1359 if exists("b:netrw_fname") && b:netrw_fname != ""
1360 call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001361" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001362 endif
1363
1364 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001365 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001366" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001367 endif
1368 for fname in fnamelist
1369 call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001370" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001371 endfor
1372 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001373 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 +02001374 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001375 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarff034192013-04-24 18:51:19 +02001376 endif
1377 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1378 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
1379 let debugkeep= &debug
1380 setl debug=msg
1381 call netrw#ErrorMsg(s:ERROR,getline(1),4)
1382 let &debug= debugkeep
1383 endif
1384
1385 elseif b:netrw_method == 3
1386 " obtain with ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001387" call Decho("obtain via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001388 call s:SaveBufVars()|sil NetrwKeepj new|call s:RestoreBufVars()
Bram Moolenaarff034192013-04-24 18:51:19 +02001389 let tmpbufnr= bufnr("%")
1390 setl ff=unix
1391
1392 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001393 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001394" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001395 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001396 NetrwKeepj put ='open '.g:netrw_machine
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_uid") && g:netrw_uid != ""
1401 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001402 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001403" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001404 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001405 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaarff034192013-04-24 18:51:19 +02001406 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001407" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001408 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001409 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001410" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001411 endif
1412 endif
1413
1414 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001415 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001416" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001417 endif
1418
1419 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001420 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001421" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001422 endif
1423
1424 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001425 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001426" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001427 endif
1428
1429 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001430 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001431" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001432 endif
1433 for fname in fnamelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001434 NetrwKeepj call setline(line("$")+1,'get "'.fname.'"')
Bram Moolenaarff034192013-04-24 18:51:19 +02001435 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001436" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001437
1438 " perform ftp:
1439 " -i : turns off interactive prompting from ftp
1440 " -n unix : DON'T use <.netrc>, even though it exists
1441 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01001442 " Note: using "_dd to delete to the black hole register; avoids messing up @@
1443 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001444 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarff034192013-04-24 18:51:19 +02001445 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
1446 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001447" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02001448 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001449 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarff034192013-04-24 18:51:19 +02001450 endif
1451 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001452
1453 elseif b:netrw_method == 9
1454 " obtain file using sftp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001455" call Decho("obtain via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02001456 if a:fname =~ '/'
1457 let localfile= substitute(a:fname,'^.*/','','')
1458 else
1459 let localfile= a:fname
1460 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001461 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 +02001462
Bram Moolenaarff034192013-04-24 18:51:19 +02001463 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar13600302014-05-22 18:26:40 +02001464 " probably a badly formed url; protocol not recognized
1465" call Dret("netrw#Obtain : unsupported method")
1466 return
1467
1468 else
1469 " protocol recognized but not supported for Obtain (yet?)
1470 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001471 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"current protocol not supported for obtaining file",97)
Bram Moolenaar13600302014-05-22 18:26:40 +02001472 endif
1473" call Dret("netrw#Obtain : current protocol not supported for obtaining file")
Bram Moolenaarff034192013-04-24 18:51:19 +02001474 return
1475 endif
1476
1477 " restore status line
1478 if type(a:fname) == 1 && exists("s:netrw_users_stl")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001479 NetrwKeepj call s:SetupNetrwStatusLine(s:netrw_users_stl)
Bram Moolenaarff034192013-04-24 18:51:19 +02001480 endif
1481
1482 endif
1483
1484 " cleanup
1485 if exists("tmpbufnr")
1486 if bufnr("%") != tmpbufnr
1487 exe tmpbufnr."bw!"
1488 else
1489 q!
1490 endif
1491 endif
1492
Bram Moolenaara6878372014-03-22 21:02:50 +01001493" call Dret("netrw#Obtain")
1494endfun
1495
1496" ---------------------------------------------------------------------
1497" netrw#Nread: save position, call netrw#NetRead(), and restore position {{{2
1498fun! netrw#Nread(mode,fname)
1499" call Dfunc("netrw#Nread(mode=".a:mode." fname<".a:fname.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001500 let svpos= winsaveview()
1501" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01001502 call netrw#NetRead(a:mode,a:fname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001503" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
1504 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01001505
1506 if exists("w:netrw_liststyle") && w:netrw_liststyle != s:TREELIST
1507 if exists("w:netrw_bannercnt")
1508 " start with cursor just after the banner
1509 exe w:netrw_bannercnt
1510 endif
1511 endif
1512" call Dret("netrw#Nread")
1513endfun
1514
1515" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001516" s:NetrwOptionsSave: save options prior to setting to "netrw-buffer-standard" form {{{2
1517" Options get restored by s:NetrwOptionsRestore()
1518"
1519" Option handling:
1520" * save user's options (s:NetrwOptionsSave)
1521" * set netrw-safe options (s:NetrwOptionsSafe)
1522" - change an option only when user option != safe option (s:netrwSetSafeSetting)
1523" * restore user's options (s:netrwOPtionsRestore)
1524" - restore a user option when != safe option (s:NetrwRestoreSetting)
1525" vt: (variable type) normally its either "w:" or "s:"
1526fun! s:NetrwOptionsSave(vt)
1527" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
1528" 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 +02001529" 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>"))
1530" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001531
1532 if !exists("{a:vt}netrw_optionsave")
1533 let {a:vt}netrw_optionsave= 1
1534 else
1535" call Dret("s:NetrwOptionsSave : options already saved")
1536 return
1537 endif
1538" call Decho("prior to save: fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." diff=".&l:diff,'~'.expand("<slnum>"))
1539
1540 " Save current settings and current directory
1541" call Decho("saving current settings and current directory",'~'.expand("<slnum>"))
1542 let s:yykeep = @@
1543 if exists("&l:acd")|let {a:vt}netrw_acdkeep = &l:acd|endif
1544 let {a:vt}netrw_aikeep = &l:ai
1545 let {a:vt}netrw_awkeep = &l:aw
1546 let {a:vt}netrw_bhkeep = &l:bh
1547 let {a:vt}netrw_blkeep = &l:bl
1548 let {a:vt}netrw_btkeep = &l:bt
1549 let {a:vt}netrw_bombkeep = &l:bomb
1550 let {a:vt}netrw_cedit = &cedit
1551 let {a:vt}netrw_cikeep = &l:ci
1552 let {a:vt}netrw_cinkeep = &l:cin
1553 let {a:vt}netrw_cinokeep = &l:cino
1554 let {a:vt}netrw_comkeep = &l:com
1555 let {a:vt}netrw_cpokeep = &l:cpo
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001556 let {a:vt}netrw_cuckeep = &l:cuc
1557 let {a:vt}netrw_culkeep = &l:cul
1558" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001559 let {a:vt}netrw_diffkeep = &l:diff
1560 let {a:vt}netrw_fenkeep = &l:fen
Bram Moolenaar85850f32019-07-19 22:05:51 +02001561 if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
1562 let {a:vt}netrw_ffkeep = &l:ff
1563 endif
1564 let {a:vt}netrw_fokeep = &l:fo " formatoptions
1565 let {a:vt}netrw_gdkeep = &l:gd " gdefault
Bram Moolenaar71badf92023-04-22 22:40:14 +01001566 let {a:vt}netrw_gokeep = &go " guioptions
Bram Moolenaar85850f32019-07-19 22:05:51 +02001567 let {a:vt}netrw_hidkeep = &l:hidden
1568 let {a:vt}netrw_imkeep = &l:im
1569 let {a:vt}netrw_iskkeep = &l:isk
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001570 let {a:vt}netrw_lines = &lines
Bram Moolenaar85850f32019-07-19 22:05:51 +02001571 let {a:vt}netrw_lskeep = &l:ls
1572 let {a:vt}netrw_makeep = &l:ma
1573 let {a:vt}netrw_magickeep = &l:magic
1574 let {a:vt}netrw_modkeep = &l:mod
1575 let {a:vt}netrw_nukeep = &l:nu
1576 let {a:vt}netrw_rnukeep = &l:rnu
1577 let {a:vt}netrw_repkeep = &l:report
1578 let {a:vt}netrw_rokeep = &l:ro
1579 let {a:vt}netrw_selkeep = &l:sel
1580 let {a:vt}netrw_spellkeep = &l:spell
Bram Moolenaar85850f32019-07-19 22:05:51 +02001581 if !g:netrw_use_noswf
1582 let {a:vt}netrw_swfkeep = &l:swf
1583 endif
1584 let {a:vt}netrw_tskeep = &l:ts
1585 let {a:vt}netrw_twkeep = &l:tw " textwidth
1586 let {a:vt}netrw_wigkeep = &l:wig " wildignore
1587 let {a:vt}netrw_wrapkeep = &l:wrap
1588 let {a:vt}netrw_writekeep = &l:write
1589
1590 " save a few selected netrw-related variables
1591" call Decho("saving a few selected netrw-related variables",'~'.expand("<slnum>"))
1592 if g:netrw_keepdir
1593 let {a:vt}netrw_dirkeep = getcwd()
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001594" call Decho("saving to ".a:vt."netrw_dirkeep<".{a:vt}netrw_dirkeep.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02001595 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001596 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001597 sil! let {a:vt}netrw_starkeep = @*
1598 sil! let {a:vt}netrw_pluskeep = @+
1599 endif
1600 sil! let {a:vt}netrw_slashkeep= @/
1601
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001602" call Decho("(s:NetrwOptionsSave) lines=".&lines)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001603" 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>"))
1604" call Dret("s:NetrwOptionsSave : tab#".tabpagenr()." win#".winnr())
1605endfun
1606
1607" ---------------------------------------------------------------------
1608" s:NetrwOptionsSafe: sets options to help netrw do its job {{{2
1609" Use s:NetrwSaveOptions() to save user settings
1610" Use s:NetrwOptionsRestore() to restore user settings
1611fun! s:NetrwOptionsSafe(islocal)
1612" call Dfunc("s:NetrwOptionsSafe(islocal=".a:islocal.") win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%"))."> winnr($)=".winnr("$"))
1613" call Decho("win#".winnr()."'s ft=".&ft,'~'.expand("<slnum>"))
1614" 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>"))
1615 if exists("+acd") | call s:NetrwSetSafeSetting("&l:acd",0)|endif
1616 call s:NetrwSetSafeSetting("&l:ai",0)
1617 call s:NetrwSetSafeSetting("&l:aw",0)
1618 call s:NetrwSetSafeSetting("&l:bl",0)
1619 call s:NetrwSetSafeSetting("&l:bomb",0)
1620 if a:islocal
1621 call s:NetrwSetSafeSetting("&l:bt","nofile")
1622 else
1623 call s:NetrwSetSafeSetting("&l:bt","acwrite")
1624 endif
1625 call s:NetrwSetSafeSetting("&l:ci",0)
1626 call s:NetrwSetSafeSetting("&l:cin",0)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001627 if g:netrw_fastbrowse > a:islocal
1628 call s:NetrwSetSafeSetting("&l:bh","hide")
1629 else
1630 call s:NetrwSetSafeSetting("&l:bh","delete")
1631 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001632 call s:NetrwSetSafeSetting("&l:cino","")
1633 call s:NetrwSetSafeSetting("&l:com","")
1634 if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
1635 if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
1636 setl fo=nroql2
Bram Moolenaar71badf92023-04-22 22:40:14 +01001637 if &go =~ 'a' | set go-=a | endif
1638 if &go =~ 'A' | set go-=A | endif
1639 if &go =~ 'P' | set go-=P | endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001640 call s:NetrwSetSafeSetting("&l:hid",0)
1641 call s:NetrwSetSafeSetting("&l:im",0)
1642 setl isk+=@ isk+=* isk+=/
1643 call s:NetrwSetSafeSetting("&l:magic",1)
1644 if g:netrw_use_noswf
1645 call s:NetrwSetSafeSetting("swf",0)
1646 endif
1647 call s:NetrwSetSafeSetting("&l:report",10000)
1648 call s:NetrwSetSafeSetting("&l:sel","inclusive")
1649 call s:NetrwSetSafeSetting("&l:spell",0)
1650 call s:NetrwSetSafeSetting("&l:tw",0)
1651 call s:NetrwSetSafeSetting("&l:wig","")
1652 setl cedit&
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001653
1654 " set up cuc and cul based on g:netrw_cursor and listing style
1655 " COMBAK -- cuc cul related
1656 call s:NetrwCursor(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02001657
1658 " allow the user to override safe options
1659" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
1660 if &ft == "netrw"
1661" call Decho("do any netrw FileType autocmds (doau FileType netrw)",'~'.expand("<slnum>"))
1662 keepalt NetrwKeepj doau FileType netrw
1663 endif
1664
1665" call Decho("fo=".&fo.(exists("+acd")? " acd=".&acd : " acd doesn't exist")." bh=".&l:bh." bt<".&bt.">",'~'.expand("<slnum>"))
1666" 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>"))
1667" call Dret("s:NetrwOptionsSafe")
1668endfun
1669
1670" ---------------------------------------------------------------------
1671" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
1672fun! s:NetrwOptionsRestore(vt)
Bram Moolenaara6878372014-03-22 21:02:50 +01001673 if !exists("{a:vt}netrw_optionsave")
Christian Brabandtaa2ce6f2024-10-30 18:27:03 +01001674 " filereadable() returns zero for remote files (e.g. scp://user@localhost//etc/fstab)
1675 " Note: @ may not be in 'isfname', so '^\w\+://\f\+/' may not match
1676 if filereadable(expand("%")) || expand("%") =~# '^\w\+://\f\+'
Bram Moolenaar71badf92023-04-22 22:40:14 +01001677 filetype detect
Bram Moolenaar71badf92023-04-22 22:40:14 +01001678 else
1679 setl ft=netrw
Bram Moolenaar3c053a12022-10-16 13:11:12 +01001680 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001681 return
1682 endif
1683 unlet {a:vt}netrw_optionsave
1684
1685 if exists("+acd")
1686 if exists("{a:vt}netrw_acdkeep")
Bram Moolenaara6878372014-03-22 21:02:50 +01001687 let curdir = getcwd()
1688 let &l:acd = {a:vt}netrw_acdkeep
1689 unlet {a:vt}netrw_acdkeep
1690 if &l:acd
1691 call s:NetrwLcd(curdir)
1692 endif
1693 endif
1694 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001695 call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
1696 call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
1697 call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
1698 call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
1699 call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
1700 call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
1701 call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
1702 call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
1703 call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
1704 call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
1705 call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
1706 call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
1707 call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
1708 if exists("g:netrw_ffkeep") && g:netrw_ffkeep
1709 call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001710 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001711 call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
1712 call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
Bram Moolenaar71badf92023-04-22 22:40:14 +01001713 call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&go")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001714 call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001715 call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
1716 call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001717 call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001718 call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
1719 call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001720 call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001721 call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
1722 call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001723 call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
1724 call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
1725 call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
1726 call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001727 call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001728 call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
1729 call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
1730 call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001731 call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
1732 call s:NetrwRestoreSetting("s:yykeep","@@")
1733 " former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
1734 " Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
1735 " rather than by appending a tab which previously was using "&ts" to set the desired spacing. (Sep 28, 2018)
1736 call s:NetrwRestoreSetting(a:vt."netrw_tskeep","&l:ts")
1737
Bram Moolenaara6878372014-03-22 21:02:50 +01001738 if exists("{a:vt}netrw_swfkeep")
1739 if &directory == ""
1740 " user hasn't specified a swapfile directory;
1741 " netrw will temporarily set the swapfile directory
1742 " to the current directory as returned by getcwd().
1743 let &l:directory= getcwd()
1744 sil! let &l:swf = {a:vt}netrw_swfkeep
1745 setl directory=
1746 unlet {a:vt}netrw_swfkeep
1747 elseif &l:swf != {a:vt}netrw_swfkeep
Bram Moolenaare0fa3742016-02-20 15:47:01 +01001748 if !g:netrw_use_noswf
1749 " following line causes a Press ENTER in windows -- can't seem to work around it!!!
1750 sil! let &l:swf= {a:vt}netrw_swfkeep
1751 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001752 unlet {a:vt}netrw_swfkeep
1753 endif
1754 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001755 if exists("{a:vt}netrw_dirkeep") && isdirectory(s:NetrwFile({a:vt}netrw_dirkeep)) && g:netrw_keepdir
Bram Moolenaara6878372014-03-22 21:02:50 +01001756 let dirkeep = substitute({a:vt}netrw_dirkeep,'\\','/','g')
1757 if exists("{a:vt}netrw_dirkeep")
1758 call s:NetrwLcd(dirkeep)
1759 unlet {a:vt}netrw_dirkeep
1760 endif
1761 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001762 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar85850f32019-07-19 22:05:51 +02001763 call s:NetrwRestoreSetting(a:vt."netrw_starkeep","@*")
1764 call s:NetrwRestoreSetting(a:vt."netrw_pluskeep","@+")
Bram Moolenaara6878372014-03-22 21:02:50 +01001765 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02001766 call s:NetrwRestoreSetting(a:vt."netrw_slashkeep","@/")
Bram Moolenaara6878372014-03-22 21:02:50 +01001767
Bram Moolenaara6878372014-03-22 21:02:50 +01001768 " Moved the filetype detect here from NetrwGetFile() because remote files
1769 " were having their filetype detect-generated settings overwritten by
1770 " NetrwOptionRestore.
1771 if &ft != "netrw"
Bram Moolenaar71badf92023-04-22 22:40:14 +01001772 filetype detect
Bram Moolenaara6878372014-03-22 21:02:50 +01001773 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001774endfun
1775
1776" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001777" s:NetrwSetSafeSetting: sets an option to a safe setting {{{2
1778" but only when the options' value and the safe setting differ
1779" Doing this means that netrw will not come up as having changed a
1780" setting last when it really didn't actually change it.
1781"
1782" Called from s:NetrwOptionsSafe
1783" ex. call s:NetrwSetSafeSetting("&l:sel","inclusive")
1784fun! s:NetrwSetSafeSetting(setting,safesetting)
1785" call Dfunc("s:NetrwSetSafeSetting(setting<".a:setting."> safesetting<".a:safesetting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001786
Bram Moolenaar85850f32019-07-19 22:05:51 +02001787 if a:setting =~ '^&'
1788" call Decho("fyi: a:setting starts with &")
1789 exe "let settingval= ".a:setting
1790" call Decho("fyi: settingval<".settingval.">")
Bram Moolenaara6878372014-03-22 21:02:50 +01001791
Bram Moolenaar85850f32019-07-19 22:05:51 +02001792 if settingval != a:safesetting
1793" call Decho("set setting<".a:setting."> to option value<".a:safesetting.">")
1794 if type(a:safesetting) == 0
1795 exe "let ".a:setting."=".a:safesetting
1796 elseif type(a:safesetting) == 1
1797 exe "let ".a:setting."= '".a:safesetting."'"
1798 else
1799 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:setting." with a safesetting of type#".type(a:safesetting),105)
1800 endif
1801 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02001802 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01001803
Bram Moolenaar85850f32019-07-19 22:05:51 +02001804" call Dret("s:NetrwSetSafeSetting")
Bram Moolenaara6878372014-03-22 21:02:50 +01001805endfun
1806
1807" ------------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02001808" s:NetrwRestoreSetting: restores specified setting using associated keepvar, {{{2
1809" but only if the setting value differs from the associated keepvar.
1810" Doing this means that netrw will not come up as having changed a
1811" setting last when it really didn't actually change it.
1812"
Viktor Szépedbf749b2023-10-16 09:53:37 +02001813" Used by s:NetrwOptionsRestore() to restore each netrw-sensitive setting
Bram Moolenaar85850f32019-07-19 22:05:51 +02001814" keepvars are set up by s:NetrwOptionsSave
1815fun! s:NetrwRestoreSetting(keepvar,setting)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001816""" call Dfunc("s:NetrwRestoreSetting(a:keepvar<".a:keepvar."> a:setting<".a:setting.">)")
Bram Moolenaara6878372014-03-22 21:02:50 +01001817
Bram Moolenaar85850f32019-07-19 22:05:51 +02001818 " typically called from s:NetrwOptionsRestore
1819 " call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
1820 " ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02001821 " Restores option (but only if different) from a:keepvar
Bram Moolenaar85850f32019-07-19 22:05:51 +02001822 if exists(a:keepvar)
1823 exe "let keepvarval= ".a:keepvar
1824 exe "let setting= ".a:setting
1825
1826"" call Decho("fyi: a:keepvar<".a:keepvar."> exists")
1827"" call Decho("fyi: keepvarval=".keepvarval)
1828"" call Decho("fyi: a:setting<".a:setting."> setting<".setting.">")
1829
1830 if setting != keepvarval
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01001831"" call Decho("restore setting<".a:setting."> (currently=".setting.") to keepvarval<".keepvarval.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +02001832 if type(a:setting) == 0
1833 exe "let ".a:setting."= ".keepvarval
1834 elseif type(a:setting) == 1
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02001835 exe "let ".a:setting."= '".substitute(keepvarval,"'","''","g")."'"
Bram Moolenaar85850f32019-07-19 22:05:51 +02001836 else
1837 call netrw#ErrorMsg(s:ERROR,"(s:NetrwRestoreSetting) doesn't know how to restore ".a:keepvar." with a setting of type#".type(a:setting),105)
1838 endif
1839 endif
1840
1841 exe "unlet ".a:keepvar
Bram Moolenaara6878372014-03-22 21:02:50 +01001842 endif
1843
Bram Moolenaar85850f32019-07-19 22:05:51 +02001844"" call Dret("s:NetrwRestoreSetting")
Bram Moolenaarff034192013-04-24 18:51:19 +02001845endfun
1846
1847" ---------------------------------------------------------------------
1848" NetrwStatusLine: {{{2
1849fun! NetrwStatusLine()
1850
1851" vvv NetrwStatusLine() debugging vvv
1852" let g:stlmsg=""
1853" if !exists("w:netrw_explore_bufnr")
1854" let g:stlmsg="!X<explore_bufnr>"
1855" elseif w:netrw_explore_bufnr != bufnr("%")
1856" let g:stlmsg="explore_bufnr!=".bufnr("%")
1857" endif
1858" if !exists("w:netrw_explore_line")
1859" let g:stlmsg=" !X<explore_line>"
1860" elseif w:netrw_explore_line != line(".")
1861" let g:stlmsg=" explore_line!={line(.)<".line(".").">"
1862" endif
1863" if !exists("w:netrw_explore_list")
1864" let g:stlmsg=" !X<explore_list>"
1865" endif
1866" ^^^ NetrwStatusLine() debugging ^^^
1867
1868 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")
1869 " restore user's status line
K.Takataa262d3f2024-01-25 04:10:19 +09001870 let &l:stl = s:netrw_users_stl
Bram Moolenaarff034192013-04-24 18:51:19 +02001871 let &laststatus = s:netrw_users_ls
1872 if exists("w:netrw_explore_bufnr")|unlet w:netrw_explore_bufnr|endif
1873 if exists("w:netrw_explore_line") |unlet w:netrw_explore_line |endif
1874 return ""
1875 else
1876 return "Match ".w:netrw_explore_mtchcnt." of ".w:netrw_explore_listlen
1877 endif
1878endfun
1879
Bram Moolenaar85850f32019-07-19 22:05:51 +02001880" ===============================
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00001881" Netrw Transfer Functions: {{{1
1882" ===============================
1883
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00001885" netrw#NetRead: responsible for reading a file over the net {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00001886" mode: =0 read remote file and insert before current line
1887" =1 read remote file and insert after current line
1888" =2 replace with remote file
1889" =3 obtain file, but leave in temporary format
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001890fun! netrw#NetRead(mode,...)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02001891" 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 +00001892
Bram Moolenaar5c736222010-01-06 20:54:52 +01001893 " NetRead: save options {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02001894 call s:NetrwOptionsSave("w:")
1895 call s:NetrwOptionsSafe(0)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02001896 call s:RestoreCursorline()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001897 " NetrwSafeOptions sets a buffer up for a netrw listing, which includes buflisting off.
1898 " However, this setting is not wanted for a remote editing session. The buffer should be "nofile", still.
1899 setl bl
Bram Moolenaar85850f32019-07-19 22:05:51 +02001900" call Decho("buf#".bufnr("%")."<".bufname("%")."> bl=".&bl." bt=".&bt." bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001901
Bram Moolenaar5c736222010-01-06 20:54:52 +01001902 " NetRead: interpret mode into a readcmd {{{3
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001903 if a:mode == 0 " read remote file before current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001904 let readcmd = "0r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001905 elseif a:mode == 1 " read file after current line
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001906 let readcmd = "r"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001907 elseif a:mode == 2 " replace with remote file
1908 let readcmd = "%r"
Bram Moolenaar9964e462007-05-05 17:54:07 +00001909 elseif a:mode == 3 " skip read of file (leave as temporary)
1910 let readcmd = "t"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001911 else
1912 exe a:mode
1913 let readcmd = "r"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001914 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001915 let ichoice = (a:0 == 0)? 0 : 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001916" call Decho("readcmd<".readcmd."> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001917
Bram Moolenaar5c736222010-01-06 20:54:52 +01001918 " NetRead: get temporary filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00001919 let tmpfile= s:GetTempfile("")
1920 if tmpfile == ""
1921" call Dret("netrw#NetRead : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00001922 return
1923 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001924
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001925 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001926
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001927 " attempt to repeat with previous host-file-etc
1928 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001929" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001930 let choice = b:netrw_lastfile
1931 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001932
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001933 else
1934 exe "let choice= a:" . ichoice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001935" call Decho("no lastfile: choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001936
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001937 if match(choice,"?") == 0
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001938 " give help
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001939 echomsg 'NetRead Usage:'
1940 echomsg ':Nread machine:path uses rcp'
1941 echomsg ':Nread "machine path" uses ftp with <.netrc>'
1942 echomsg ':Nread "machine id password path" uses ftp'
1943 echomsg ':Nread dav://machine[:port]/path uses cadaver'
1944 echomsg ':Nread fetch://machine/path uses fetch'
1945 echomsg ':Nread ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
1946 echomsg ':Nread http://[user@]machine/path uses http wget'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001947 echomsg ':Nread file:///path uses elinks'
Bram Moolenaara6878372014-03-22 21:02:50 +01001948 echomsg ':Nread https://[user@]machine/path uses http wget'
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001949 echomsg ':Nread rcp://[user@]machine/path uses rcp'
1950 echomsg ':Nread rsync://machine[:port]/path uses rsync'
1951 echomsg ':Nread scp://[user@]machine[[:#]port]/path uses scp'
1952 echomsg ':Nread sftp://[user@]machine[[:#]port]/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00001953 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001954 break
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001955
Bram Moolenaar9964e462007-05-05 17:54:07 +00001956 elseif match(choice,'^"') != -1
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001957 " Reconstruct Choice if choice starts with '"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001958" call Decho("reconstructing choice",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00001959 if match(choice,'"$') != -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001960 " case "..."
Bram Moolenaaradc21822011-04-01 18:03:16 +02001961 let choice= strpart(choice,1,strlen(choice)-2)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001962 else
1963 " case "... ... ..."
1964 let choice = strpart(choice,1,strlen(choice)-1)
1965 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001966
Bram Moolenaar9964e462007-05-05 17:54:07 +00001967 while match(choice,'"$') == -1
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001968 let wholechoice = wholechoice . " " . choice
1969 let ichoice = ichoice + 1
1970 if ichoice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09001971 if !exists("g:netrw_quiet")
1972 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",3)
1973 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001974" call Dret("netrw#NetRead :2 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001975 return
1976 endif
1977 let choice= a:{ichoice}
1978 endwhile
1979 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
1980 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 endif
1982 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001984" call Decho("choice<" . choice . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001985 let ichoice= ichoice + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001986
Bram Moolenaar5c736222010-01-06 20:54:52 +01001987 " NetRead: Determine method of read (ftp, rcp, etc) {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00001988 call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01001989 if !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02001990" call Dret("netrw#NetRead : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001991 return
1992 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00001993 let tmpfile= s:GetTempfile(b:netrw_fname) " apply correct suffix
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001994
Bram Moolenaar8d043172014-01-23 14:24:41 +01001995 " Check whether or not NetrwBrowse() should be handling this request
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001996" 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 +02001997 if choice =~ "^.*[\/]$" && b:netrw_method != 5 && choice !~ '^https\=://'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01001998" call Decho("yes, choice matches '^.*[\/]$'",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01001999 NetrwKeepj call s:NetrwBrowse(0,choice)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002000" call Dret("netrw#NetRead :3 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002001 return
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002003
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002004 " ============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002005 " NetRead: Perform Protocol-Based Read {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002006 " ===========================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002007 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2008 echo "(netrw) Processing your read request..."
2009 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002010
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002011 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002012 " NetRead: (rcp) NetRead Method #1 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002013 if b:netrw_method == 1 " read with rcp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002014" call Decho("read via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaard68071d2006-05-02 22:08:30 +00002015 " ER: nothing done with g:netrw_uid yet?
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002016 " ER: on Win2K" rcp machine[.user]:file tmpfile
Bram Moolenaar8d043172014-01-23 14:24:41 +01002017 " ER: when machine contains '.' adding .user is required (use $USERNAME)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002018 " ER: the tmpfile is full path: rcp sees C:\... as host C
2019 if s:netrw_has_nt_rcp == 1
2020 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2021 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2022 else
2023 " Any way needed it machine contains a '.'
2024 let uid_machine = g:netrw_machine .'.'. $USERNAME
2025 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 else
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002027 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2028 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2029 else
2030 let uid_machine = g:netrw_machine
2031 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002033 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 +00002034 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002035 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002036
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002037 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002038 " NetRead: (ftp + <.netrc>) NetRead Method #2 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002039 elseif b:netrw_method == 2 " read with ftp + <.netrc>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002040" call Decho("read via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar8dff8182006-04-06 20:18:50 +00002041 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002042 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002043 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002044 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002045 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002046" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002047 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002048 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002049" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002050 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002051 call setline(line("$")+1,'get "'.netrw_fname.'" '.tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002052" call Decho("filter input: ".getline(line("$")),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002053 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002054 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 +00002055 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002056 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002057 endif
2058 " 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 +00002059 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
Bram Moolenaarc236c162008-07-13 17:41:49 +00002060 let debugkeep = &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02002061 setl debug=msg
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002062 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),4)
Bram Moolenaarc236c162008-07-13 17:41:49 +00002063 let &debug = debugkeep
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002064 endif
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002065 call s:SaveBufVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002066 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002067 if bufname("%") == "" && getline("$") == "" && line('$') == 1
2068 " needed when one sources a file in a nolbl setting window via ftp
Bram Moolenaared39e1d2008-08-09 17:55:22 +00002069 q!
2070 endif
2071 call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002072 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002073 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002074
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002075 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002076 " NetRead: (ftp + machine,id,passwd,filename) NetRead Method #3 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002077 elseif b:netrw_method == 3 " read with ftp + machine, id, passwd, and fname
2078 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002079" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002080 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002081 NetrwKeepj call s:SaveBufVars()|new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002082 let filtbuf= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002083 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002084 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002085 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002086" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002087 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002088 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002089" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002090 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002091
Bram Moolenaar97d62492012-11-15 21:28:22 +01002092 if exists("g:netrw_uid") && g:netrw_uid != ""
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002093 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002094 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002095" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002096 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002097 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002098 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002099" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002100 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002101 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002102" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002103 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002104 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002105
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002106 if exists("g:netrw_ftpmode") && g:netrw_ftpmode != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002107 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002108" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002109 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002110 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002111 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002112" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002113 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002114 NetrwKeepj put ='get \"'.netrw_fname.'\" '.tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002115" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002116
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002117 " perform ftp:
2118 " -i : turns off interactive prompting from ftp
2119 " -n unix : DON'T use <.netrc>, even though it exists
2120 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002121 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002122 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002123 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2124 if getline(1) !~ "^$"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002125" call Decho("error<".getline(1).">",'~'.expand("<slnum>"))
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002126 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002127 call netrw#ErrorMsg(s:ERROR,getline(1),5)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002128 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002129 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002130 call s:SaveBufVars()|keepj bd!|call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00002131 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002132 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002133
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002134 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002135 " NetRead: (scp) NetRead Method #4 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002136 elseif b:netrw_method == 4 " read with scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002137" call Decho("read via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002138 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +00002139 let useport= " ".g:netrw_scpport." ".g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002140 else
2141 let useport= ""
2142 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002143 " 'C' in 'C:\path\to\file' is handled as hostname on windows.
2144 " This is workaround to avoid mis-handle windows local-path:
Nir Lichtman1e34b952024-05-08 19:19:34 +02002145 if g:netrw_scp_cmd =~ '^scp' && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002146 let tmpfile_get = substitute(tr(tmpfile, '\', '/'), '^\(\a\):[/\\]\(.*\)$', '/\1/\2', '')
2147 else
2148 let tmpfile_get = tmpfile
2149 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002150 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 +00002151 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002152 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002153
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002154 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002155 " NetRead: (http) NetRead Method #5 (wget) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002156 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002157" call Decho("read via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002158 if g:netrw_http_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002159 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002160 call netrw#ErrorMsg(s:ERROR,"neither the wget nor the fetch command is available",6)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002161 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002162" call Dret("netrw#NetRead :4 getcwd<".getcwd().">")
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002163 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002164 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002165
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002166 if match(b:netrw_fname,"#") == -1 || exists("g:netrw_http_xcmd")
2167 " using g:netrw_http_cmd (usually elinks, links, curl, wget, or fetch)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002168" call Decho('using '.g:netrw_http_cmd.' (# not in b:netrw_fname<'.b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002169 if exists("g:netrw_http_xcmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002170 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 +00002171 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002172 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 +00002173 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002174 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002175
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002176 else
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002177 " wget/curl/fetch plus a jump to an in-page marker (ie. http://abc/def.html#aMarker)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002178" call Decho("wget/curl plus jump (# in b:netrw_fname<".b:netrw_fname.">)",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002179 let netrw_html= substitute(b:netrw_fname,"#.*$","","")
2180 let netrw_tag = substitute(b:netrw_fname,"^.*#","","")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002181" call Decho("netrw_html<".netrw_html.">",'~'.expand("<slnum>"))
2182" call Decho("netrw_tag <".netrw_tag.">",'~'.expand("<slnum>"))
2183 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 +00002184 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002185" call Decho('<\s*a\s*name=\s*"'.netrw_tag.'"/','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002186 exe 'NetrwKeepj norm! 1G/<\s*a\s*name=\s*"'.netrw_tag.'"/'."\<CR>"
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002187 endif
2188 let b:netrw_lastfile = choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002189" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002190 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002191
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002192 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002193 " NetRead: (dav) NetRead Method #6 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002194 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002195" call Decho("read via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002196
Bram Moolenaar5c736222010-01-06 20:54:52 +01002197 if !executable(g:netrw_dav_cmd)
2198 call netrw#ErrorMsg(s:ERROR,g:netrw_dav_cmd." is not executable",73)
2199" call Dret("netrw#NetRead : ".g:netrw_dav_cmd." not executable")
2200 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002201 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002202 if g:netrw_dav_cmd =~ "curl"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002203 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 +01002204 else
2205 " Construct execution string (four lines) which will be passed through filter
2206 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
2207 new
Bram Moolenaarff034192013-04-24 18:51:19 +02002208 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002209 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002210 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaar5c736222010-01-06 20:54:52 +01002211 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002212 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaar5c736222010-01-06 20:54:52 +01002213 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002214 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002215 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002216 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002217 NetrwKeepj put ='get '.netrw_fname.' '.tmpfile
2218 NetrwKeepj put ='quit'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002219
Bram Moolenaar5c736222010-01-06 20:54:52 +01002220 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002221 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002222 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002223 keepj bd!
Bram Moolenaar5c736222010-01-06 20:54:52 +01002224 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00002225 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002226 let b:netrw_lastfile = choice
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: (rsync) NetRead Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002230 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002231" call Decho("read via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002232 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 +00002233 let result = s:NetrwGetFile(readcmd,tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002234 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002235
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002236 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002237 " NetRead: (fetch) NetRead Method #8 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002238 " fetch://[user@]host[:http]/path
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002239 elseif b:netrw_method == 8
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002240" call Decho("read via fetch (method #8)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002241 if g:netrw_fetch_cmd == ""
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002242 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002243 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"fetch command not available",7)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002244 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002245" call Dret("NetRead")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002246 return
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002247 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002248 if exists("g:netrw_option") && g:netrw_option =~ ":https\="
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002249 let netrw_option= "http"
2250 else
2251 let netrw_option= "ftp"
2252 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002253" call Decho("read via fetch for ".netrw_option,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002254
Bram Moolenaar446cb832008-06-24 21:56:24 +00002255 if exists("g:netrw_uid") && g:netrw_uid != "" && exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002256 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 +00002257 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002258 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 +00002259 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002260
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 Moolenaara0f849e2015-10-30 14:37:44 +01002263" call Decho("setl ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02002264 setl ro nomod
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002265
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002266 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002267 " NetRead: (sftp) NetRead Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002268 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002269" call Decho("read via sftp (method #9)",'~'.expand("<slnum>"))
2270 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 +00002271 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002272 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002273
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002274 ".........................................
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002275 " NetRead: (file) NetRead Method #10 {{{3
2276 elseif b:netrw_method == 10 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002277" " call Decho("read via ".b:netrw_file_cmd." (method #10)",'~'.expand("<slnum>"))
2278 call s:NetrwExe(s:netrw_silentxfer."!".g:netrw_file_cmd." ".s:ShellEscape(b:netrw_fname,1)." ".tmpfile)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002279 let result = s:NetrwGetFile(readcmd, tmpfile, b:netrw_method)
2280 let b:netrw_lastfile = choice
2281
2282 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002283 " NetRead: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002284 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002285 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",8)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002286 endif
2287 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002288
Bram Moolenaar5c736222010-01-06 20:54:52 +01002289 " NetRead: cleanup {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002290 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002291" call Decho("cleanup b:netrw_method and b:netrw_fname",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002292 unlet b:netrw_method
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002293 unlet b:netrw_fname
2294 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002295 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 +01002296" call Decho("cleanup by deleting tmpfile<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002297 NetrwKeepj call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002298 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002299 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar8299df92004-07-10 09:47:34 +00002300
Bram Moolenaar9964e462007-05-05 17:54:07 +00002301" call Dret("netrw#NetRead :5 getcwd<".getcwd().">")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002302endfun
2303
2304" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002305" netrw#NetWrite: responsible for writing a file over the net {{{2
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002306fun! netrw#NetWrite(...) range
Bram Moolenaar9964e462007-05-05 17:54:07 +00002307" call Dfunc("netrw#NetWrite(a:0=".a:0.") ".g:loaded_netrw)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002308
Bram Moolenaar5c736222010-01-06 20:54:52 +01002309 " NetWrite: option handling {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002310 let mod= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02002311 call s:NetrwOptionsSave("w:")
2312 call s:NetrwOptionsSafe(0)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002313
Bram Moolenaar5c736222010-01-06 20:54:52 +01002314 " NetWrite: Get Temporary Filename {{{3
Bram Moolenaar9964e462007-05-05 17:54:07 +00002315 let tmpfile= s:GetTempfile("")
2316 if tmpfile == ""
2317" call Dret("netrw#NetWrite : unable to get a tempfile!")
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +00002318 return
2319 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002320
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002321 if a:0 == 0
2322 let ichoice = 0
2323 else
2324 let ichoice = 1
2325 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002326
Bram Moolenaar9964e462007-05-05 17:54:07 +00002327 let curbufname= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002328" call Decho("curbufname<".curbufname.">",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002329 if &binary
Bram Moolenaar9964e462007-05-05 17:54:07 +00002330 " For binary writes, always write entire file.
2331 " (line numbers don't really make sense for that).
2332 " Also supports the writing of tar and zip files.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002333" call Decho("(write entire file) sil exe w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002334 exe "sil NetrwKeepj w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002335 elseif g:netrw_cygwin
2336 " write (selected portion of) file to temporary
Bram Moolenaar8d043172014-01-23 14:24:41 +01002337 let cygtmpfile= substitute(tmpfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002338" 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 +01002339 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(cygtmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002340 else
2341 " write (selected portion of) file to temporary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002342" 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 +01002343 exe "sil NetrwKeepj ".a:firstline."," . a:lastline . "w! ".fnameescape(v:cmdarg)." ".fnameescape(tmpfile)
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002344 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002345
Bram Moolenaar9964e462007-05-05 17:54:07 +00002346 if curbufname == ""
Bram Moolenaar8d043172014-01-23 14:24:41 +01002347 " when the file is [No Name], and one attempts to Nwrite it, the buffer takes
Bram Moolenaar9964e462007-05-05 17:54:07 +00002348 " on the temporary file's name. Deletion of the temporary file during
2349 " cleanup then causes an error message.
2350 0file!
2351 endif
2352
Bram Moolenaar5c736222010-01-06 20:54:52 +01002353 " NetWrite: while choice loop: {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002354 while ichoice <= a:0
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002355
Bram Moolenaar9964e462007-05-05 17:54:07 +00002356 " Process arguments: {{{4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002357 " attempt to repeat with previous host-file-etc
2358 if exists("b:netrw_lastfile") && a:0 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002359" call Decho("using b:netrw_lastfile<" . b:netrw_lastfile . ">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002360 let choice = b:netrw_lastfile
2361 let ichoice= ichoice + 1
2362 else
2363 exe "let choice= a:" . ichoice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002364
Bram Moolenaar8d043172014-01-23 14:24:41 +01002365 " Reconstruct Choice when choice starts with '"'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002366 if match(choice,"?") == 0
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002367 echomsg 'NetWrite Usage:"'
2368 echomsg ':Nwrite machine:path uses rcp'
2369 echomsg ':Nwrite "machine path" uses ftp with <.netrc>'
2370 echomsg ':Nwrite "machine id password path" uses ftp'
2371 echomsg ':Nwrite dav://[user@]machine/path uses cadaver'
2372 echomsg ':Nwrite fetch://[user@]machine/path uses fetch'
2373 echomsg ':Nwrite ftp://machine[#port]/path uses ftp (autodetects <.netrc>)'
2374 echomsg ':Nwrite rcp://machine/path uses rcp'
2375 echomsg ':Nwrite rsync://[user@]machine/path uses rsync'
2376 echomsg ':Nwrite scp://[user@]machine[[:#]port]/path uses scp'
2377 echomsg ':Nwrite sftp://[user@]machine/path uses sftp'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002378 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002379 break
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002380
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002381 elseif match(choice,"^\"") != -1
2382 if match(choice,"\"$") != -1
2383 " case "..."
2384 let choice=strpart(choice,1,strlen(choice)-2)
2385 else
2386 " case "... ... ..."
2387 let choice = strpart(choice,1,strlen(choice)-1)
2388 let wholechoice = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002389
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002390 while match(choice,"\"$") == -1
2391 let wholechoice= wholechoice . " " . choice
2392 let ichoice = ichoice + 1
2393 if choice > a:0
K.Takata71d0ba02024-01-10 03:21:05 +09002394 if !exists("g:netrw_quiet")
2395 call netrw#ErrorMsg(s:ERROR,"Unbalanced string in filename '". wholechoice ."'",13)
2396 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002397" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002398 return
2399 endif
2400 let choice= a:{ichoice}
2401 endwhile
2402 let choice= strpart(wholechoice,1,strlen(wholechoice)-1) . " " . strpart(choice,0,strlen(choice)-1)
2403 endif
2404 endif
2405 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002406 let ichoice= ichoice + 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002407" call Decho("choice<" . choice . "> ichoice=".ichoice,'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002408
Bram Moolenaar9964e462007-05-05 17:54:07 +00002409 " Determine method of write (ftp, rcp, etc) {{{4
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002410 NetrwKeepj call s:NetrwMethod(choice)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002411 if !exists("b:netrw_method") || b:netrw_method < 0
2412" call Dfunc("netrw#NetWrite : unsupported method")
2413 return
2414 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002415
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002416 " =============
Bram Moolenaar5c736222010-01-06 20:54:52 +01002417 " NetWrite: Perform Protocol-Based Write {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002418 " ============================
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002419 if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1
2420 echo "(netrw) Processing your write request..."
Bram Moolenaar85850f32019-07-19 22:05:51 +02002421" call Decho("Processing your write request...",'~'.expand("<slnum>"))
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002422 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002423
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002424 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002425 " NetWrite: (rcp) NetWrite Method #1 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002426 if b:netrw_method == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002427" call Decho("write via rcp (method #1)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002428 if s:netrw_has_nt_rcp == 1
2429 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2430 let uid_machine = g:netrw_machine .'.'. g:netrw_uid
2431 else
2432 let uid_machine = g:netrw_machine .'.'. $USERNAME
2433 endif
2434 else
2435 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2436 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2437 else
2438 let uid_machine = g:netrw_machine
2439 endif
2440 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002441 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 +00002442 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002443
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002444 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002445 " NetWrite: (ftp + <.netrc>) NetWrite Method #2 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002446 elseif b:netrw_method == 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002447" call Decho("write via ftp+.netrc (method #2)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002448 let netrw_fname = b:netrw_fname
2449
2450 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2451 let bhkeep = &l:bh
2452 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002453 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002454 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002455
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002456" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02002457 setl ff=unix
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002458 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002459" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002460 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002461 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002462" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002463 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002464 NetrwKeepj call setline(line("$")+1,'put "'.tmpfile.'" "'.netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002465" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002466 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002467 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 +00002468 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002469" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
2470 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 endif
2472 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2473 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002474 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002475 NetrwKeepj call netrw#ErrorMsg(s:ERROR,getline(1),14)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002476 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002477 let mod=1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002479
2480 " remove enew buffer (quietly)
2481 let filtbuf= bufnr("%")
2482 exe curbuf."b!"
2483 let &l:bh = bhkeep
2484 exe filtbuf."bw!"
2485
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002487
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002488 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002489 " NetWrite: (ftp + machine, id, passwd, filename) NetWrite Method #3 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002490 elseif b:netrw_method == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01002491 " Construct execution string (three or more lines) which will be passed through filter
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002492" call Decho("read via ftp+mipf (method #3)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002493 let netrw_fname = b:netrw_fname
2494 let bhkeep = &l:bh
2495
2496 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2497 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002498 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002499 keepj keepalt enew
Bram Moolenaarff034192013-04-24 18:51:19 +02002500 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002501
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002502 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002503 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002504" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002505 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002506 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002507" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002508 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002509 if exists("g:netrw_uid") && g:netrw_uid != ""
2510 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002511 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002512" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002513 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002514 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002515 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002516" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002517 elseif exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002518 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002519" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002520 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002521 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002522 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002523" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002524 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002525 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002526" call Decho("filter input: ".getline("$"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002527 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002528 NetrwKeepj put ='put \"'.tmpfile.'\" \"'.netrw_fname.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002529" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002530 " save choice/id/password for future use
2531 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002532
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002533 " perform ftp:
2534 " -i : turns off interactive prompting from ftp
2535 " -n unix : DON'T use <.netrc>, even though it exists
2536 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01002537 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002538 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002539 " If the result of the ftp operation isn't blank, show an error message (tnx to Doug Claar)
2540 if getline(1) !~ "^$"
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002541 if !exists("g:netrw_quiet")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002542 call netrw#ErrorMsg(s:ERROR,getline(1),15)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002543 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002544 let mod=1
2545 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002546
2547 " remove enew buffer (quietly)
2548 let filtbuf= bufnr("%")
2549 exe curbuf."b!"
2550 let &l:bh= bhkeep
2551 exe filtbuf."bw!"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002552
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002553 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002554 " NetWrite: (scp) NetWrite Method #4 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002555 elseif b:netrw_method == 4
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002556" call Decho("write via scp (method #4)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002557 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaarc236c162008-07-13 17:41:49 +00002558 let useport= " ".g:netrw_scpport." ".fnameescape(g:netrw_port)
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002559 else
2560 let useport= ""
2561 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002562 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 +00002563 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002564
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002565 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002566 " NetWrite: (http) NetWrite Method #5 {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002567 elseif b:netrw_method == 5
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002568" call Decho("write via http (method #5)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01002569 let curl= substitute(g:netrw_http_put_cmd,'\s\+.*$',"","")
2570 if executable(curl)
2571 let url= g:netrw_choice
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002572 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 +01002573 elseif !exists("g:netrw_quiet")
dkearns4b715bd2024-03-25 03:47:37 +11002574 call netrw#ErrorMsg(s:ERROR,"can't write to http using <".g:netrw_http_put_cmd.">",16)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00002575 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002576
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002577 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002578 " NetWrite: (dav) NetWrite Method #6 (cadaver) {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002579 elseif b:netrw_method == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002580" call Decho("write via cadaver (method #6)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002581
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002582 " Construct execution string (four lines) which will be passed through filter
Bram Moolenaar5c736222010-01-06 20:54:52 +01002583 let netrw_fname = escape(b:netrw_fname,g:netrw_fname_escape)
2584 let bhkeep = &l:bh
2585
2586 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2587 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002588 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002589 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002590
Bram Moolenaarff034192013-04-24 18:51:19 +02002591 setl ff=unix
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002592 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002593 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002594 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002595 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002596 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002597 if exists("g:netrw_uid") && exists("s:netrw_passwd") && g:netrw_uid != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002598 NetrwKeepj put ='user '.g:netrw_uid.' '.s:netrw_passwd
Bram Moolenaar446cb832008-06-24 21:56:24 +00002599 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002600 NetrwKeepj put ='put '.tmpfile.' '.netrw_fname
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002601
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002602 " perform cadaver operation:
Bram Moolenaar91359012019-11-30 17:57:03 +01002603 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002604 call s:NetrwExe(s:netrw_silentxfer."%!".g:netrw_dav_cmd)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002605
2606 " remove enew buffer (quietly)
2607 let filtbuf= bufnr("%")
2608 exe curbuf."b!"
2609 let &l:bh = bhkeep
2610 exe filtbuf."bw!"
2611
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002612 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002613
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002614 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002615 " NetWrite: (rsync) NetWrite Method #7 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002616 elseif b:netrw_method == 7
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002617" call Decho("write via rsync (method #7)",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02002618 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 +00002619 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002620
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002621 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002622 " NetWrite: (sftp) NetWrite Method #9 {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002623 elseif b:netrw_method == 9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002624" call Decho("write via sftp (method #9)",'~'.expand("<slnum>"))
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002625 let netrw_fname= escape(b:netrw_fname,g:netrw_fname_escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626 if exists("g:netrw_uid") && ( g:netrw_uid != "" )
2627 let uid_machine = g:netrw_uid .'@'. g:netrw_machine
2628 else
2629 let uid_machine = g:netrw_machine
2630 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01002631
2632 " formerly just a "new...bd!", that changed the window sizes when equalalways. Using enew workaround instead
2633 let bhkeep = &l:bh
2634 let curbuf = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02002635 setl bh=hide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002636 keepj keepalt enew
Bram Moolenaar5c736222010-01-06 20:54:52 +01002637
Bram Moolenaarff034192013-04-24 18:51:19 +02002638 setl ff=unix
Bram Moolenaar5c736222010-01-06 20:54:52 +01002639 call setline(1,'put "'.escape(tmpfile,'\').'" '.netrw_fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002640" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01002641 let sftpcmd= substitute(g:netrw_sftp_cmd,"%TEMPFILE%",escape(tmpfile,'\'),"g")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002642 call s:NetrwExe(s:netrw_silentxfer."%!".sftpcmd.' '.s:ShellEscape(uid_machine,1))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002643 let filtbuf= bufnr("%")
2644 exe curbuf."b!"
2645 let &l:bh = bhkeep
2646 exe filtbuf."bw!"
2647 let b:netrw_lastfile = choice
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002648
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002649 ".........................................
Bram Moolenaar5c736222010-01-06 20:54:52 +01002650 " NetWrite: Complain {{{3
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00002651 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002652 call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . choice . ">",17)
Bram Moolenaaradc21822011-04-01 18:03:16 +02002653 let leavemod= 1
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002655 endwhile
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002656
Bram Moolenaar5c736222010-01-06 20:54:52 +01002657 " NetWrite: Cleanup: {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002658" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002659 if s:FileReadable(tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002660" call Decho("tmpfile<".tmpfile."> readable, will now delete it",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00002661 call s:NetrwDelete(tmpfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002662 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002663 call s:NetrwOptionsRestore("w:")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002664
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002665 if a:firstline == 1 && a:lastline == line("$")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002666 " restore modifiability; usually equivalent to set nomod
K.Takataa262d3f2024-01-25 04:10:19 +09002667 let &l:mod= mod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002668" 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 +02002669 elseif !exists("leavemod")
2670 " indicate that the buffer has not been modified since last written
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002671" call Decho("set nomod",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01002672 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002673" 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 +00002674 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002675
Bram Moolenaar9964e462007-05-05 17:54:07 +00002676" call Dret("netrw#NetWrite")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002677endfun
2678
2679" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002680" netrw#NetSource: source a remotely hosted vim script {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002681" uses NetRead to get a copy of the file into a temporarily file,
2682" then sources that file,
2683" then removes that file.
2684fun! netrw#NetSource(...)
2685" call Dfunc("netrw#NetSource() a:0=".a:0)
2686 if a:0 > 0 && a:1 == '?'
2687 " give help
2688 echomsg 'NetSource Usage:'
2689 echomsg ':Nsource dav://machine[:port]/path uses cadaver'
2690 echomsg ':Nsource fetch://machine/path uses fetch'
2691 echomsg ':Nsource ftp://[user@]machine[:port]/path uses ftp autodetects <.netrc>'
Bram Moolenaar15146672011-10-20 22:22:38 +02002692 echomsg ':Nsource http[s]://[user@]machine/path uses http wget'
Bram Moolenaar9964e462007-05-05 17:54:07 +00002693 echomsg ':Nsource rcp://[user@]machine/path uses rcp'
2694 echomsg ':Nsource rsync://machine[:port]/path uses rsync'
2695 echomsg ':Nsource scp://[user@]machine[[:#]port]/path uses scp'
2696 echomsg ':Nsource sftp://[user@]machine[[:#]port]/path uses sftp'
2697 sleep 4
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002698 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00002699 let i= 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002700 while i <= a:0
Bram Moolenaar9964e462007-05-05 17:54:07 +00002701 call netrw#NetRead(3,a:{i})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002702" call Decho("s:netread_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002703 if s:FileReadable(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002704" call Decho("exe so ".fnameescape(s:netrw_tmpfile),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00002705 exe "so ".fnameescape(s:netrw_tmpfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002706" call Decho("delete(".s:netrw_tmpfile.")",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01002707 if delete(s:netrw_tmpfile)
2708 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".s:netrw_tmpfile.">!",103)
2709 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00002710 unlet s:netrw_tmpfile
2711 else
2712 call netrw#ErrorMsg(s:ERROR,"unable to source <".a:{i}.">!",48)
2713 endif
2714 let i= i + 1
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002715 endwhile
Bram Moolenaar9964e462007-05-05 17:54:07 +00002716 endif
2717" call Dret("netrw#NetSource")
2718endfun
2719
Bram Moolenaar8d043172014-01-23 14:24:41 +01002720" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01002721" netrw#SetTreetop: resets the tree top to the current directory/specified directory {{{2
2722" (implements the :Ntree command)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002723fun! netrw#SetTreetop(iscmd,...)
Bram Moolenaara6878372014-03-22 21:02:50 +01002724
Bram Moolenaar85850f32019-07-19 22:05:51 +02002725 " iscmd==0: netrw#SetTreetop called using gn mapping
2726 " iscmd==1: netrw#SetTreetop called using :Ntree from the command line
Bram Moolenaar8d043172014-01-23 14:24:41 +01002727 " clear out the current tree
2728 if exists("w:netrw_treetop")
2729 let inittreetop= w:netrw_treetop
2730 unlet w:netrw_treetop
2731 endif
2732 if exists("w:netrw_treedict")
2733 unlet w:netrw_treedict
2734 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01002735
Bram Moolenaar85850f32019-07-19 22:05:51 +02002736 if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002737 let treedir = s:NetrwTreePath(inittreetop)
Bram Moolenaar8d043172014-01-23 14:24:41 +01002738 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002739 if isdirectory(s:NetrwFile(a:1))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002740 let treedir = a:1
2741 let s:netrw_treetop = treedir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002742 elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002743 let treedir = b:netrw_curdir."/".a:1
2744 let s:netrw_treetop = treedir
Bram Moolenaar8d043172014-01-23 14:24:41 +01002745 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002746 " normally the cursor is left in the message window.
2747 " However, here this results in the directory being listed in the message window, which is not wanted.
2748 let netrwbuf= bufnr("%")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002749 call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002750 exe bufwinnr(netrwbuf)."wincmd w"
Bram Moolenaar89a9c152021-08-29 21:55:35 +02002751 let treedir = "."
2752 let s:netrw_treetop = getcwd()
Bram Moolenaar8d043172014-01-23 14:24:41 +01002753 endif
2754 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002755
2756 " determine if treedir is remote or local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002757 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar85850f32019-07-19 22:05:51 +02002758
2759 " browse the resulting directory
Bram Moolenaara6878372014-03-22 21:02:50 +01002760 if islocal
Tom Benham64a536d2024-11-07 21:15:03 +01002761 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002762 else
Tom Benham64a536d2024-11-07 21:15:03 +01002763 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,treedir,0))
Bram Moolenaara6878372014-03-22 21:02:50 +01002764 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002765
Bram Moolenaar8d043172014-01-23 14:24:41 +01002766endfun
2767
Bram Moolenaar9964e462007-05-05 17:54:07 +00002768" ===========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +00002769" s:NetrwGetFile: Function to read temporary file "tfile" with command "readcmd". {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00002770" readcmd == %r : replace buffer with newly read file
2771" == 0r : read file at top of buffer
2772" == r : read file after current line
2773" == t : leave file in temporary form (ie. don't read into buffer)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002774fun! s:NetrwGetFile(readcmd, tfile, method)
2775" call Dfunc("NetrwGetFile(readcmd<".a:readcmd.">,tfile<".a:tfile."> method<".a:method.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002776
2777 " readcmd=='t': simply do nothing
2778 if a:readcmd == 't'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002779" 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 +01002780" call Dret("NetrwGetFile : skip read of tfile<".a:tfile.">")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002781 return
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002782 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002783
Bram Moolenaar9964e462007-05-05 17:54:07 +00002784 " get name of remote filename (ie. url and all)
2785 let rfile= bufname("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002786" call Decho("rfile<".rfile.">",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002787
Bram Moolenaar9964e462007-05-05 17:54:07 +00002788 if exists("*NetReadFixup")
2789 " for the use of NetReadFixup (not otherwise used internally)
2790 let line2= line("$")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002791 endif
2792
Bram Moolenaar9964e462007-05-05 17:54:07 +00002793 if a:readcmd[0] == '%'
2794 " get file into buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002795" call Decho("get file into buffer",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002796
2797 " rename the current buffer to the temp file (ie. tfile)
2798 if g:netrw_cygwin
Bram Moolenaar8d043172014-01-23 14:24:41 +01002799 let tfile= substitute(a:tfile,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00002800 else
2801 let tfile= a:tfile
2802 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02002803 call s:NetrwBufRename(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002804
2805 " edit temporary file (ie. read the temporary file in)
2806 if rfile =~ '\.zip$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002807" call Decho("handling remote zip file with zip#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002808 call zip#Browse(tfile)
2809 elseif rfile =~ '\.tar$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002810" call Decho("handling remote tar file with tar#Browse(tfile<".tfile.">)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002811 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002812 elseif rfile =~ '\.tar\.gz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002813" call Decho("handling remote gzip-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002814 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002815 elseif rfile =~ '\.tar\.bz2$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002816" call Decho("handling remote bz2-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002817 call tar#Browse(tfile)
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002818 elseif rfile =~ '\.tar\.xz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002819" call Decho("handling remote xz-compressed tar file",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002820 call tar#Browse(tfile)
2821 elseif rfile =~ '\.txz$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002822" call Decho("handling remote xz-compressed tar file (.txz)",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02002823 call tar#Browse(tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002824 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002825" call Decho("edit temporary file",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002826 NetrwKeepj e!
Bram Moolenaar9964e462007-05-05 17:54:07 +00002827 endif
2828
2829 " rename buffer back to remote filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02002830 call s:NetrwBufRename(rfile)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002831
Bram Moolenaar71badf92023-04-22 22:40:14 +01002832 " Jan 19, 2022: COMBAK -- bram problem with https://github.com/vim/vim/pull/9554.diff filetype
Bram Moolenaar97d62492012-11-15 21:28:22 +01002833 " Detect filetype of local version of remote file.
Bram Moolenaar5b435d62012-04-05 17:33:26 +02002834 " Note that isk must not include a "/" for scripts.vim
2835 " to process this detection correctly.
Bram Moolenaar71badf92023-04-22 22:40:14 +01002836" call Decho("detect filetype of local version of remote file<".rfile.">",'~'.expand("<slnum>"))
2837" call Decho("..did_filetype()=".did_filetype())
Christian Brabandtd8b86c92023-09-17 18:52:56 +02002838" setl ft=
Bram Moolenaar71badf92023-04-22 22:40:14 +01002839" call Decho("..initial filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
2840 let iskkeep= &isk
Bram Moolenaar97d62492012-11-15 21:28:22 +01002841 setl isk-=/
Bram Moolenaar71badf92023-04-22 22:40:14 +01002842 filetype detect
2843" call Decho("..local filetype<".&ft."> for buf#".bufnr()."<".bufname().">")
K.Takataa262d3f2024-01-25 04:10:19 +09002844 let &l:isk= iskkeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02002845" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002846 let line1 = 1
2847 let line2 = line("$")
2848
Bram Moolenaar8d043172014-01-23 14:24:41 +01002849 elseif !&ma
2850 " 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 +01002851 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"attempt to read<".a:tfile."> into a non-modifiable buffer!",94)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002852" call Dret("NetrwGetFile : attempt to read<".a:tfile."> into a non-modifiable buffer!")
Bram Moolenaar8d043172014-01-23 14:24:41 +01002853 return
2854
Bram Moolenaar9964e462007-05-05 17:54:07 +00002855 elseif s:FileReadable(a:tfile)
2856 " read file after current line
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002857" call Decho("read file<".a:tfile."> after current line",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002858 let curline = line(".")
2859 let lastline= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002860" call Decho("exe<".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)."> line#".curline,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002861 exe "NetrwKeepj ".a:readcmd." ".fnameescape(v:cmdarg)." ".fnameescape(a:tfile)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002862 let line1= curline + 1
2863 let line2= line("$") - lastline + 1
2864
2865 else
2866 " not readable
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002867" call Decho(" ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
2868" call Decho("tfile<".a:tfile."> not readable",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002869 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"file <".a:tfile."> not readable",9)
Bram Moolenaar446cb832008-06-24 21:56:24 +00002870" call Dret("NetrwGetFile : tfile<".a:tfile."> not readable")
Bram Moolenaar9964e462007-05-05 17:54:07 +00002871 return
2872 endif
2873
2874 " User-provided (ie. optional) fix-it-up command
2875 if exists("*NetReadFixup")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002876" call Decho("calling NetReadFixup(method<".a:method."> line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002877 NetrwKeepj call NetReadFixup(a:method, line1, line2)
Bram Moolenaar9964e462007-05-05 17:54:07 +00002878" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002879" call Decho("NetReadFixup() not called, doesn't exist (line1=".line1." line2=".line2.")",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00002880 endif
2881
Bram Moolenaaradc21822011-04-01 18:03:16 +02002882 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00002883 " update the Buffers menu
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002884 NetrwKeepj call s:UpdateBuffersMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00002885 endif
2886
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002887" 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 +00002888
2889 " make sure file is being displayed
Bram Moolenaar446cb832008-06-24 21:56:24 +00002890" redraw!
2891
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002892" 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 +00002893" call Dret("NetrwGetFile")
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002894endfun
2895
Bram Moolenaar9964e462007-05-05 17:54:07 +00002896" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00002897" s:NetrwMethod: determine method of transfer {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01002898" Input:
2899" choice = url [protocol:]//[userid@]hostname[:port]/[path-to-file]
2900" Output:
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002901" b:netrw_method= 1: rcp
2902" 2: ftp + <.netrc>
2903" 3: ftp + machine, id, password, and [path]filename
2904" 4: scp
2905" 5: http[s] (wget)
Bram Moolenaar5c736222010-01-06 20:54:52 +01002906" 6: dav
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002907" 7: rsync
2908" 8: fetch
2909" 9: sftp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002910" 10: file
Bram Moolenaar5c736222010-01-06 20:54:52 +01002911" g:netrw_machine= hostname
2912" b:netrw_fname = filename
2913" g:netrw_port = optional port number (for ftp)
2914" g:netrw_choice = copy of input url (choice)
2915fun! s:NetrwMethod(choice)
Bram Moolenaar85850f32019-07-19 22:05:51 +02002916" call Dfunc("s:NetrwMethod(a:choice<".a:choice.">)")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002917
Bram Moolenaar251e1912011-06-19 05:09:16 +02002918 " sanity check: choice should have at least three slashes in it
2919 if strlen(substitute(a:choice,'[^/]','','g')) < 3
2920 call netrw#ErrorMsg(s:ERROR,"not a netrw-style url; netrw uses protocol://[user@]hostname[:port]/[path])",78)
2921 let b:netrw_method = -1
Bram Moolenaar85850f32019-07-19 22:05:51 +02002922" call Dret("s:NetrwMethod : incorrect url format<".a:choice.">")
Bram Moolenaar251e1912011-06-19 05:09:16 +02002923 return
2924 endif
2925
Bram Moolenaar5c736222010-01-06 20:54:52 +01002926 " record current g:netrw_machine, if any
2927 " curmachine used if protocol == ftp and no .netrc
2928 if exists("g:netrw_machine")
2929 let curmachine= g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002930" call Decho("curmachine<".curmachine.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01002931 else
2932 let curmachine= "N O T A HOST"
2933 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02002934 if exists("g:netrw_port")
2935 let netrw_port= g:netrw_port
2936 endif
2937
2938 " insure that netrw_ftp_cmd starts off every method determination
2939 " with the current g:netrw_ftp_cmd
2940 let s:netrw_ftp_cmd= g:netrw_ftp_cmd
Bram Moolenaar5c736222010-01-06 20:54:52 +01002941
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002942 " initialization
2943 let b:netrw_method = 0
2944 let g:netrw_machine = ""
2945 let b:netrw_fname = ""
2946 let g:netrw_port = ""
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002947 let g:netrw_choice = a:choice
2948
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002949 " Patterns:
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002950 " mipf : a:machine a:id password filename Use ftp
Bram Moolenaar446cb832008-06-24 21:56:24 +00002951 " mf : a:machine filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
2952 " ftpurm : ftp://[user@]host[[#:]port]/filename Use ftp + <.netrc> or g:netrw_uid s:netrw_passwd
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002953 " rcpurm : rcp://[user@]host/filename Use rcp
2954 " rcphf : [user@]host:filename Use rcp
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002955 " scpurm : scp://[user@]host[[#:]port]/filename Use scp
Bram Moolenaar15146672011-10-20 22:22:38 +02002956 " httpurm : http[s]://[user@]host/filename Use wget
Bram Moolenaar5c736222010-01-06 20:54:52 +01002957 " davurm : dav[s]://host[:port]/path Use cadaver/curl
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002958 " rsyncurm : rsync://host[:port]/path Use rsync
2959 " fetchurm : fetch://[user@]host[:http]/filename Use fetch (defaults to ftp, override for http)
2960 " sftpurm : sftp://[user@]host/filename Use scp
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002961 " fileurm : file://[user@]host/filename Use elinks or links
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002962 let mipf = '^\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)\s\+\(\S\+\)$'
2963 let mf = '^\(\S\+\)\s\+\(\S\+\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002964 let ftpurm = '^ftp://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\([#:]\d\+\)\=/\(.*\)$'
2965 let rcpurm = '^rcp://\%(\([^/]*\)@\)\=\([^/]\{-}\)/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002966 let rcphf = '^\(\(\h\w*\)@\)\=\(\h\w*\):\([^@]\+\)$'
Bram Moolenaar1afcace2005-11-25 19:54:28 +00002967 let scpurm = '^scp://\([^/#:]\+\)\%([#:]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002968 let httpurm = '^https\=://\([^/]\{-}\)\(/.*\)\=$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00002969 let davurm = '^davs\=://\([^/]\+\)/\(.*/\)\([-_.~[:alnum:]]\+\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002970 let rsyncurm = '^rsync://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar15146672011-10-20 22:22:38 +02002971 let fetchurm = '^fetch://\(\([^/]*\)@\)\=\([^/#:]\{-}\)\(:http\)\=/\(.*\)$'
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002972 let sftpurm = '^sftp://\([^/]\{-}\)/\(.*\)\=$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01002973 let fileurm = '^file\=://\(.*\)$'
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002974
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002975" call Decho("determine method:",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002976 " Determine Method
Bram Moolenaaradc21822011-04-01 18:03:16 +02002977 " Method#1: rcp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002978 if match(a:choice,rcpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002979" call Decho("rcp://...",'~'.expand("<slnum>"))
Bram Moolenaar83bab712005-08-01 21:58:57 +00002980 let b:netrw_method = 1
2981 let userid = substitute(a:choice,rcpurm,'\1',"")
2982 let g:netrw_machine = substitute(a:choice,rcpurm,'\2',"")
2983 let b:netrw_fname = substitute(a:choice,rcpurm,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002984 if userid != ""
2985 let g:netrw_uid= userid
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002987
Bram Moolenaaradc21822011-04-01 18:03:16 +02002988 " Method#4: scp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002989 elseif match(a:choice,scpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002990" call Decho("scp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00002991 let b:netrw_method = 4
Bram Moolenaar83bab712005-08-01 21:58:57 +00002992 let g:netrw_machine = substitute(a:choice,scpurm,'\1',"")
2993 let g:netrw_port = substitute(a:choice,scpurm,'\2',"")
2994 let b:netrw_fname = substitute(a:choice,scpurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00002995
Bram Moolenaar15146672011-10-20 22:22:38 +02002996 " Method#5: http[s]://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002997 elseif match(a:choice,httpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01002998" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00002999 let b:netrw_method = 5
3000 let g:netrw_machine= substitute(a:choice,httpurm,'\1',"")
3001 let b:netrw_fname = substitute(a:choice,httpurm,'\2',"")
Bram Moolenaara6878372014-03-22 21:02:50 +01003002 let b:netrw_http = (a:choice =~ '^https:')? "https" : "http"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003003
Bram Moolenaaradc21822011-04-01 18:03:16 +02003004 " Method#6: dav://hostname[:port]/..path-to-file.. {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003005 elseif match(a:choice,davurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003006" call Decho("dav://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003007 let b:netrw_method= 6
Bram Moolenaar15146672011-10-20 22:22:38 +02003008 if a:choice =~ 'davs:'
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003009 let g:netrw_machine= 'https://'.substitute(a:choice,davurm,'\1/\2',"")
3010 else
3011 let g:netrw_machine= 'http://'.substitute(a:choice,davurm,'\1/\2',"")
3012 endif
3013 let b:netrw_fname = substitute(a:choice,davurm,'\3',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003014
Bram Moolenaaradc21822011-04-01 18:03:16 +02003015 " Method#7: rsync://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003016 elseif match(a:choice,rsyncurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003017" call Decho("rsync://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003018 let b:netrw_method = 7
3019 let g:netrw_machine= substitute(a:choice,rsyncurm,'\1',"")
3020 let b:netrw_fname = substitute(a:choice,rsyncurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003021
Bram Moolenaaradc21822011-04-01 18:03:16 +02003022 " Methods 2,3: ftp://[user@]hostname[[:#]port]/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003023 elseif match(a:choice,ftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003024" call Decho("ftp://...",'~'.expand("<slnum>"))
Bram Moolenaar578b49e2005-09-10 19:22:57 +00003025 let userid = substitute(a:choice,ftpurm,'\2',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003026 let g:netrw_machine= substitute(a:choice,ftpurm,'\3',"")
3027 let g:netrw_port = substitute(a:choice,ftpurm,'\4',"")
3028 let b:netrw_fname = substitute(a:choice,ftpurm,'\5',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003029" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003030 if userid != ""
3031 let g:netrw_uid= userid
3032 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003033
Bram Moolenaaradc21822011-04-01 18:03:16 +02003034 if curmachine != g:netrw_machine
Bram Moolenaar85850f32019-07-19 22:05:51 +02003035 if exists("s:netrw_hup[".g:netrw_machine."]")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003036 call NetUserPass("ftp:".g:netrw_machine)
3037 elseif exists("s:netrw_passwd")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003038 " if there's a change in hostname, require password re-entry
3039 unlet s:netrw_passwd
3040 endif
3041 if exists("netrw_port")
3042 unlet netrw_port
3043 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003044 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003045
Bram Moolenaar446cb832008-06-24 21:56:24 +00003046 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003047 let b:netrw_method = 3
3048 else
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003049 let host= substitute(g:netrw_machine,'\..*$','','')
3050 if exists("s:netrw_hup[host]")
3051 call NetUserPass("ftp:".host)
3052
Nir Lichtman1e34b952024-05-08 19:19:34 +02003053 elseif has("win32") && s:netrw_ftp_cmd =~# '-[sS]:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003054" call Decho("has -s: : s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
3055" call Decho(" g:netrw_ftp_cmd<".g:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003056 if g:netrw_ftp_cmd =~# '-[sS]:\S*MACHINE\>'
Bram Moolenaare6ae6222013-05-21 21:01:10 +02003057 let s:netrw_ftp_cmd= substitute(g:netrw_ftp_cmd,'\<MACHINE\>',g:netrw_machine,'')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003058" call Decho("s:netrw_ftp_cmd<".s:netrw_ftp_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003059 endif
3060 let b:netrw_method= 2
3061 elseif s:FileReadable(expand("$HOME/.netrc")) && !g:netrw_ignorenetrc
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003062" call Decho("using <".expand("$HOME/.netrc")."> (readable)",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003063 let b:netrw_method= 2
3064 else
3065 if !exists("g:netrw_uid") || g:netrw_uid == ""
3066 call NetUserPass()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003067 elseif !exists("s:netrw_passwd") || s:netrw_passwd == ""
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003068 call NetUserPass(g:netrw_uid)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003069 " else just use current g:netrw_uid and s:netrw_passwd
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003070 endif
3071 let b:netrw_method= 3
3072 endif
3073 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003074
Bram Moolenaaradc21822011-04-01 18:03:16 +02003075 " Method#8: fetch {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003076 elseif match(a:choice,fetchurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003077" call Decho("fetch://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003078 let b:netrw_method = 8
3079 let g:netrw_userid = substitute(a:choice,fetchurm,'\2',"")
3080 let g:netrw_machine= substitute(a:choice,fetchurm,'\3',"")
3081 let b:netrw_option = substitute(a:choice,fetchurm,'\4',"")
3082 let b:netrw_fname = substitute(a:choice,fetchurm,'\5',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003083
Bram Moolenaaradc21822011-04-01 18:03:16 +02003084 " Method#3: Issue an ftp : "machine id password [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003085 elseif match(a:choice,mipf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003086" call Decho("(ftp) host id pass file",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 let b:netrw_method = 3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003088 let g:netrw_machine = substitute(a:choice,mipf,'\1',"")
3089 let g:netrw_uid = substitute(a:choice,mipf,'\2',"")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003090 let s:netrw_passwd = substitute(a:choice,mipf,'\3',"")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003091 let b:netrw_fname = substitute(a:choice,mipf,'\4',"")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003092 call NetUserPass(g:netrw_machine,g:netrw_uid,s:netrw_passwd)
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003093
Bram Moolenaaradc21822011-04-01 18:03:16 +02003094 " Method#3: Issue an ftp: "hostname [path/]filename" {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003095 elseif match(a:choice,mf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003096" call Decho("(ftp) host file",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003097 if exists("g:netrw_uid") && exists("s:netrw_passwd")
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003098 let b:netrw_method = 3
3099 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3100 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003101
Bram Moolenaar9964e462007-05-05 17:54:07 +00003102 elseif s:FileReadable(expand("$HOME/.netrc"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003103 let b:netrw_method = 2
3104 let g:netrw_machine = substitute(a:choice,mf,'\1',"")
3105 let b:netrw_fname = substitute(a:choice,mf,'\2',"")
3106 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003107
Bram Moolenaaradc21822011-04-01 18:03:16 +02003108 " Method#9: sftp://user@hostname/...path-to-file {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003109 elseif match(a:choice,sftpurm) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003110" call Decho("sftp://...",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003111 let b:netrw_method = 9
3112 let g:netrw_machine= substitute(a:choice,sftpurm,'\1',"")
3113 let b:netrw_fname = substitute(a:choice,sftpurm,'\2',"")
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003114
Bram Moolenaaradc21822011-04-01 18:03:16 +02003115 " Method#1: Issue an rcp: hostname:filename" (this one should be last) {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003116 elseif match(a:choice,rcphf) == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003117" call Decho("(rcp) [user@]host:file) rcphf<".rcphf.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003118 let b:netrw_method = 1
3119 let userid = substitute(a:choice,rcphf,'\2',"")
3120 let g:netrw_machine = substitute(a:choice,rcphf,'\3',"")
3121 let b:netrw_fname = substitute(a:choice,rcphf,'\4',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003122" call Decho('\1<'.substitute(a:choice,rcphf,'\1',"").">",'~'.expand("<slnum>"))
3123" call Decho('\2<'.substitute(a:choice,rcphf,'\2',"").">",'~'.expand("<slnum>"))
3124" call Decho('\3<'.substitute(a:choice,rcphf,'\3',"").">",'~'.expand("<slnum>"))
3125" call Decho('\4<'.substitute(a:choice,rcphf,'\4',"").">",'~'.expand("<slnum>"))
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003126 if userid != ""
3127 let g:netrw_uid= userid
3128 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003129
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003130 " Method#10: file://user@hostname/...path-to-file {{{3
3131 elseif match(a:choice,fileurm) == 0 && exists("g:netrw_file_cmd")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003132" call Decho("http[s]://...",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003133 let b:netrw_method = 10
3134 let b:netrw_fname = substitute(a:choice,fileurm,'\1',"")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003135" call Decho('\1<'.substitute(a:choice,fileurm,'\1',"").">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003136
Bram Moolenaaradc21822011-04-01 18:03:16 +02003137 " Cannot Determine Method {{{3
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003138 else
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003139 if !exists("g:netrw_quiet")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003140 call netrw#ErrorMsg(s:WARNING,"cannot determine method (format: protocol://[user@]hostname[:port]/[path])",45)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003141 endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003142 let b:netrw_method = -1
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003144 "}}}3
Bram Moolenaar81695252004-12-29 20:58:21 +00003145
Bram Moolenaar81695252004-12-29 20:58:21 +00003146 if g:netrw_port != ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02003147 " remove any leading [:#] from port number
3148 let g:netrw_port = substitute(g:netrw_port,'[#:]\+','','')
3149 elseif exists("netrw_port")
3150 " retain port number as implicit for subsequent ftp operations
3151 let g:netrw_port= netrw_port
Bram Moolenaar81695252004-12-29 20:58:21 +00003152 endif
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003153
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003154" call Decho("a:choice <".a:choice.">",'~'.expand("<slnum>"))
3155" call Decho("b:netrw_method <".b:netrw_method.">",'~'.expand("<slnum>"))
3156" call Decho("g:netrw_machine<".g:netrw_machine.">",'~'.expand("<slnum>"))
3157" call Decho("g:netrw_port <".g:netrw_port.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003158" if exists("g:netrw_uid") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003159" call Decho("g:netrw_uid <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003160" endif "Decho
Bram Moolenaar446cb832008-06-24 21:56:24 +00003161" if exists("s:netrw_passwd") "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003162" call Decho("s:netrw_passwd <".s:netrw_passwd.">",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003163" endif "Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003164" call Decho("b:netrw_fname <".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003165" call Dret("s:NetrwMethod : b:netrw_method=".b:netrw_method." g:netrw_port=".g:netrw_port)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167
Bram Moolenaar9964e462007-05-05 17:54:07 +00003168" ---------------------------------------------------------------------
Bram Moolenaarafeb4fa2006-02-01 21:51:12 +00003169" NetUserPass: set username and password for subsequent ftp transfer {{{2
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003170" Usage: :call NetUserPass() -- will prompt for userid and password
3171" :call NetUserPass("uid") -- will prompt for password
3172" :call NetUserPass("uid","password") -- sets global userid and password
3173" :call NetUserPass("ftp:host") -- looks up userid and password using hup dictionary
3174" :call NetUserPass("host","uid","password") -- sets hup dictionary with host, userid, password
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175fun! NetUserPass(...)
3176
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003177" call Dfunc("NetUserPass() a:0=".a:0)
3178
3179 if !exists('s:netrw_hup')
3180 let s:netrw_hup= {}
3181 endif
3182
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 if a:0 == 0
Bram Moolenaar97d62492012-11-15 21:28:22 +01003184 " case: no input arguments
3185
3186 " change host and username if not previously entered; get new password
3187 if !exists("g:netrw_machine")
3188 let g:netrw_machine= input('Enter hostname: ')
3189 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190 if !exists("g:netrw_uid") || g:netrw_uid == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01003191 " get username (user-id) via prompt
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192 let g:netrw_uid= input('Enter username: ')
3193 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003194 " get password via prompting
Bram Moolenaar446cb832008-06-24 21:56:24 +00003195 let s:netrw_passwd= inputsecret("Enter Password: ")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003196
3197 " set up hup database
3198 let host = substitute(g:netrw_machine,'\..*$','','')
3199 if !exists('s:netrw_hup[host]')
3200 let s:netrw_hup[host]= {}
3201 endif
3202 let s:netrw_hup[host].uid = g:netrw_uid
3203 let s:netrw_hup[host].passwd = s:netrw_passwd
3204
3205 elseif a:0 == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01003206 " case: one input argument
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003207
3208 if a:1 =~ '^ftp:'
Bram Moolenaar97d62492012-11-15 21:28:22 +01003209 " get host from ftp:... url
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003210 " access userid and password from hup (host-user-passwd) dictionary
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003211" call Decho("case a:0=1: a:1<".a:1."> (get host from ftp:... url)",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003212 let host = substitute(a:1,'^ftp:','','')
3213 let host = substitute(host,'\..*','','')
3214 if exists("s:netrw_hup[host]")
3215 let g:netrw_uid = s:netrw_hup[host].uid
3216 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003217" call Decho("get s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3218" call Decho("get s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003219 else
3220 let g:netrw_uid = input("Enter UserId: ")
3221 let s:netrw_passwd = inputsecret("Enter Password: ")
3222 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003223
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003224 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01003225 " case: one input argument, not an url. Using it as a new user-id.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003226" 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 +02003227 if exists("g:netrw_machine")
Bram Moolenaara6878372014-03-22 21:02:50 +01003228 if g:netrw_machine =~ '[0-9.]\+'
3229 let host= g:netrw_machine
3230 else
3231 let host= substitute(g:netrw_machine,'\..*$','','')
3232 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003233 else
3234 let g:netrw_machine= input('Enter hostname: ')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003235 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003236 let g:netrw_uid = a:1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003237" call Decho("set g:netrw_uid= <".g:netrw_uid.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01003238 if exists("g:netrw_passwd")
3239 " ask for password if one not previously entered
3240 let s:netrw_passwd= g:netrw_passwd
3241 else
3242 let s:netrw_passwd = inputsecret("Enter Password: ")
3243 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003244 endif
3245
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003246" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003247 if exists("host")
3248 if !exists('s:netrw_hup[host]')
3249 let s:netrw_hup[host]= {}
3250 endif
3251 let s:netrw_hup[host].uid = g:netrw_uid
3252 let s:netrw_hup[host].passwd = s:netrw_passwd
3253 endif
3254
3255 elseif a:0 == 2
3256 let g:netrw_uid = a:1
3257 let s:netrw_passwd = a:2
3258
3259 elseif a:0 == 3
3260 " enter hostname, user-id, and password into the hup dictionary
3261 let host = substitute(a:1,'^\a\+:','','')
3262 let host = substitute(host,'\..*$','','')
3263 if !exists('s:netrw_hup[host]')
3264 let s:netrw_hup[host]= {}
3265 endif
3266 let s:netrw_hup[host].uid = a:2
3267 let s:netrw_hup[host].passwd = a:3
3268 let g:netrw_uid = s:netrw_hup[host].uid
3269 let s:netrw_passwd = s:netrw_hup[host].passwd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003270" call Decho("set s:netrw_hup[".host."].uid <".s:netrw_hup[host].uid.">",'~'.expand("<slnum>"))
3271" call Decho("set s:netrw_hup[".host."].passwd<".s:netrw_hup[host].passwd.">",'~'.expand("<slnum>"))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272 endif
Bram Moolenaar1afcace2005-11-25 19:54:28 +00003273
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003274" call Dret("NetUserPass : uid<".g:netrw_uid."> passwd<".s:netrw_passwd.">")
Bram Moolenaar071d4272004-06-13 20:20:40 +00003275endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276
Bram Moolenaar85850f32019-07-19 22:05:51 +02003277" =================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00003278" Shared Browsing Support: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003279" =================================
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00003281" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003282" s:ExplorePatHls: converts an Explore pattern into a regular expression search pattern {{{2
3283fun! s:ExplorePatHls(pattern)
3284" call Dfunc("s:ExplorePatHls(pattern<".a:pattern.">)")
3285 let repat= substitute(a:pattern,'^**/\{1,2}','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003286" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003287 let repat= escape(repat,'][.\')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003288" call Decho("repat<".repat.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003289 let repat= '\<'.substitute(repat,'\*','\\(\\S\\+ \\)*\\S\\+','g').'\>'
3290" call Dret("s:ExplorePatHls repat<".repat.">")
3291 return repat
Bram Moolenaar9964e462007-05-05 17:54:07 +00003292endfun
3293
3294" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01003295" s:NetrwBookHistHandler: {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003296" 0: (user: <mb>) bookmark current directory
3297" 1: (user: <gb>) change to the bookmarked directory
3298" 2: (user: <qb>) list bookmarks
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003299" 3: (browsing) records current directory history
3300" 4: (user: <u>) go up (previous) directory, using history
3301" 5: (user: <U>) go down (next) directory, using history
Bram Moolenaar446cb832008-06-24 21:56:24 +00003302" 6: (user: <mB>) delete bookmark
Bram Moolenaar5c736222010-01-06 20:54:52 +01003303fun! s:NetrwBookHistHandler(chg,curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003304" 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 +02003305 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
3306" " call Dret("s:NetrwBookHistHandler - suppressed due to g:netrw_dirhistmax")
3307 return
3308 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003309
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003310 let ykeep = @@
3311 let curbufnr = bufnr("%")
3312
Bram Moolenaar9964e462007-05-05 17:54:07 +00003313 if a:chg == 0
3314 " bookmark the current directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003315" call Decho("(user: <b>) bookmark the current directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003316 if exists("s:netrwmarkfilelist_{curbufnr}")
3317 call s:NetrwBookmark(0)
3318 echo "bookmarked marked files"
3319 else
3320 call s:MakeBookmark(a:curdir)
3321 echo "bookmarked the current directory"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003322 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003323
KSR-Yasudaf4498252023-10-06 03:34:17 +09003324 try
3325 call s:NetrwBookHistSave()
3326 catch
3327 endtry
3328
Bram Moolenaar9964e462007-05-05 17:54:07 +00003329 elseif a:chg == 1
3330 " change to the bookmarked directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003331" call Decho("(user: <".v:count."gb>) change to the bookmarked directory",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003332 if exists("g:netrw_bookmarklist[v:count-1]")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003333" call Decho("(user: <".v:count."gb>) bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003334 exe "NetrwKeepj e ".fnameescape(g:netrw_bookmarklist[v:count-1])
Bram Moolenaar9964e462007-05-05 17:54:07 +00003335 else
3336 echomsg "Sorry, bookmark#".v:count." doesn't exist!"
3337 endif
3338
3339 elseif a:chg == 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003340" redraw!
Bram Moolenaar9964e462007-05-05 17:54:07 +00003341 let didwork= 0
3342 " list user's bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003343" call Decho("(user: <q>) list user's bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003344 if exists("g:netrw_bookmarklist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003345" call Decho('list '.len(g:netrw_bookmarklist).' bookmarks','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003346 let cnt= 1
3347 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003348" call Decho("Netrw Bookmark#".cnt.": ".g:netrw_bookmarklist[cnt-1],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003349 echo printf("Netrw Bookmark#%-2d: %s",cnt,g:netrw_bookmarklist[cnt-1])
Bram Moolenaar5c736222010-01-06 20:54:52 +01003350 let didwork = 1
3351 let cnt = cnt + 1
3352 endfor
Bram Moolenaar9964e462007-05-05 17:54:07 +00003353 endif
3354
3355 " list directory history
Bram Moolenaar85850f32019-07-19 22:05:51 +02003356 " Note: history is saved only when PerformListing is done;
3357 " ie. when netrw can re-use a netrw buffer, the current directory is not saved in the history.
3358 let cnt = g:netrw_dirhistcnt
Bram Moolenaar9964e462007-05-05 17:54:07 +00003359 let first = 1
3360 let histcnt = 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003361 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003362 while ( first || cnt != g:netrw_dirhistcnt )
3363" call Decho("first=".first." cnt=".cnt." dirhistcnt=".g:netrw_dirhistcnt,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003364 if exists("g:netrw_dirhist_{cnt}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003365" call Decho("Netrw History#".histcnt.": ".g:netrw_dirhist_{cnt},'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003366 echo printf("Netrw History#%-2d: %s",histcnt,g:netrw_dirhist_{cnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003367 let didwork= 1
3368 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003369 let histcnt = histcnt + 1
3370 let first = 0
3371 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003372 if cnt < 0
3373 let cnt= cnt + g:netrw_dirhistmax
3374 endif
3375 endwhile
3376 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003377 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003378 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003379 if didwork
3380 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
3381 endif
3382
3383 elseif a:chg == 3
3384 " saves most recently visited directories (when they differ)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003385" call Decho("(browsing) record curdir history",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02003386 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 +02003387 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003388 let g:netrw_dirhistcnt = ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3389 let g:netrw_dirhist_{g:netrw_dirhistcnt} = a:curdir
Bram Moolenaaradc21822011-04-01 18:03:16 +02003390 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003391" call Decho("save dirhist#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003392 endif
3393
3394 elseif a:chg == 4
3395 " u: change to the previous directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003396" call Decho("(user: <u>) chg to prev dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003397 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003398 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - v:count1 ) % g:netrw_dirhistmax
3399 if g:netrw_dirhistcnt < 0
3400 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003401 endif
3402 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003403 let g:netrw_dirhistcnt= 0
Bram Moolenaar9964e462007-05-05 17:54:07 +00003404 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003405 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3406" call Decho("changedir u#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00003407 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003408 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003409" call Decho("setl ma noro",'~'.expand("<slnum>"))
3410 sil! NetrwKeepj %d _
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003411 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003412" call Decho("setl nomod",'~'.expand("<slnum>"))
3413" 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 +00003414 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003415" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3416 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaar9964e462007-05-05 17:54:07 +00003417 else
Bram Moolenaaradc21822011-04-01 18:03:16 +02003418 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003419 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + v:count1 ) % g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003420 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003421 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003422 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00003423 echo "Sorry, no predecessor directory exists yet"
3424 endif
3425
3426 elseif a:chg == 5
3427 " U: change to the subsequent directory stored on the history list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003428" call Decho("(user: <U>) chg to next dir from history",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003429 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003430 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt + 1 ) % g:netrw_dirhistmax
3431 if exists("g:netrw_dirhist_{g:netrw_dirhistcnt}")
3432" call Decho("changedir U#".g:netrw_dirhistcnt."<".g:netrw_dirhist_{g:netrw_dirhistcnt}.">",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02003433 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003434" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003435 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003436 sil! NetrwKeepj %d _
3437" call Decho("removed all lines from buffer (%d)",'~'.expand("<slnum>"))
3438" call Decho("setl nomod",'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003439 setl nomod
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003440" 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 +02003441 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003442" call Decho("exe e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt}),'~'.expand("<slnum>"))
3443 exe "NetrwKeepj e! ".fnameescape(g:netrw_dirhist_{g:netrw_dirhistcnt})
Bram Moolenaaradc21822011-04-01 18:03:16 +02003444 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003445 let g:netrw_dirhistcnt= ( g:netrw_dirhistcnt - 1 ) % g:netrw_dirhistmax
3446 if g:netrw_dirhistcnt < 0
3447 let g:netrw_dirhistcnt= g:netrw_dirhistcnt + g:netrw_dirhistmax
Bram Moolenaaradc21822011-04-01 18:03:16 +02003448 endif
3449 echo "Sorry, no successor directory exists yet"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003450 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02003451 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003452 let g:netrw_dirhistcnt= 0
Bram Moolenaaradc21822011-04-01 18:03:16 +02003453 echo "Sorry, no successor directory exists yet (g:netrw_dirhistmax is ".g:netrw_dirhistmax.")"
Bram Moolenaar9964e462007-05-05 17:54:07 +00003454 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003455
3456 elseif a:chg == 6
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003457" call Decho("(user: <mB>) delete bookmark'd directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003458 if exists("s:netrwmarkfilelist_{curbufnr}")
3459 call s:NetrwBookmark(1)
3460 echo "removed marked files from bookmarks"
3461 else
3462 " delete the v:count'th bookmark
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003463 let iremove = v:count
3464 let dremove = g:netrw_bookmarklist[iremove - 1]
3465" call Decho("delete bookmark#".iremove."<".g:netrw_bookmarklist[iremove - 1].">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003466 call s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003467" call Decho("remove g:netrw_bookmarklist[".(iremove-1)."]<".g:netrw_bookmarklist[(iremove-1)].">",'~'.expand("<slnum>"))
3468 NetrwKeepj call remove(g:netrw_bookmarklist,iremove-1)
3469 echo "removed ".dremove." from g:netrw_bookmarklist"
3470" call Decho("g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003471 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003472" call Decho("resulting g:netrw_bookmarklist=".string(g:netrw_bookmarklist),'~'.expand("<slnum>"))
KSR-Yasudaf4498252023-10-06 03:34:17 +09003473
3474 try
3475 call s:NetrwBookHistSave()
3476 catch
3477 endtry
Bram Moolenaar9964e462007-05-05 17:54:07 +00003478 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003479 call s:NetrwBookmarkMenu()
Bram Moolenaarff034192013-04-24 18:51:19 +02003480 call s:NetrwTgtMenu()
Bram Moolenaar97d62492012-11-15 21:28:22 +01003481 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003482" call Dret("s:NetrwBookHistHandler")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003483endfun
3484
3485" ---------------------------------------------------------------------
3486" s:NetrwBookHistRead: this function reads bookmarks and history {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003487" Will source the history file (.netrwhist) only if the g:netrw_disthistmax is > 0.
Bram Moolenaar5c736222010-01-06 20:54:52 +01003488" Sister function: s:NetrwBookHistSave()
3489fun! s:NetrwBookHistRead()
3490" call Dfunc("s:NetrwBookHistRead()")
Bram Moolenaarff034192013-04-24 18:51:19 +02003491 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003492" 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 +02003493 return
3494 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003495 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02003496
3497 " read bookmarks
Bram Moolenaar5c736222010-01-06 20:54:52 +01003498 if !exists("s:netrw_initbookhist")
3499 let home = s:NetrwHome()
3500 let savefile= home."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003501 if filereadable(s:NetrwFile(savefile))
3502" call Decho("sourcing .netrwbook",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003503 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003504 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003505
3506 " read history
Bram Moolenaaradc21822011-04-01 18:03:16 +02003507 if g:netrw_dirhistmax > 0
3508 let savefile= home."/.netrwhist"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003509 if filereadable(s:NetrwFile(savefile))
3510" call Decho("sourcing .netrwhist",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003511 exe "keepalt NetrwKeepj so ".savefile
Bram Moolenaaradc21822011-04-01 18:03:16 +02003512 endif
3513 let s:netrw_initbookhist= 1
3514 au VimLeave * call s:NetrwBookHistSave()
Bram Moolenaar5c736222010-01-06 20:54:52 +01003515 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003516 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003517
Bram Moolenaar97d62492012-11-15 21:28:22 +01003518 let @@= ykeep
Bram Moolenaar85850f32019-07-19 22:05:51 +02003519" call Decho("dirhistmax=".(exists("g:netrw_dirhistmax")? g:netrw_dirhistmax : "n/a"),'~'.expand("<slnum>"))
3520" call Decho("dirhistcnt=".(exists("g:netrw_dirhistcnt")? g:netrw_dirhistcnt : "n/a"),'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003521" call Dret("s:NetrwBookHistRead")
3522endfun
3523
3524" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003525" s:NetrwBookHistSave: this function saves bookmarks and history to files {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01003526" Sister function: s:NetrwBookHistRead()
3527" I used to do this via viminfo but that appears to
3528" be unreliable for long-term storage
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003529" If g:netrw_dirhistmax is <= 0, no history or bookmarks
3530" will be saved.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003531" (s:NetrwBookHistHandler(3,...) used to record history)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003532fun! s:NetrwBookHistSave()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003533" call Dfunc("s:NetrwBookHistSave() dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt)
Bram Moolenaarff034192013-04-24 18:51:19 +02003534 if !exists("g:netrw_dirhistmax") || g:netrw_dirhistmax <= 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02003535" call Dret("s:NetrwBookHistSave : nothing saved (dirhistmax=".g:netrw_dirhistmax.")")
Bram Moolenaaradc21822011-04-01 18:03:16 +02003536 return
3537 endif
3538
Bram Moolenaar5c736222010-01-06 20:54:52 +01003539 let savefile= s:NetrwHome()."/.netrwhist"
Bram Moolenaar85850f32019-07-19 22:05:51 +02003540" call Decho("savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003541 1split
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02003542
3543 " setting up a new buffer which will become .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003544 call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003545" call Decho("case g:netrw_use_noswf=".g:netrw_use_noswf.(exists("+acd")? " +acd" : " -acd"),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003546 if g:netrw_use_noswf
3547 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000 noswf
3548 else
3549 setl cino= com= cpo-=a cpo-=A fo=nroql2 tw=0 report=10000
3550 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003551 setl nocin noai noci magic nospell nohid wig= noaw
3552 setl ma noro write
3553 if exists("+acd") | setl noacd | endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003554 sil! NetrwKeepj keepalt %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003555
Bram Moolenaar85850f32019-07-19 22:05:51 +02003556 " rename enew'd file: .netrwhist -- no attempt to merge
3557 " record dirhistmax and current dirhistcnt
3558 " save history
3559" call Decho("saving history: dirhistmax=".g:netrw_dirhistmax." dirhistcnt=".g:netrw_dirhistcnt." lastline=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02003560 sil! keepalt file .netrwhist
Bram Moolenaar5c736222010-01-06 20:54:52 +01003561 call setline(1,"let g:netrw_dirhistmax =".g:netrw_dirhistmax)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003562 call setline(2,"let g:netrw_dirhistcnt =".g:netrw_dirhistcnt)
3563 if g:netrw_dirhistmax > 0
3564 let lastline = line("$")
3565 let cnt = g:netrw_dirhistcnt
3566 let first = 1
3567 while ( first || cnt != g:netrw_dirhistcnt )
3568 let lastline= lastline + 1
3569 if exists("g:netrw_dirhist_{cnt}")
3570 call setline(lastline,'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'")
3571" call Decho("..".lastline.'let g:netrw_dirhist_'.cnt."='".g:netrw_dirhist_{cnt}."'",'~'.expand("<slnum>"))
3572 endif
3573 let first = 0
3574 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
3575 if cnt < 0
3576 let cnt= cnt + g:netrw_dirhistmax
3577 endif
3578 endwhile
3579 exe "sil! w! ".savefile
3580" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
3581 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003582
Bram Moolenaar85850f32019-07-19 22:05:51 +02003583 " save bookmarks
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003584 sil NetrwKeepj %d _
Bram Moolenaar5c736222010-01-06 20:54:52 +01003585 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != []
Bram Moolenaar85850f32019-07-19 22:05:51 +02003586" call Decho("saving bookmarks",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003587 " merge and write .netrwbook
3588 let savefile= s:NetrwHome()."/.netrwbook"
3589
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003590 if filereadable(s:NetrwFile(savefile))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003591 let booklist= deepcopy(g:netrw_bookmarklist)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003592 exe "sil NetrwKeepj keepalt so ".savefile
Bram Moolenaar5c736222010-01-06 20:54:52 +01003593 for bdm in booklist
3594 if index(g:netrw_bookmarklist,bdm) == -1
3595 call add(g:netrw_bookmarklist,bdm)
3596 endif
3597 endfor
3598 call sort(g:netrw_bookmarklist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01003599 endif
3600
3601 " construct and save .netrwbook
3602 call setline(1,"let g:netrw_bookmarklist= ".string(g:netrw_bookmarklist))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02003603 exe "sil! w! ".savefile
Bram Moolenaar85850f32019-07-19 22:05:51 +02003604" call Decho("exe sil! w! ".savefile,'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01003605 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003606
3607 " cleanup -- remove buffer used to construct history
Bram Moolenaar5c736222010-01-06 20:54:52 +01003608 let bgone= bufnr("%")
3609 q!
Bram Moolenaarff034192013-04-24 18:51:19 +02003610 exe "keepalt ".bgone."bwipe!"
Bram Moolenaar5c736222010-01-06 20:54:52 +01003611
3612" call Dret("s:NetrwBookHistSave")
Bram Moolenaar9964e462007-05-05 17:54:07 +00003613endfun
3614
3615" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003616" s:NetrwBrowse: This function uses the command in g:netrw_list_cmd to provide a {{{2
3617" list of the contents of a local or remote directory. It is assumed that the
3618" g:netrw_list_cmd has a string, USEPORT HOSTNAME, that needs to be substituted
3619" with the requested remote hostname first.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003620" Often called via: Explore/e dirname/etc -> netrw#LocalBrowseCheck() -> s:NetrwBrowse()
Bram Moolenaar446cb832008-06-24 21:56:24 +00003621fun! s:NetrwBrowse(islocal,dirname)
3622 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaara6878372014-03-22 21:02:50 +01003623
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003624 " save alternate-file's filename if w:netrw_rexlocal doesn't exist
3625 " This is useful when one edits a local file, then :e ., then :Rex
3626 if a:islocal && !exists("w:netrw_rexfile") && bufname("#") != ""
3627 let w:netrw_rexfile= bufname("#")
Bram Moolenaar5c736222010-01-06 20:54:52 +01003628 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003629
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003630 " s:NetrwBrowse : initialize history {{{3
3631 if !exists("s:netrw_initbookhist")
3632 NetrwKeepj call s:NetrwBookHistRead()
3633 endif
3634
3635 " s:NetrwBrowse : simplify the dirname (especially for ".."s in dirnames) {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003636 if a:dirname !~ '^\a\{3,}://'
Bram Moolenaar5c736222010-01-06 20:54:52 +01003637 let dirname= simplify(a:dirname)
3638 else
3639 let dirname= a:dirname
3640 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003641
Bram Moolenaar85850f32019-07-19 22:05:51 +02003642 " repoint t:netrw_lexbufnr if appropriate
3643 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02003644 let repointlexbufnr= 1
3645 endif
3646
3647 " s:NetrwBrowse : sanity checks: {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003648 if exists("s:netrw_skipbrowse")
3649 unlet s:netrw_skipbrowse
Bram Moolenaar446cb832008-06-24 21:56:24 +00003650 return
3651 endif
3652 if !exists("*shellescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003653 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing shellescape()",69)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003654 return
3655 endif
3656 if !exists("*fnameescape")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003657 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw can't run -- your vim is missing fnameescape()",70)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003658 return
3659 endif
3660
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003661 " s:NetrwBrowse : save options: {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003662 call s:NetrwOptionsSave("w:")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003663
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003664 " s:NetrwBrowse : re-instate any marked files {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003665 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3666 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003667 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3668 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003669 endif
3670
3671 if a:islocal && exists("w:netrw_acdkeep") && w:netrw_acdkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003672 " s:NetrwBrowse : set up "safe" options for local directory/file {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02003673 if s:NetrwLcd(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003674 return
3675 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003676
Bram Moolenaar5c736222010-01-06 20:54:52 +01003677 elseif !a:islocal && dirname !~ '[\/]$' && dirname !~ '^"'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003678 " s:NetrwBrowse : remote regular file handler {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003679 if bufname(dirname) != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003680 exe "NetrwKeepj b ".bufname(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +01003681 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003682 " attempt transfer of remote regular file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003683
3684 " remove any filetype indicator from end of dirname, except for the
3685 " "this is a directory" indicator (/).
3686 " There shouldn't be one of those here, anyway.
3687 let path= substitute(dirname,'[*=@|]\r\=$','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003688 call s:RemotePathAnalysis(dirname)
3689
3690 " s:NetrwBrowse : remote-read the requested file into current buffer {{{3
3691 call s:NetrwEnew(dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003692 call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003693 setl ma noro
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003694 let b:netrw_curdir = dirname
3695 let url = s:method."://".((s:user == "")? "" : s:user."@").s:machine.(s:port ? ":".s:port : "")."/".s:path
Bram Moolenaar85850f32019-07-19 22:05:51 +02003696 call s:NetrwBufRename(url)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003697 exe "sil! NetrwKeepj keepalt doau BufReadPre ".fnameescape(s:fname)
3698 sil call netrw#NetRead(2,url)
3699 " netrw.vim and tar.vim have already handled decompression of the tarball; avoiding gzip.vim error
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003700 if s:path =~ '.bz2'
3701 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.bz2$','',''))
3702 elseif s:path =~ '.gz'
3703 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.gz$','',''))
3704 elseif s:path =~ '.gz'
3705 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(substitute(s:fname,'\.txz$','',''))
3706 else
3707 exe "sil NetrwKeepj keepalt doau BufReadPost ".fnameescape(s:fname)
3708 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003709 endif
3710
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003711 " s:NetrwBrowse : save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003712 call s:SetBufWinVars()
Bram Moolenaar85850f32019-07-19 22:05:51 +02003713 call s:NetrwOptionsRestore("w:")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003714 setl ma nomod noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00003715 return
3716 endif
3717
Bram Moolenaaradc21822011-04-01 18:03:16 +02003718 " use buffer-oriented WinVars if buffer variables exist but associated window variables don't {{{3
Bram Moolenaar446cb832008-06-24 21:56:24 +00003719 call s:UseBufWinVars()
3720
3721 " set up some variables {{{3
3722 let b:netrw_browser_active = 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01003723 let dirname = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003724 let s:last_sort_by = g:netrw_sort_by
3725
3726 " set up menu {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003727 NetrwKeepj call s:NetrwMenu(1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003728
Bram Moolenaar97d62492012-11-15 21:28:22 +01003729 " get/set-up buffer {{{3
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003730 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01003731
3732 " NetrwGetBuffer might change buffers but s:rexposn_X was set for the
3733 " previous buffer
3734 let prevbufnr = bufnr('%')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003735 let reusing= s:NetrwGetBuffer(a:islocal,dirname)
Tom Benham64a536d2024-11-07 21:15:03 +01003736 if exists("s:rexposn_".prevbufnr)
3737 let s:rexposn_{bufnr('%')} = s:rexposn_{prevbufnr}
3738 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003739
Bram Moolenaar446cb832008-06-24 21:56:24 +00003740 " maintain markfile highlighting
Bram Moolenaar85850f32019-07-19 22:05:51 +02003741 if has("syntax") && exists("g:syntax_on") && g:syntax_on
3742 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02003743 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
3744 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02003745 2match none
3746 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003747 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02003748 if reusing && line("$") > 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02003749 call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003750 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003751 return
3752 endif
3753
3754 " set b:netrw_curdir to the new directory name {{{3
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02003755 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003756 if b:netrw_curdir =~ '[/\\]$'
3757 let b:netrw_curdir= substitute(b:netrw_curdir,'[/\\]$','','e')
3758 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02003759 if b:netrw_curdir =~ '\a:$' && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003760 let b:netrw_curdir= b:netrw_curdir."/"
3761 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003762 if b:netrw_curdir == ''
3763 if has("amiga")
3764 " On the Amiga, the empty string connotes the current directory
3765 let b:netrw_curdir= getcwd()
3766 else
3767 " under unix, when the root directory is encountered, the result
3768 " from the preceding substitute is an empty string.
3769 let b:netrw_curdir= '/'
3770 endif
3771 endif
3772 if !a:islocal && b:netrw_curdir !~ '/$'
3773 let b:netrw_curdir= b:netrw_curdir.'/'
3774 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003775
3776 " ------------
3777 " (local only) {{{3
3778 " ------------
3779 if a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00003780 " Set up ShellCmdPost handling. Append current buffer to browselist
3781 call s:LocalFastBrowser()
3782
3783 " handle g:netrw_keepdir: set vim's current directory to netrw's notion of the current directory {{{3
3784 if !g:netrw_keepdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003785 if !exists("&l:acd") || !&l:acd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003786 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003787 return
3788 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00003789 endif
3790 endif
3791
3792 " --------------------------------
3793 " remote handling: {{{3
3794 " --------------------------------
3795 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00003796
Bram Moolenaar97d62492012-11-15 21:28:22 +01003797 " analyze dirname and g:netrw_list_cmd {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003798 if dirname =~# "^NetrwTreeListing\>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00003799 let dirname= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00003800 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir")
3801 let dirname= substitute(b:netrw_curdir,'\\','/','g')
3802 if dirname !~ '/$'
3803 let dirname= dirname.'/'
3804 endif
3805 let b:netrw_curdir = dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003806 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01003807 let dirname = substitute(dirname,'\\','/','g')
Bram Moolenaar446cb832008-06-24 21:56:24 +00003808 endif
3809
3810 let dirpat = '^\(\w\{-}\)://\(\w\+@\)\=\([^/]\+\)/\(.*\)$'
3811 if dirname !~ dirpat
3812 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003813 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"netrw doesn't understand your dirname<".dirname.">",20)
Bram Moolenaar446cb832008-06-24 21:56:24 +00003814 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02003815 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02003816 setl noma nomod nowrap
Bram Moolenaar446cb832008-06-24 21:56:24 +00003817 return
3818 endif
3819 let b:netrw_curdir= dirname
Bram Moolenaar446cb832008-06-24 21:56:24 +00003820 endif " (additional remote handling)
3821
Bram Moolenaar85850f32019-07-19 22:05:51 +02003822 " -------------------------------
3823 " Perform Directory Listing: {{{3
3824 " -------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003825 NetrwKeepj call s:NetrwMaps(a:islocal)
3826 NetrwKeepj call s:NetrwCommands(a:islocal)
3827 NetrwKeepj call s:PerformListing(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003828
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003829 " restore option(s)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003830 call s:NetrwOptionsRestore("w:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003831
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003832 " If there is a rexposn: restore position with rexposn
3833 " Otherwise : set rexposn
3834 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003835 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
3836 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
3837 NetrwKeepj exe w:netrw_bannercnt
3838 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003839 else
3840 NetrwKeepj call s:SetRexDir(a:islocal,b:netrw_curdir)
3841 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02003842 if v:version >= 700 && has("balloon_eval") && &beval == 0 && &l:bexpr == "" && !exists("g:netrw_nobeval")
Bram Moolenaara6878372014-03-22 21:02:50 +01003843 let &l:bexpr= "netrw#BalloonHelp()"
Bram Moolenaara6878372014-03-22 21:02:50 +01003844 setl beval
Bram Moolenaaradc21822011-04-01 18:03:16 +02003845 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01003846
Bram Moolenaar85850f32019-07-19 22:05:51 +02003847 " repoint t:netrw_lexbufnr if appropriate
3848 if exists("repointlexbufnr")
3849 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02003850 endif
3851
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003852 " restore position
3853 if reusing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003854 call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01003855 endif
3856
Bram Moolenaara6878372014-03-22 21:02:50 +01003857 " The s:LocalBrowseRefresh() function is called by an autocmd
Bram Moolenaar85850f32019-07-19 22:05:51 +02003858 " installed by s:LocalFastBrowser() when g:netrw_fastbrowse <= 1 (ie. slow or medium speed).
3859 " However, s:NetrwBrowse() causes the FocusGained event to fire the first time.
Bram Moolenaar446cb832008-06-24 21:56:24 +00003860 return
3861endfun
3862
3863" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003864" s:NetrwFile: because of g:netrw_keepdir, isdirectory(), type(), etc may or {{{2
3865" may not apply correctly; ie. netrw's idea of the current directory may
3866" differ from vim's. This function insures that netrw's idea of the current
3867" directory is used.
Bram Moolenaar85850f32019-07-19 22:05:51 +02003868" Returns a path to the file specified by a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003869fun! s:NetrwFile(fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003870" "" call Dfunc("s:NetrwFile(fname<".a:fname.">) win#".winnr())
3871" "" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
3872" "" call Decho("g:netrw_cygwin =".(exists("g:netrw_cygwin")? g:netrw_cygwin : 'n/a'),'~'.expand("<slnum>"))
3873" "" call Decho("g:netrw_liststyle=".(exists("g:netrw_liststyle")? g:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
3874" "" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003875
3876 " clean up any leading treedepthstring
3877 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
3878 let fname= substitute(a:fname,'^'.s:treedepthstring.'\+','','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02003879" "" call Decho("clean up any leading treedepthstring: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003880 else
3881 let fname= a:fname
3882 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003883
3884 if g:netrw_keepdir
3885 " vim's idea of the current directory possibly may differ from netrw's
3886 if !exists("b:netrw_curdir")
3887 let b:netrw_curdir= getcwd()
3888 endif
3889
Nir Lichtman1e34b952024-05-08 19:19:34 +02003890 if !exists("g:netrw_cygwin") && has("win32")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003891 if fname =~ '^\' || fname =~ '^\a:\'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003892 " windows, but full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003893 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003894" "" call Decho("windows+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003895 else
3896 " windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003897 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003898" "" call Decho("windows+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003899 endif
3900
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003901 elseif fname =~ '^/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003902 " not windows, full path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003903 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003904" "" call Decho("unix+full path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003905 else
3906 " not windows, relative path given
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003907 let ret= s:ComposePath(b:netrw_curdir,fname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02003908" "" call Decho("unix+rltv path: isdirectory(".fname.")",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003909 endif
3910 else
3911 " vim and netrw agree on the current directory
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003912 let ret= fname
Bram Moolenaar85850f32019-07-19 22:05:51 +02003913" "" call Decho("vim and netrw agree on current directory (g:netrw_keepdir=".g:netrw_keepdir.")",'~'.expand("<slnum>"))
3914" "" call Decho("vim directory: ".getcwd(),'~'.expand("<slnum>"))
3915" "" call Decho("netrw directory: ".(exists("b:netrw_curdir")? b:netrw_curdir : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003916 endif
3917
Bram Moolenaar85850f32019-07-19 22:05:51 +02003918" "" call Dret("s:NetrwFile ".ret)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003919 return ret
3920endfun
3921
3922" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00003923" s:NetrwFileInfo: supports qf (query for file information) {{{2
3924fun! s:NetrwFileInfo(islocal,fname)
Bram Moolenaar8d043172014-01-23 14:24:41 +01003925" call Dfunc("s:NetrwFileInfo(islocal=".a:islocal." fname<".a:fname.">) b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar97d62492012-11-15 21:28:22 +01003926 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00003927 if a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003928 let lsopt= "-lsad"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003929 if g:netrw_sizestyle =~# 'H'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003930 let lsopt= "-lsadh"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003931 elseif g:netrw_sizestyle =~# 'h'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003932 let lsopt= "-lsadh --si"
3933 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003934" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00003935 if (has("unix") || has("macunix")) && executable("/bin/ls")
Bram Moolenaar8d043172014-01-23 14:24:41 +01003936
3937 if getline(".") == "../"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003938 echo system("/bin/ls ".lsopt." ".s:ShellEscape(".."))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003939" call Decho("#1: echo system(/bin/ls -lsad ".s:ShellEscape(..).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003940
Bram Moolenaara6878372014-03-22 21:02:50 +01003941 elseif w:netrw_liststyle == s:TREELIST && getline(".") !~ '^'.s:treedepthstring
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003942 echo system("/bin/ls ".lsopt." ".s:ShellEscape(b:netrw_curdir))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003943" call Decho("#2: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003944
3945 elseif exists("b:netrw_curdir")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003946 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003947" call Decho("#3: echo system(/bin/ls -lsad ".s:ShellEscape(b:netrw_curdir.a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01003948
Bram Moolenaar446cb832008-06-24 21:56:24 +00003949 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003950" call Decho('using ls '.a:fname." using cwd<".getcwd().">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003951 echo system("/bin/ls ".lsopt." ".s:ShellEscape(s:NetrwFile(a:fname)))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003952" call Decho("#5: echo system(/bin/ls -lsad ".s:ShellEscape(a:fname).")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003953 endif
3954 else
3955 " use vim functions to return information about file below cursor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003956" call Decho("using vim functions to query for file info",'~'.expand("<slnum>"))
3957 if !isdirectory(s:NetrwFile(a:fname)) && !filereadable(s:NetrwFile(a:fname)) && a:fname =~ '[*@/]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00003958 let fname= substitute(a:fname,".$","","")
3959 else
3960 let fname= a:fname
3961 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003962 let t = getftime(s:NetrwFile(fname))
3963 let sz = getfsize(s:NetrwFile(fname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003964 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +01003965 let sz= s:NetrwHumanReadable(sz)
3966 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003967 echo a:fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(s:NetrwFile(fname)))
3968" call Decho("fname.": ".sz." ".strftime(g:netrw_timefmt,getftime(fname)),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00003969 endif
3970 else
3971 echo "sorry, \"qf\" not supported yet for remote files"
3972 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01003973 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00003974" call Dret("s:NetrwFileInfo")
3975endfun
3976
3977" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02003978" s:NetrwFullPath: returns the full path to a directory and/or file {{{2
3979fun! s:NetrwFullPath(filename)
3980" " call Dfunc("s:NetrwFullPath(filename<".a:filename.">)")
3981 let filename= a:filename
3982 if filename !~ '^/'
3983 let filename= resolve(getcwd().'/'.filename)
3984 endif
3985 if filename != "/" && filename =~ '/$'
3986 let filename= substitute(filename,'/$','','')
3987 endif
3988" " call Dret("s:NetrwFullPath <".filename.">")
3989 return filename
3990endfun
3991
3992" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02003993" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00003994" returns 0=cleared buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01003995" 1=re-used buffer (buffer not cleared)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003996" 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 +00003997fun! s:NetrwGetBuffer(islocal,dirname)
3998" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02003999" 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 +02004000" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
4001" call Dredir("ls!","s:NetrwGetBuffer")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004002 let dirname= a:dirname
4003
4004 " re-use buffer if possible {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004005" call Decho("--re-use a buffer if possible--",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004006 if !exists("s:netrwbuf")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004007" call Decho(" s:netrwbuf initialized to {}",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004008 let s:netrwbuf= {}
4009 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004010" call Decho(" s:netrwbuf =".string(s:netrwbuf),'~'.expand("<slnum>"))
4011" call Decho(" w:netrw_liststyle =".(exists("w:netrw_liststyle")? w:netrw_liststyle : "n/a"),'~'.expand("<slnum>"))
4012
4013 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4014 let bufnum = -1
4015
4016 if !empty(s:netrwbuf) && has_key(s:netrwbuf,s:NetrwFullPath(dirname))
4017 if has_key(s:netrwbuf,"NetrwTreeListing")
4018 let bufnum= s:netrwbuf["NetrwTreeListing"]
4019 else
4020 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
4021 endif
4022" call Decho(" NetrwTreeListing: bufnum#".bufnum,'~'.expand("<slnum>"))
4023 if !bufexists(bufnum)
Peter Aronoffbe551da2024-09-22 11:29:40 +02004024 call remove(s:netrwbuf,"NetrwTreeListing")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004025 let bufnum= -1
4026 endif
4027 elseif bufnr("NetrwTreeListing") != -1
4028 let bufnum= bufnr("NetrwTreeListing")
4029" call Decho(" NetrwTreeListing".": bufnum#".bufnum,'~'.expand("<slnum>"))
4030 else
4031" call Decho(" did not find a NetrwTreeListing buffer",'~'.expand("<slnum>"))
4032 let bufnum= -1
4033 endif
4034
4035 elseif has_key(s:netrwbuf,s:NetrwFullPath(dirname))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004036 let bufnum= s:netrwbuf[s:NetrwFullPath(dirname)]
Bram Moolenaar85850f32019-07-19 22:05:51 +02004037" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnum,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004038 if !bufexists(bufnum)
4039 call remove(s:netrwbuf,s:NetrwFullPath(dirname))
4040 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004041 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004042
Bram Moolenaar446cb832008-06-24 21:56:24 +00004043 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004044" call Decho(" lookup netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."] not a key",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004045 let bufnum= -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004046 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004047" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
4048
Bram Moolenaar71badf92023-04-22 22:40:14 +01004049 " highjack the current buffer
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004050 " IF the buffer already has the desired name
4051 " AND it is empty
4052 let curbuf = bufname("%")
4053 if curbuf == '.'
4054 let curbuf = getcwd()
4055 endif
4056" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
Bram Moolenaar71badf92023-04-22 22:40:14 +01004057" call Decho("deciding if netrw may highjack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004058" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
4059" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
4060" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
4061" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
4062 if dirname == curbuf && line("$") == 1 && getline("%") == ""
Bram Moolenaar85850f32019-07-19 22:05:51 +02004063" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
4064 return 0
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004065 else " DEBUG
Bram Moolenaar71badf92023-04-22 22:40:14 +01004066" call Decho("..did NOT highjack buffer",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004067 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004068 " 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 +00004069
4070 " get enew buffer and name it -or- re-use buffer {{{3
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004071 if bufnum < 0 " get enew buffer and name it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004072" 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 +00004073 call s:NetrwEnew(dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004074" call Decho(" got enew buffer#".bufnr("%")." (altbuf<".expand("#").">)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004075 " name the buffer
4076 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
4077 " Got enew buffer; transform into a NetrwTreeListing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004078" call Decho("--transform enew buffer#".bufnr("%")." into a NetrwTreeListing --",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004079 let w:netrw_treebufnr = bufnr("%")
4080 call s:NetrwBufRename("NetrwTreeListing")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004081 if g:netrw_use_noswf
4082 setl nobl bt=nofile noswf
4083 else
4084 setl nobl bt=nofile
4085 endif
4086 nnoremap <silent> <buffer> [[ :sil call <SID>TreeListMove('[[')<cr>
4087 nnoremap <silent> <buffer> ]] :sil call <SID>TreeListMove(']]')<cr>
4088 nnoremap <silent> <buffer> [] :sil call <SID>TreeListMove('[]')<cr>
4089 nnoremap <silent> <buffer> ][ :sil call <SID>TreeListMove('][')<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02004090" call Decho(" tree listing bufnr=".w:netrw_treebufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004091 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004092 call s:NetrwBufRename(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004093 " enter the new buffer into the s:netrwbuf dictionary
4094 let s:netrwbuf[s:NetrwFullPath(dirname)]= bufnr("%")
4095" call Decho("update netrwbuf dictionary: s:netrwbuf[".s:NetrwFullPath(dirname)."]=".bufnr("%"),'~'.expand("<slnum>"))
4096" call Decho("netrwbuf dictionary=".string(s:netrwbuf),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004097 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004098" call Decho(" named enew buffer#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004099
4100 else " Re-use the buffer
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004101" call Decho("--re-use buffer#".bufnum." (bufnum#".bufnum.">=0 AND bufexists(".bufnum.")=".bufexists(bufnum)."!=0)",'~'.expand("<slnum>"))
Bram Moolenaar71badf92023-04-22 22:40:14 +01004102 " ignore all events
Bram Moolenaar446cb832008-06-24 21:56:24 +00004103 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01004104 setl ei=all
Bram Moolenaar71badf92023-04-22 22:40:14 +01004105
4106 if &ft == "netrw"
4107" call Decho("buffer type is netrw; not using keepalt with b ".bufnum)
4108 exe "sil! NetrwKeepj noswapfile b ".bufnum
4109" call Dredir("ls!","one")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004110 else
Bram Moolenaar71badf92023-04-22 22:40:14 +01004111" call Decho("buffer type is not netrw; using keepalt with b ".bufnum)
4112 call s:NetrwEditBuf(bufnum)
4113" call Dredir("ls!","two")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004114 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004115" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004116 if bufname("%") == '.'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004117 call s:NetrwBufRename(getcwd())
Bram Moolenaar446cb832008-06-24 21:56:24 +00004118 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01004119
4120 " restore ei
Bram Moolenaar446cb832008-06-24 21:56:24 +00004121 let &ei= eikeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004122
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004123 if line("$") <= 1 && getline(1) == ""
4124 " empty buffer
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004125 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004126" 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>"))
4127" 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 +01004128" call Dret("s:NetrwGetBuffer 0<buffer empty> : re-using buffer#".bufnr("%").", but its empty, so refresh it")
4129 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004130
Bram Moolenaar97d62492012-11-15 21:28:22 +01004131 elseif g:netrw_fastbrowse == 0 || (a:islocal && g:netrw_fastbrowse == 1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004132" call Decho("g:netrw_fastbrowse=".g:netrw_fastbrowse." a:islocal=".a:islocal.": clear buffer",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004133 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004134 sil NetrwKeepj %d _
4135" 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>"))
4136" 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 +01004137" 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 +00004138 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004139
Bram Moolenaar446cb832008-06-24 21:56:24 +00004140 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004141" call Decho("--re-use tree listing--",'~'.expand("<slnum>"))
4142" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02004143 setl ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004144 sil NetrwKeepj %d _
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004145 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004146" 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>"))
4147" 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 +01004148" 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 +00004149 return 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004150
Bram Moolenaar446cb832008-06-24 21:56:24 +00004151 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004152" 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>"))
4153" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4154" call Dret("s:NetrwGetBuffer 1<buffer not cleared>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004155 return 1
4156 endif
4157 endif
4158
4159 " do netrw settings: make this buffer not-a-file, modifiable, not line-numbered, etc {{{3
4160 " fastbrowse Local Remote Hiding a buffer implies it may be re-used (fast)
4161 " slow 0 D D Deleting a buffer implies it will not be re-used (slow)
4162 " med 1 D H
4163 " fast 2 H H
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004164" 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 +00004165 let fname= expand("%")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004166 NetrwKeepj call s:NetrwListSettings(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004167 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004168
4169 " delete all lines from buffer {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004170" call Decho("--delete all lines from buffer--",'~'.expand("<slnum>"))
4171" call Decho(" clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
4172 sil! keepalt NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004173
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004174" 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>"))
4175" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4176" call Dret("s:NetrwGetBuffer 0<cleared buffer>")
Bram Moolenaar446cb832008-06-24 21:56:24 +00004177 return 0
4178endfun
4179
4180" ---------------------------------------------------------------------
4181" s:NetrwGetcwd: get the current directory. {{{2
4182" Change backslashes to forward slashes, if any.
4183" If doesc is true, escape certain troublesome characters
4184fun! s:NetrwGetcwd(doesc)
4185" call Dfunc("NetrwGetcwd(doesc=".a:doesc.")")
4186 let curdir= substitute(getcwd(),'\\','/','ge')
4187 if curdir !~ '[\/]$'
4188 let curdir= curdir.'/'
4189 endif
4190 if a:doesc
4191 let curdir= fnameescape(curdir)
4192 endif
4193" call Dret("NetrwGetcwd <".curdir.">")
4194 return curdir
4195endfun
4196
4197" ---------------------------------------------------------------------
4198" s:NetrwGetWord: it gets the directory/file named under the cursor {{{2
4199fun! s:NetrwGetWord()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004200" call Dfunc("s:NetrwGetWord() liststyle=".s:ShowStyle()." virtcol=".virtcol("."))
4201" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
4202 let keepsol= &l:sol
4203 setl nosol
4204
Bram Moolenaar446cb832008-06-24 21:56:24 +00004205 call s:UseBufWinVars()
4206
4207 " insure that w:netrw_liststyle is set up
4208 if !exists("w:netrw_liststyle")
4209 if exists("g:netrw_liststyle")
4210 let w:netrw_liststyle= g:netrw_liststyle
4211 else
4212 let w:netrw_liststyle= s:THINLIST
4213 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004214" call Decho("w:netrw_liststyle=".w:netrw_liststyle,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004215 endif
4216
4217 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt
4218 " Active Banner support
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004219" call Decho("active banner handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004220 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004221 let dirname= "./"
4222 let curline= getline('.')
4223
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004224 if curline =~# '"\s*Sorted by\s'
Bram Moolenaar91359012019-11-30 17:57:03 +01004225 NetrwKeepj norm! "_s
Bram Moolenaar446cb832008-06-24 21:56:24 +00004226 let s:netrw_skipbrowse= 1
4227 echo 'Pressing "s" also works'
4228
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004229 elseif curline =~# '"\s*Sort sequence:'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004230 let s:netrw_skipbrowse= 1
4231 echo 'Press "S" to edit sorting sequence'
4232
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004233 elseif curline =~# '"\s*Quick Help:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004234 NetrwKeepj norm! ?
Bram Moolenaar446cb832008-06-24 21:56:24 +00004235 let s:netrw_skipbrowse= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004236
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004237 elseif curline =~# '"\s*\%(Hiding\|Showing\):'
Bram Moolenaar85850f32019-07-19 22:05:51 +02004238 NetrwKeepj norm! a
Bram Moolenaar446cb832008-06-24 21:56:24 +00004239 let s:netrw_skipbrowse= 1
4240 echo 'Pressing "a" also works'
4241
4242 elseif line("$") > w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004243 exe 'sil NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00004244 endif
4245
4246 elseif w:netrw_liststyle == s:THINLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004247" call Decho("thin column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004248 NetrwKeepj norm! 0
4249 let dirname= substitute(getline('.'),'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004250
4251 elseif w:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004252" call Decho("long column handling",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004253 NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004254 let dirname= substitute(getline('.'),'^\(\%(\S\+ \)*\S\+\).\{-}$','\1','e')
4255
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004256 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004257" call Decho("treelist handling",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004258 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004259 let dirname= substitute(dirname,'\t -->.*$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004260
4261 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004262" call Decho("obtain word from wide listing",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004263 let dirname= getline('.')
4264
4265 if !exists("b:netrw_cpf")
4266 let b:netrw_cpf= 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004267 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 +01004268 call histdel("/",-1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004269" "call Decho("computed cpf=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004270 endif
4271
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004272" call Decho("buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004273 let filestart = (virtcol(".")/b:netrw_cpf)*b:netrw_cpf
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004274" call Decho("filestart= ([virtcol=".virtcol(".")."]/[b:netrw_cpf=".b:netrw_cpf."])*b:netrw_cpf=".filestart." bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
4275" call Decho("1: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004276 if filestart == 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004277 NetrwKeepj norm! 0ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004278 else
4279 call cursor(line("."),filestart+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004280 NetrwKeepj norm! ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004281 endif
Enno3146d632024-07-04 19:44:42 +02004282
4283 let dict={}
4284 " save the unnamed register and register 0-9 and a
4285 let dict.a=[getreg('a'), getregtype('a')]
4286 for i in range(0, 9)
4287 let dict[i] = [getreg(i), getregtype(i)]
4288 endfor
4289 let dict.unnamed = [getreg(''), getregtype('')]
4290
Bram Moolenaarc236c162008-07-13 17:41:49 +00004291 let eofname= filestart + b:netrw_cpf + 1
4292 if eofname <= col("$")
4293 call cursor(line("."),filestart+b:netrw_cpf+1)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004294 NetrwKeepj norm! "ay`a
Bram Moolenaarc236c162008-07-13 17:41:49 +00004295 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004296 NetrwKeepj norm! "ay$
Bram Moolenaarc236c162008-07-13 17:41:49 +00004297 endif
Enno3146d632024-07-04 19:44:42 +02004298
Bram Moolenaar446cb832008-06-24 21:56:24 +00004299 let dirname = @a
Enno3146d632024-07-04 19:44:42 +02004300 call s:RestoreRegister(dict)
4301
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004302" call Decho("2: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004303 let dirname= substitute(dirname,'\s\+$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004304" call Decho("3: dirname<".dirname.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00004305 endif
4306
4307 " symlinks are indicated by a trailing "@". Remove it before further processing.
4308 let dirname= substitute(dirname,"@$","","")
4309
4310 " executables are indicated by a trailing "*". Remove it before further processing.
4311 let dirname= substitute(dirname,"\*$","","")
4312
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004313 let &l:sol= keepsol
4314
Bram Moolenaar446cb832008-06-24 21:56:24 +00004315" call Dret("s:NetrwGetWord <".dirname.">")
4316 return dirname
4317endfun
4318
4319" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004320" s:NetrwListSettings: make standard settings for making a netrw listing {{{2
4321" g:netrw_bufsettings will be used after the listing is produced.
4322" Called by s:NetrwGetBuffer()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004323fun! s:NetrwListSettings(islocal)
4324" call Dfunc("s:NetrwListSettings(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004325" 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 +00004326 let fname= bufname("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004327" " call Decho("setl bt=nofile nobl ma nonu nowrap noro nornu",'~'.expand("<slnum>"))
4328 " nobl noma nomod nonu noma nowrap ro nornu (std g:netrw_bufsettings)
4329 setl bt=nofile nobl ma nonu nowrap noro nornu
4330 call s:NetrwBufRename(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004331 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02004332 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00004333 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004334" call Dredir("ls!","s:NetrwListSettings")
4335" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004336 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaarff034192013-04-24 18:51:19 +02004337 setl isk+=.,~,-
Bram Moolenaar446cb832008-06-24 21:56:24 +00004338 if g:netrw_fastbrowse > a:islocal
Bram Moolenaarff034192013-04-24 18:51:19 +02004339 setl bh=hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00004340 else
Bram Moolenaarff034192013-04-24 18:51:19 +02004341 setl bh=delete
Bram Moolenaar446cb832008-06-24 21:56:24 +00004342 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004343" 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 +00004344" call Dret("s:NetrwListSettings")
4345endfun
4346
4347" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02004348" s:NetrwListStyle: change list style (thin - long - wide - tree) {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00004349" islocal=0: remote browsing
4350" =1: local browsing
4351fun! s:NetrwListStyle(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004352 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004353 let fname = s:NetrwGetWord()
4354 if !exists("w:netrw_liststyle")|let w:netrw_liststyle= g:netrw_liststyle|endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004355 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00004356 let w:netrw_liststyle = (w:netrw_liststyle + 1) % s:MAXLIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004357
Bram Moolenaar85850f32019-07-19 22:05:51 +02004358 " repoint t:netrw_lexbufnr if appropriate
4359 if exists("t:netrw_lexbufnr") && bufnr("%") == t:netrw_lexbufnr
Bram Moolenaar85850f32019-07-19 22:05:51 +02004360 let repointlexbufnr= 1
4361 endif
4362
Bram Moolenaar446cb832008-06-24 21:56:24 +00004363 if w:netrw_liststyle == s:THINLIST
4364 " use one column listing
Bram Moolenaar446cb832008-06-24 21:56:24 +00004365 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4366
4367 elseif w:netrw_liststyle == s:LONGLIST
4368 " use long list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004369 let g:netrw_list_cmd = g:netrw_list_cmd." -l"
4370
4371 elseif w:netrw_liststyle == s:WIDELIST
4372 " give wide list
Bram Moolenaar446cb832008-06-24 21:56:24 +00004373 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4374
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004375 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00004376 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4377
4378 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004379 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"bad value for g:netrw_liststyle (=".w:netrw_liststyle.")",46)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004380 let g:netrw_liststyle = s:THINLIST
4381 let w:netrw_liststyle = g:netrw_liststyle
4382 let g:netrw_list_cmd = substitute(g:netrw_list_cmd,' -l','','ge')
4383 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02004384 setl ma noro
Bram Moolenaar446cb832008-06-24 21:56:24 +00004385
4386 " clear buffer - this will cause NetrwBrowse/LocalBrowseCheck to do a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004387 sil! NetrwKeepj %d _
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004388 " following prevents tree listing buffer from being marked "modified"
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004389 setl nomod
Bram Moolenaar446cb832008-06-24 21:56:24 +00004390
4391 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01004392 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004393 NetrwKeepj call s:NetrwCursor(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004394
Bram Moolenaar85850f32019-07-19 22:05:51 +02004395 " repoint t:netrw_lexbufnr if appropriate
4396 if exists("repointlexbufnr")
4397 let t:netrw_lexbufnr= bufnr("%")
Bram Moolenaar85850f32019-07-19 22:05:51 +02004398 endif
4399
Bram Moolenaar13600302014-05-22 18:26:40 +02004400 " restore position; keep cursor on the filename
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004401" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
4402 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004403 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00004404
Bram Moolenaar446cb832008-06-24 21:56:24 +00004405endfun
4406
4407" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01004408" s:NetrwBannerCtrl: toggles the display of the banner {{{2
4409fun! s:NetrwBannerCtrl(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004410 let ykeep= @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01004411 " toggle the banner (enable/suppress)
4412 let g:netrw_banner= !g:netrw_banner
4413
4414 " refresh the listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004415 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01004416 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01004417
4418 " keep cursor on the filename
Bram Moolenaar85850f32019-07-19 22:05:51 +02004419 if g:netrw_banner && exists("w:netrw_bannercnt") && line(".") >= w:netrw_bannercnt
4420 let fname= s:NetrwGetWord()
4421 sil NetrwKeepj $
4422 let result= search('\%(^\%(|\+\s\)\=\|\s\{2,}\)\zs'.escape(fname,'.\[]*$^').'\%(\s\{2,}\|$\)','bc')
4423" " call Decho("search result=".result." w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'N/A'),'~'.expand("<slnum>"))
4424 if result <= 0 && exists("w:netrw_bannercnt")
4425 exe "NetrwKeepj ".w:netrw_bannercnt
4426 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004427 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01004428 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01004429" call Dret("s:NetrwBannerCtrl : g:netrw_banner=".g:netrw_banner)
4430endfun
4431
4432" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004433" s:NetrwBookmark: supports :NetrwMB[!] [file]s {{{2
4434"
4435" No bang: enters files/directories into Netrw's bookmark system
4436" No argument and in netrw buffer:
4437" if there are marked files: bookmark marked files
4438" otherwise : bookmark file/directory under cursor
4439" No argument and not in netrw buffer: bookmarks current open file
4440" Has arguments: globs them individually and bookmarks them
4441"
4442" With bang: deletes files/directories from Netrw's bookmark system
4443fun! s:NetrwBookmark(del,...)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004444 if a:0 == 0
4445 if &ft == "netrw"
4446 let curbufnr = bufnr("%")
4447
4448 if exists("s:netrwmarkfilelist_{curbufnr}")
4449 " for every filename in the marked list
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004450 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004451 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004452 for fname in s:netrwmarkfilelist_{curbufnr}
4453 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4454 endfor
4455 let curdir = exists("b:netrw_curdir")? b:netrw_curdir : getcwd()
4456 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01004457 NetrwKeepj call s:NetrwRefresh(islocal,s:NetrwBrowseChgDir(islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004458 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004459 else
4460 let fname= s:NetrwGetWord()
4461 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4462 endif
4463
4464 else
4465 " bookmark currently open file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004466 let fname= expand("%")
4467 if a:del|call s:DeleteBookmark(fname)|else|call s:MakeBookmark(fname)|endif
4468 endif
4469
4470 else
4471 " bookmark specified files
4472 " attempts to infer if working remote or local
4473 " by deciding if the current file begins with an url
4474 " Globbing cannot be done remotely.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004475 let islocal= expand("%") !~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004476 let i = 1
4477 while i <= a:0
4478 if islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004479 if v:version > 704 || (v:version == 704 && has("patch656"))
4480 let mbfiles= glob(fnameescape(a:{i}),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004481 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004482 let mbfiles= glob(fnameescape(a:{i}),0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004483 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004484 else
4485 let mbfiles= [a:{i}]
4486 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004487 for mbfile in mbfiles
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004488 if a:del|call s:DeleteBookmark(mbfile)|else|call s:MakeBookmark(mbfile)|endif
4489 endfor
4490 let i= i + 1
4491 endwhile
4492 endif
4493
4494 " update the menu
4495 call s:NetrwBookmarkMenu()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004496endfun
4497
4498" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004499" s:NetrwBookmarkMenu: Uses menu priorities {{{2
4500" .2.[cnt] for bookmarks, and
4501" .3.[cnt] for history
4502" (see s:NetrwMenu())
4503fun! s:NetrwBookmarkMenu()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004504 if !exists("s:netrw_menucnt")
4505 return
4506 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004507" call Dfunc("NetrwBookmarkMenu() histcnt=".g:netrw_dirhistcnt." menucnt=".s:netrw_menucnt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004508
4509 " the following test assures that gvim is running, has menus available, and has menus enabled.
Bram Moolenaaradc21822011-04-01 18:03:16 +02004510 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar9964e462007-05-05 17:54:07 +00004511 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004512" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004513 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks'
4514 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Delete'
Bram Moolenaar5c736222010-01-06 20:54:52 +01004515 endif
4516 if !exists("s:netrw_initbookhist")
4517 call s:NetrwBookHistRead()
Bram Moolenaar9964e462007-05-05 17:54:07 +00004518 endif
4519
4520 " show bookmarked places
Bram Moolenaarff034192013-04-24 18:51:19 +02004521 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaar5c736222010-01-06 20:54:52 +01004522 let cnt= 1
4523 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004524" call Decho('sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmark.'.bmd.' :e '.bmd,'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01004525 let bmd= escape(bmd,g:netrw_menu_escape)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004526
4527 " show bookmarks for goto menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004528 exe 'sil! menu '.g:NetrwMenuPriority.".2.".cnt." ".g:NetrwTopLvlMenu.'Bookmarks.'.bmd.' :e '.bmd."\<cr>"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004529
4530 " show bookmarks for deletion menu
Bram Moolenaar8d043172014-01-23 14:24:41 +01004531 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 +01004532 let cnt= cnt + 1
4533 endfor
4534
4535 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004536
4537 " show directory browsing history
Bram Moolenaaradc21822011-04-01 18:03:16 +02004538 if g:netrw_dirhistmax > 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004539 let cnt = g:netrw_dirhistcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004540 let first = 1
4541 let histcnt = 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02004542 while ( first || cnt != g:netrw_dirhistcnt )
Bram Moolenaaradc21822011-04-01 18:03:16 +02004543 let histcnt = histcnt + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004544 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaaradc21822011-04-01 18:03:16 +02004545 if exists("g:netrw_dirhist_{cnt}")
4546 let histdir= escape(g:netrw_dirhist_{cnt},g:netrw_menu_escape)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004547" call Decho('sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02004548 exe 'sil! menu '.g:NetrwMenuPriority.".3.".priority." ".g:NetrwTopLvlMenu.'History.'.histdir.' :e '.histdir."\<cr>"
4549 endif
4550 let first = 0
4551 let cnt = ( cnt - 1 ) % g:netrw_dirhistmax
4552 if cnt < 0
4553 let cnt= cnt + g:netrw_dirhistmax
4554 endif
4555 endwhile
4556 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004557
Bram Moolenaar9964e462007-05-05 17:54:07 +00004558 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004559" call Dret("NetrwBookmarkMenu")
Bram Moolenaar9964e462007-05-05 17:54:07 +00004560endfun
4561
4562" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004563" s:NetrwBrowseChgDir: constructs a new directory based on the current {{{2
4564" directory and a new directory name. Also, if the
4565" "new directory name" is actually a file,
4566" NetrwBrowseChgDir() edits the file.
Tom Benham64a536d2024-11-07 21:15:03 +01004567" cursor=0: newdir is relative to b:netrw_curdir
4568" =1: newdir is relative to the path to the word under the cursor in
4569" tree view
4570fun! s:NetrwBrowseChgDir(islocal,newdir,cursor,...)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004571 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00004572 if !exists("b:netrw_curdir")
4573 " Don't try to change-directory: this can happen, for example, when netrw#ErrorMsg has been called
4574 " and the current window is the NetrwMessage window.
Bram Moolenaar97d62492012-11-15 21:28:22 +01004575 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004576 return
Bram Moolenaar9964e462007-05-05 17:54:07 +00004577 endif
4578
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004579 " NetrwBrowseChgDir; save options and initialize {{{3
Bram Moolenaar85850f32019-07-19 22:05:51 +02004580 call s:SavePosn(s:netrw_posn)
4581 NetrwKeepj call s:NetrwOptionsSave("s:")
4582 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Tom Benham64a536d2024-11-07 21:15:03 +01004583
4584 let newdir = a:newdir
4585 if a:cursor && exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
4586 " dirname is the path to the word under the cursor
4587 let dirname = s:NetrwTreePath(w:netrw_treetop)
4588 " Remove trailing "/"
4589 let dirname = substitute(dirname, "/$", "", "")
4590
4591 " If the word under the cursor is a directory (except for ../), NetrwTreePath
4592 " returns the full path, including the word under the cursor, remove it
4593 if newdir =~ "/$" && newdir != "../"
4594 let dirname = fnamemodify(dirname, ":h")
4595 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004596 else
Bram Moolenaara6878372014-03-22 21:02:50 +01004597 let dirname = b:netrw_curdir
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004598 endif
Tom Benham64a536d2024-11-07 21:15:03 +01004599 if has("win32")
4600 let dirname = substitute(dirname,'\\','/','ge')
4601 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004602 let dolockout = 0
Bram Moolenaar13600302014-05-22 18:26:40 +02004603 let dorestore = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01004604
4605 " ignore <cr>s when done in the banner
4606 if g:netrw_banner
Bram Moolenaara6878372014-03-22 21:02:50 +01004607 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt && line("$") >= w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004608 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +01004609 let g:netrw_quickhelp= (g:netrw_quickhelp + 1)%len(s:QuickHelp)
Bram Moolenaar13600302014-05-22 18:26:40 +02004610 setl ma noro nowrap
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004611 NetrwKeepj call setline(line('.'),'" Quick Help: <F1>:help '.s:QuickHelp[g:netrw_quickhelp])
Bram Moolenaara6878372014-03-22 21:02:50 +01004612 setl noma nomod nowrap
Bram Moolenaar85850f32019-07-19 22:05:51 +02004613 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara6878372014-03-22 21:02:50 +01004614 endif
4615 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004616 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004617
Bram Moolenaar446cb832008-06-24 21:56:24 +00004618 " set up o/s-dependent directory recognition pattern
4619 if has("amiga")
4620 let dirpat= '[\/:]$'
Bram Moolenaar9964e462007-05-05 17:54:07 +00004621 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004622 let dirpat= '[\/]$'
4623 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004624
4625 if dirname !~ dirpat
4626 " apparently vim is "recognizing" that it is in a directory and
Bram Moolenaaradc21822011-04-01 18:03:16 +02004627 " is removing the trailing "/". Bad idea, so let's put it back.
Bram Moolenaar446cb832008-06-24 21:56:24 +00004628 let dirname= dirname.'/'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004629 endif
4630
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004631 if newdir !~ dirpat && !(a:islocal && isdirectory(s:NetrwFile(s:ComposePath(dirname,newdir))))
Bram Moolenaar97d62492012-11-15 21:28:22 +01004632 " ------------------------------
4633 " NetrwBrowseChgDir: edit a file {{{3
4634 " ------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004635
Bram Moolenaar97d62492012-11-15 21:28:22 +01004636 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004637 let s:rexposn_{bufnr("%")}= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01004638
Bram Moolenaar446cb832008-06-24 21:56:24 +00004639 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004640 if dirname =~ '/$'
4641 let dirname= dirname.newdir
4642 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01004643 let dirname= dirname."/".newdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004644 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004645 elseif newdir =~ '^\(/\|\a:\)'
4646 let dirname= newdir
Bram Moolenaar9964e462007-05-05 17:54:07 +00004647 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004648 let dirname= s:ComposePath(dirname,newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004649 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004650 " this lets netrw#BrowseX avoid the edit
Bram Moolenaar446cb832008-06-24 21:56:24 +00004651 if a:0 < 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02004652 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004653 let curdir= b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00004654 if !exists("s:didsplit")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004655 if type(g:netrw_browse_split) == 3
4656 " open file in server
4657 " Note that g:netrw_browse_split is a List: [servername,tabnr,winnr]
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004658 call s:NetrwServerEdit(a:islocal,dirname)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004659 return
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004660
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004661 elseif g:netrw_browse_split == 1
Bram Moolenaar97d62492012-11-15 21:28:22 +01004662 " horizontally splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004663 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
4664 exe "keepalt ".(g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004665 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004666 keepalt wincmd _
Bram Moolenaar5c736222010-01-06 20:54:52 +01004667 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004668 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004669
Bram Moolenaar446cb832008-06-24 21:56:24 +00004670 elseif g:netrw_browse_split == 2
Bram Moolenaar97d62492012-11-15 21:28:22 +01004671 " vertically splitting the window first
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004672 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
4673 exe "keepalt ".(g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar5c736222010-01-06 20:54:52 +01004674 if !&ea
Bram Moolenaarff034192013-04-24 18:51:19 +02004675 keepalt wincmd |
Bram Moolenaar5c736222010-01-06 20:54:52 +01004676 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004677 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004678
Bram Moolenaar446cb832008-06-24 21:56:24 +00004679 elseif g:netrw_browse_split == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004680 " open file in new tab
Bram Moolenaarff034192013-04-24 18:51:19 +02004681 keepalt tabnew
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004682 if !exists("b:netrw_curdir")
4683 let b:netrw_curdir= getcwd()
4684 endif
4685 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004686
Bram Moolenaar446cb832008-06-24 21:56:24 +00004687 elseif g:netrw_browse_split == 4
Bram Moolenaar97d62492012-11-15 21:28:22 +01004688 " act like "P" (ie. open previous window)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004689 if s:NetrwPrevWinOpen(2) == 3
Bram Moolenaar97d62492012-11-15 21:28:22 +01004690 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004691 return
4692 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004693 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004694
Bram Moolenaar9964e462007-05-05 17:54:07 +00004695 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004696 " handling a file, didn't split, so remove menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00004697 call s:NetrwMenu(0)
4698 " optional change to window
4699 if g:netrw_chgwin >= 1
Bram Moolenaar13600302014-05-22 18:26:40 +02004700 if winnr("$")+1 == g:netrw_chgwin
K.Takata71d0ba02024-01-10 03:21:05 +09004701 " if g:netrw_chgwin is set to one more than the last window, then
4702 " vertically split the last window to make that window available.
4703 let curwin= winnr()
4704 exe "NetrwKeepj keepalt ".winnr("$")."wincmd w"
4705 vs
4706 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd ".curwin
Bram Moolenaar13600302014-05-22 18:26:40 +02004707 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004708 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
Bram Moolenaar9964e462007-05-05 17:54:07 +00004709 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01004710 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +00004711 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004712
Bram Moolenaar9964e462007-05-05 17:54:07 +00004713 endif
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004714
Bram Moolenaar446cb832008-06-24 21:56:24 +00004715 " the point where netrw actually edits the (local) file
4716 " if its local only: LocalBrowseCheck() doesn't edit a file, but NetrwBrowse() will
Bram Moolenaar71badf92023-04-22 22:40:14 +01004717 " use keepalt to support :e # to return to a directory listing
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004718 if !&mod
4719 " if e the new file would fail due to &mod, then don't change any of the flags
4720 let dolockout= 1
4721 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004722 if a:islocal
Bram Moolenaar8d043172014-01-23 14:24:41 +01004723 " some like c-^ to return to the last edited file
4724 " others like c-^ to return to the netrw buffer
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02004725 " Apr 30, 2020: used to have e! here. That can cause loss of a modified file,
4726 " so emit error E37 instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01004727 call s:NetrwEditFile("e","",dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004728 call s:NetrwCursor(1)
Bram Moolenaar13600302014-05-22 18:26:40 +02004729 if &hidden || &bufhidden == "hide"
4730 " file came from vim's hidden storage. Don't "restore" options with it.
4731 let dorestore= 0
4732 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004733 else
Bram Moolenaar9964e462007-05-05 17:54:07 +00004734 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01004735
4736 " handle g:Netrw_funcref -- call external-to-netrw functions
4737 " This code will handle g:Netrw_funcref as an individual function reference
4738 " or as a list of function references. It will ignore anything that's not
4739 " a function reference. See :help Funcref for information about function references.
4740 if exists("g:Netrw_funcref")
4741 if type(g:Netrw_funcref) == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004742 NetrwKeepj call g:Netrw_funcref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004743 elseif type(g:Netrw_funcref) == 3
4744 for Fncref in g:Netrw_funcref
Bram Moolenaar89a9c152021-08-29 21:55:35 +02004745 if type(Fncref) == 2
4746 NetrwKeepj call Fncref()
Bram Moolenaar5c736222010-01-06 20:54:52 +01004747 endif
4748 endfor
4749 endif
4750 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004751 endif
4752
4753 elseif newdir =~ '^/'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004754 " ----------------------------------------------------
4755 " NetrwBrowseChgDir: just go to the new directory spec {{{3
4756 " ----------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004757 let dirname = newdir
4758 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004759 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004760 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004761
4762 elseif newdir == './'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004763 " ---------------------------------------------
4764 " NetrwBrowseChgDir: refresh the directory list {{{3
4765 " ---------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004766 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004767 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004768
4769 elseif newdir == '../'
Bram Moolenaar97d62492012-11-15 21:28:22 +01004770 " --------------------------------------
4771 " NetrwBrowseChgDir: go up one directory {{{3
4772 " --------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00004773
4774 if w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
4775 " force a refresh
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004776 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004777 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004778 endif
4779
4780 if has("amiga")
4781 " amiga
Bram Moolenaar446cb832008-06-24 21:56:24 +00004782 if a:islocal
4783 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+$\)','\1','')
4784 let dirname= substitute(dirname,'/$','','')
4785 else
4786 let dirname= substitute(dirname,'^\(.*[/:]\)\([^/]\+/$\)','\1','')
4787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004788
Nir Lichtman1e34b952024-05-08 19:19:34 +02004789 elseif !g:netrw_cygwin && has("win32")
Bram Moolenaar8d043172014-01-23 14:24:41 +01004790 " windows
4791 if a:islocal
4792 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4793 if dirname == ""
4794 let dirname= '/'
4795 endif
4796 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004797 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar8d043172014-01-23 14:24:41 +01004798 endif
4799 if dirname =~ '^\a:$'
4800 let dirname= dirname.'/'
4801 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01004802
Bram Moolenaar446cb832008-06-24 21:56:24 +00004803 else
4804 " unix or cygwin
Bram Moolenaar446cb832008-06-24 21:56:24 +00004805 if a:islocal
4806 let dirname= substitute(dirname,'^\(.*\)/\([^/]\+\)/$','\1','')
4807 if dirname == ""
4808 let dirname= '/'
4809 endif
4810 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004811 let dirname= substitute(dirname,'^\(\a\{3,}://.\{-}/\{1,2}\)\(.\{-}\)\([^/]\+\)/$','\1\2','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004812 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00004813 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004814 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004815 norm! m`
Bram Moolenaar446cb832008-06-24 21:56:24 +00004816
4817 elseif exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaar97d62492012-11-15 21:28:22 +01004818 " --------------------------------------
4819 " NetrwBrowseChgDir: Handle Tree Listing {{{3
4820 " --------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004821 " force a refresh (for TREELIST, NetrwTreeDir() will force the refresh)
Bram Moolenaar5b435d62012-04-05 17:33:26 +02004822 setl noro ma
Bram Moolenaar446cb832008-06-24 21:56:24 +00004823 if !(exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("b:netrw_curdir"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004824 NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00004825 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004826 let treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02004827 let s:treecurpos = winsaveview()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004828 let haskey = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00004829
4830 " search treedict for tree dir as-is
4831 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004832 let haskey= 1
4833 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004834 endif
4835
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004836 " search treedict for treedir with a [/@] appended
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004837 if !haskey && treedir !~ '[/@]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +00004838 if has_key(w:netrw_treedict,treedir."/")
4839 let treedir= treedir."/"
Bram Moolenaar446cb832008-06-24 21:56:24 +00004840 let haskey = 1
4841 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004842 endif
4843 endif
4844
4845 " search treedict for treedir with any trailing / elided
4846 if !haskey && treedir =~ '/$'
4847 let treedir= substitute(treedir,'/$','','')
4848 if has_key(w:netrw_treedict,treedir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00004849 let haskey = 1
4850 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00004851 endif
4852 endif
4853
4854 if haskey
4855 " close tree listing for selected subdirectory
Bram Moolenaar446cb832008-06-24 21:56:24 +00004856 call remove(w:netrw_treedict,treedir)
Bram Moolenaar00a927d2010-05-14 23:24:24 +02004857 let dirname= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00004858 else
4859 " go down one directory
4860 let dirname= substitute(treedir,'/*$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00004861 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004862 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01004863 let s:treeforceredraw = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00004864
4865 else
Bram Moolenaar97d62492012-11-15 21:28:22 +01004866 " ----------------------------------------
4867 " NetrwBrowseChgDir: Go down one directory {{{3
4868 " ----------------------------------------
4869 let dirname = s:ComposePath(dirname,newdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004870 NetrwKeepj call s:SetRexDir(a:islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004871 norm! m`
Bram Moolenaar9964e462007-05-05 17:54:07 +00004872 endif
4873
Bram Moolenaar97d62492012-11-15 21:28:22 +01004874 " --------------------------------------
4875 " NetrwBrowseChgDir: Restore and Cleanup {{{3
4876 " --------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02004877 if dorestore
4878 " dorestore is zero'd when a local file was hidden or bufhidden;
4879 " in such a case, we want to keep whatever settings it may have.
Bram Moolenaar85850f32019-07-19 22:05:51 +02004880 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar13600302014-05-22 18:26:40 +02004881 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02004882 if dolockout && dorestore
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004883 if filewritable(dirname)
Bram Moolenaar13600302014-05-22 18:26:40 +02004884 setl ma noro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004885 else
Bram Moolenaar13600302014-05-22 18:26:40 +02004886 setl ma ro nomod
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02004887 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00004888 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004889 call s:RestorePosn(s:netrw_posn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01004890 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00004891
Bram Moolenaar446cb832008-06-24 21:56:24 +00004892 return dirname
Bram Moolenaar9964e462007-05-05 17:54:07 +00004893endfun
4894
4895" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01004896" s:NetrwBrowseUpDir: implements the "-" mappings {{{2
4897" for thin, long, and wide: cursor placed just after banner
4898" for tree, keeps cursor on current filename
4899fun! s:NetrwBrowseUpDir(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004900 if exists("w:netrw_bannercnt") && line(".") < w:netrw_bannercnt-1
4901 " this test needed because occasionally this function seems to be incorrectly called
4902 " when multiple leftmouse clicks are taken when atop the one line help in the banner.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004903 " I'm allowing the very bottom line to permit a "-" exit so that one may escape empty
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004904 " directories.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01004905 return
4906 endif
4907
Bram Moolenaara6878372014-03-22 21:02:50 +01004908 norm! 0
4909 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
Bram Moolenaara6878372014-03-22 21:02:50 +01004910 let curline= getline(".")
4911 let swwline= winline() - 1
4912 if exists("w:netrw_treetop")
4913 let b:netrw_curdir= w:netrw_treetop
Bram Moolenaar85850f32019-07-19 22:05:51 +02004914 elseif exists("b:netrw_curdir")
4915 let w:netrw_treetop= b:netrw_curdir
4916 else
4917 let w:netrw_treetop= getcwd()
4918 let b:netrw_curdir = w:netrw_treetop
Bram Moolenaara6878372014-03-22 21:02:50 +01004919 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004920 let curfile = getline(".")
4921 let curpath = s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaara6878372014-03-22 21:02:50 +01004922 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004923 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004924 else
Tom Benham64a536d2024-11-07 21:15:03 +01004925 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004926 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004927 if w:netrw_treetop == '/'
4928 keepj call search('^\M'.curfile,"w")
4929 elseif curfile == '../'
4930 keepj call search('^\M'.curfile,"wb")
4931 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004932 while 1
4933 keepj call search('^\M'.s:treedepthstring.curfile,"wb")
4934 let treepath= s:NetrwTreePath(w:netrw_treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02004935 if treepath == curpath
4936 break
4937 endif
4938 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01004939 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004940
Bram Moolenaara6878372014-03-22 21:02:50 +01004941 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02004942 call s:SavePosn(s:netrw_posn)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01004943 if exists("b:netrw_curdir")
4944 let curdir= b:netrw_curdir
4945 else
4946 let curdir= expand(getcwd())
4947 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004948 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01004949 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004950 else
Tom Benham64a536d2024-11-07 21:15:03 +01004951 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,'../',0))
Bram Moolenaara6878372014-03-22 21:02:50 +01004952 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02004953 call s:RestorePosn(s:netrw_posn)
4954 let curdir= substitute(curdir,'^.*[\/]','','')
Christian Brabandt9a775b42023-12-14 20:09:07 +01004955 let curdir= '\<'. escape(curdir, '~'). '/'
4956 call search(curdir,'wc')
Bram Moolenaara6878372014-03-22 21:02:50 +01004957 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01004958endfun
4959
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01004960func s:redir()
4961 " set up redirection (avoids browser messages)
4962 " by default if not set, g:netrw_suppress_gx_mesg is true
4963 if get(g:, 'netrw_suppress_gx_mesg', 1)
4964 if &srr =~# "%s"
4965 return printf(&srr, has("win32") ? "nul" : "/dev/null")
4966 else
4967 return &srr .. (has("win32") ? "nul" : "/dev/null")
4968 endif
4969 endif
4970 return ''
4971endfunc
4972
4973if has('unix')
4974 if has('win32unix')
4975 " Cygwin provides cygstart
4976 if executable('cygstart')
4977 fun! netrw#Launch(args)
4978 exe 'silent ! cygstart --hide' a:args s:redir() | redraw!
4979 endfun
4980 elseif !empty($MSYSTEM) && executable('start')
4981 " MSYS2/Git Bash comes by default without cygstart; see
4982 " https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin
4983 " Instead it provides /usr/bin/start script running `cmd.exe //c start`
4984 " Adding "" //b` sets void title, hides cmd window and blocks path conversion
4985 " of /b to \b\ " by MSYS2; see https://www.msys2.org/docs/filesystem-paths/
4986 fun! netrw#Launch(args)
4987 exe 'silent !start "" //b' a:args s:redir() | redraw!
4988 endfun
4989 else
4990 " imitate /usr/bin/start script for other environments and hope for the best
4991 fun! netrw#Launch(args)
4992 exe 'silent !cmd //c start "" //b' a:args s:redir() | redraw!
4993 endfun
4994 endif
4995 elseif exists('$WSL_DISTRO_NAME') " use cmd.exe to start GUI apps in WSL
4996 fun! netrw#Launch(args)
4997 let args = a:args
4998 exe 'silent !' ..
4999 \ ((args =~? '\v<\f+\.(exe|com|bat|cmd)>') ?
5000 \ 'cmd.exe /c start "" /b ' .. args :
5001 \ 'nohup ' .. args .. ' ' .. s:redir() .. ' &')
5002 \ | redraw!
5003 endfun
5004 else
5005 fun! netrw#Launch(args)
5006 exe ':silent ! nohup' a:args s:redir() '&' | redraw!
5007 endfun
5008 endif
5009elseif has('win32')
5010 fun! netrw#Launch(args)
5011 exe 'silent !' .. (&shell =~? '\<cmd\.exe\>' ? '' : 'cmd.exe /c')
5012 \ 'start "" /b' a:args s:redir() | redraw!
5013 endfun
5014else
5015 fun! netrw#Launch(dummy)
5016 echom 'No common launcher found'
5017 endfun
5018endif
5019
5020" Git Bash
5021if has('win32unix')
5022 " (cyg)start suffices
5023 let s:os_viewer = ''
5024" Windows / WSL
5025elseif executable('explorer.exe')
5026 let s:os_viewer = 'explorer.exe'
5027" Linux / BSD
5028elseif executable('xdg-open')
5029 let s:os_viewer = 'xdg-open'
5030" MacOS
5031elseif executable('open')
5032 let s:os_viewer = 'open'
5033endif
5034
5035fun! s:viewer()
5036 if exists('g:netrw_browsex_viewer') && executable(g:netrw_browsex_viewer)
5037 " extract any viewing options. Assumes that they're set apart by spaces.
5038 " call Decho("extract any viewing options from g:netrw_browsex_viewer<".g:netrw_browsex_viewer.">",'~'.expand("<slnum>"))
5039 if g:netrw_browsex_viewer =~ '\s'
5040 let viewer = substitute(g:netrw_browsex_viewer,'\s.*$','','')
5041 let viewopt = substitute(g:netrw_browsex_viewer,'^\S\+\s*','','')." "
5042 let oviewer = ''
5043 let cnt = 1
5044 while !executable(viewer) && viewer != oviewer
5045 let viewer = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\1','')
5046 let viewopt = substitute(g:netrw_browsex_viewer,'^\(\(^\S\+\s\+\)\{'.cnt.'}\S\+\)\(.*\)$','\3','')." "
5047 let cnt = cnt + 1
5048 let oviewer = viewer
5049 " call Decho("!exe: viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5050 endwhile
5051 else
5052 let viewer = g:netrw_browsex_viewer
5053 let viewopt = ""
5054 endif
5055 " call Decho("viewer<".viewer."> viewopt<".viewopt.">",'~'.expand("<slnum>"))
5056 return viewer .. ' ' .. viewopt
5057 else
5058 if !exists('s:os_viewer')
5059 call netrw#ErrorMsg(s:ERROR,"No program to open this path found. See :help Open for more information.",106)
5060 else
5061 return s:os_viewer
5062 endif
5063 endif
5064endfun
5065
5066fun! netrw#Open(file) abort
5067 call netrw#Launch(s:viewer() .. ' ' .. shellescape(a:file, 1))
5068endf
5069
5070if !exists('g:netrw_regex_url')
5071 let g:netrw_regex_url = '\%(\%(http\|ftp\|irc\)s\?\|file\)://\S\{-}'
5072endif
5073
Bram Moolenaara6878372014-03-22 21:02:50 +01005074" ---------------------------------------------------------------------
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01005075" netrw#BrowseX: (implements "x" and "gx") executes a special "viewer" script or program for the {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +01005076" given filename; typically this means given their extension.
5077" 0=local, 1=remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005078fun! netrw#BrowseX(fname,remote)
Bram Moolenaar91359012019-11-30 17:57:03 +01005079 if a:remote == 0 && isdirectory(a:fname)
5080 " if its really just a local directory, then do a "gf" instead
Bram Moolenaar29634562020-01-09 21:46:04 +01005081 exe "e ".a:fname
Bram Moolenaar91359012019-11-30 17:57:03 +01005082 elseif a:remote == 1 && a:fname !~ '^https\=:' && a:fname =~ '/$'
5083 " remote directory, not a webpage access, looks like an attempt to do a directory listing
Bram Moolenaar91359012019-11-30 17:57:03 +01005084 norm! gf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005085 endif
5086
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005087 if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
5088 let remote = a:remote
5089 else
5090 let remote = 0
5091 endif
5092
Bram Moolenaar97d62492012-11-15 21:28:22 +01005093 let ykeep = @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005094 let screenposn = winsaveview()
Bram Moolenaar97d62492012-11-15 21:28:22 +01005095
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005096 " need to save and restore aw setting as gx can invoke this function from non-netrw buffers
5097 let awkeep = &aw
5098 set noaw
5099
Bram Moolenaar5c736222010-01-06 20:54:52 +01005100 " special core dump handler
5101 if a:fname =~ '/core\(\.\d\+\)\=$'
5102 if exists("g:Netrw_corehandler")
5103 if type(g:Netrw_corehandler) == 2
5104 " g:Netrw_corehandler is a function reference (see :help Funcref)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005105 call g:Netrw_corehandler(s:NetrwFile(a:fname))
Bram Moolenaarff034192013-04-24 18:51:19 +02005106 elseif type(g:Netrw_corehandler) == 3
Bram Moolenaar5c736222010-01-06 20:54:52 +01005107 " g:Netrw_corehandler is a List of function references (see :help Funcref)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005108 for Fncref in g:Netrw_corehandler
Bram Moolenaar71badf92023-04-22 22:40:14 +01005109 if type(Fncref) == 2
5110 call Fncref(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005111 endif
5112 endfor
5113 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005114 call winrestview(screenposn)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005115 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005116 let &aw= awkeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005117 return
5118 endif
5119 endif
5120
Bram Moolenaar446cb832008-06-24 21:56:24 +00005121 " set up the filename
5122 " (lower case the extension, make a local copy of a remote file)
5123 let exten= substitute(a:fname,'.*\.\(.\{-}\)','\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +02005124 if has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005125 let exten= substitute(exten,'^.*$','\L&\E','')
Bram Moolenaar9964e462007-05-05 17:54:07 +00005126 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005127 if exten =~ "[\\/]"
5128 let exten= ""
5129 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005130
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005131 if remote == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005132 " create a local copy
Bram Moolenaarff034192013-04-24 18:51:19 +02005133 setl bh=delete
Bram Moolenaar5c736222010-01-06 20:54:52 +01005134 call netrw#NetRead(3,a:fname)
5135 " attempt to rename tempfile
5136 let basename= substitute(a:fname,'^\(.*\)/\(.*\)\.\([^.]*\)$','\2','')
Bram Moolenaar97d62492012-11-15 21:28:22 +01005137 let newname = substitute(s:netrw_tmpfile,'^\(.*\)/\(.*\)\.\([^.]*\)$','\1/'.basename.'.\3','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02005138 if s:netrw_tmpfile != newname && newname != ""
5139 if rename(s:netrw_tmpfile,newname) == 0
5140 " renaming succeeded
Bram Moolenaar85850f32019-07-19 22:05:51 +02005141 let fname= newname
5142 else
5143 " renaming failed
Bram Moolenaar85850f32019-07-19 22:05:51 +02005144 let fname= s:netrw_tmpfile
5145 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005146 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01005147 let fname= s:netrw_tmpfile
5148 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +00005149 else
5150 let fname= a:fname
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005151 " special ~ handler for local
5152 if fname =~ '^\~' && expand("$HOME") != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005153 let fname= s:NetrwFile(substitute(fname,'^\~',expand("$HOME"),''))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005154 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005155 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005156
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005157 " although shellescape(..., 1) is used in netrw#Open(), it's insufficient
5158 call netrw#Open(escape(fname, '#%'))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005159
Bram Moolenaar446cb832008-06-24 21:56:24 +00005160 " cleanup: remove temporary file,
5161 " delete current buffer if success with handler,
5162 " return to prior buffer (directory listing)
Viktor Szépedbf749b2023-10-16 09:53:37 +02005163 " Feb 12, 2008: had to de-activate removal of
Bram Moolenaar446cb832008-06-24 21:56:24 +00005164 " temporary file because it wasn't getting seen.
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005165" if remote == 1 && fname != a:fname
Bram Moolenaarc236c162008-07-13 17:41:49 +00005166" call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005167" endif
5168
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005169 if remote == 1
Bram Moolenaarff034192013-04-24 18:51:19 +02005170 setl bh=delete bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00005171 if g:netrw_use_noswf
Bram Moolenaarff034192013-04-24 18:51:19 +02005172 setl noswf
Bram Moolenaar446cb832008-06-24 21:56:24 +00005173 endif
Christian Brabandt9f320692024-10-30 18:36:20 +01005174 exe "sil! NetrwKeepj norm! \<c-o>"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005175 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005176 call winrestview(screenposn)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005177 let @@ = ykeep
5178 let &aw= awkeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005179endfun
5180
5181" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005182" netrw#GX: gets word under cursor for gx support {{{2
5183" See also: netrw#BrowseXVis
5184" netrw#BrowseX
5185fun! netrw#GX()
5186" call Dfunc("netrw#GX()")
5187 if &ft == "netrw"
5188 let fname= s:NetrwGetWord()
5189 else
Konfekt3d7e5672024-10-27 22:16:49 +01005190 let fname= exists("g:netrw_gx")? expand(g:netrw_gx) : s:GetURL()
Bram Moolenaar85850f32019-07-19 22:05:51 +02005191 endif
5192" call Dret("netrw#GX <".fname.">")
5193 return fname
5194endfun
5195
Konfekt3d7e5672024-10-27 22:16:49 +01005196fun! s:GetURL() abort
5197 let URL = ''
5198 if exists('*Netrw_get_URL_' .. &filetype)
5199 let URL = call('Netrw_get_URL_' .. &filetype, [])
5200 endif
5201 if !empty(URL) | return URL | endif
5202 " URLs end in letter, digit or forward slash
5203 let URL = matchstr(expand("<cWORD>"), '\<' .. g:netrw_regex_url .. '\ze[^A-Za-z0-9/]*$')
5204 if !empty(URL) | return URL | endif
5205
5206 " Is it a file in the current work dir ...
5207 let file = expand("<cfile>")
5208 if filereadable(file) | return file | endif
5209 " ... or in that of the current buffer?
5210 let path = fnamemodify(expand('%'), ':p')
5211 if isdirectory(path)
5212 let dir = path
5213 elseif filereadable(path)
5214 let dir = fnamemodify(path, ':h')
5215 endif
5216 if exists('dir') && filereadable(dir..'/'..file) | return dir..'/'..file | endif
5217
5218 return ''
5219endf
5220
Bram Moolenaar85850f32019-07-19 22:05:51 +02005221" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005222" netrw#BrowseXVis: used by gx in visual mode to select a file for browsing {{{2
5223fun! netrw#BrowseXVis()
Christian Brabandt62f7b552024-06-23 20:23:40 +02005224 let dict={}
5225 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar91359012019-11-30 17:57:03 +01005226 norm! gv"ay
5227 let gxfile= @a
Christian Brabandt62f7b552024-06-23 20:23:40 +02005228 call s:RestoreRegister(dict)
Bram Moolenaar91359012019-11-30 17:57:03 +01005229 call netrw#BrowseX(gxfile,netrw#CheckIfRemote(gxfile))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005230endfun
5231
5232" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02005233" s:NetrwBufRename: renames a buffer without the side effect of retaining an unlisted buffer having the old name {{{2
5234" Using the file command on a "[No Name]" buffer does not seem to cause the old "[No Name]" buffer
5235" to become an unlisted buffer, so in that case don't bwipe it.
5236fun! s:NetrwBufRename(newname)
5237" call Dfunc("s:NetrwBufRename(newname<".a:newname.">) buf(%)#".bufnr("%")."<".bufname(bufnr("%")).">")
5238" call Dredir("ls!","s:NetrwBufRename (before rename)")
5239 let oldbufname= bufname(bufnr("%"))
5240" call Decho("buf#".bufnr("%").": oldbufname<".oldbufname.">",'~'.expand("<slnum>"))
5241
5242 if oldbufname != a:newname
5243" call Decho("do buffer rename: oldbufname<".oldbufname."> ≠ a:newname<".a:newname.">",'~'.expand("<slnum>"))
5244 let b:junk= 1
5245" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
5246 exe 'sil! keepj keepalt file '.fnameescape(a:newname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005247" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005248 let oldbufnr= bufnr(oldbufname)
5249" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
5250" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
5251 if oldbufname != "" && oldbufnr != -1 && oldbufnr != bufnr("%")
5252" call Decho("bwipe ".oldbufnr,'~'.expand("<slnum>"))
5253 exe "bwipe! ".oldbufnr
5254" else " Decho
5255" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02005256" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
5257" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
5258" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
Bram Moolenaar85850f32019-07-19 22:05:51 +02005259 endif
5260" call Dredir("ls!","s:NetrwBufRename (after rename)")
5261" else " Decho
5262" call Decho("oldbufname<".oldbufname."> == a:newname: did *not* rename",'~'.expand("<slnum>"))
5263 endif
5264
5265" call Dret("s:NetrwBufRename : buf#".bufnr("%").": oldname<".oldbufname."> newname<".a:newname."> expand(%)<".expand("%").">")
5266endfun
5267
5268" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005269" netrw#CheckIfRemote: returns 1 if current file looks like an url, 0 else {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005270fun! netrw#CheckIfRemote(...)
5271" call Dfunc("netrw#CheckIfRemote() a:0=".a:0)
5272 if a:0 > 0
5273 let curfile= a:1
5274 else
5275 let curfile= expand("%")
5276 endif
5277" call Decho("curfile<".curfile.">")
5278 if curfile =~ '^\a\{3,}://'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005279" call Dret("netrw#CheckIfRemote 1")
5280 return 1
5281 else
5282" call Dret("netrw#CheckIfRemote 0")
5283 return 0
5284 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +00005285endfun
5286
5287" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005288" s:NetrwChgPerm: (implements "gp") change file permission {{{2
5289fun! s:NetrwChgPerm(islocal,curdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005290 let ykeep = @@
Bram Moolenaar5c736222010-01-06 20:54:52 +01005291 call inputsave()
5292 let newperm= input("Enter new permission: ")
5293 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005294 let chgperm= substitute(g:netrw_chgperm,'\<FILENAME\>',s:ShellEscape(expand("<cfile>")),'')
5295 let chgperm= substitute(chgperm,'\<PERM\>',s:ShellEscape(newperm),'')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005296 call system(chgperm)
5297 if v:shell_error != 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005298 NetrwKeepj call netrw#ErrorMsg(1,"changing permission on file<".expand("<cfile>")."> seems to have failed",75)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005299 endif
5300 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005301 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005302 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005303 let @@= ykeep
Bram Moolenaar5c736222010-01-06 20:54:52 +01005304endfun
5305
5306" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005307" s:CheckIfKde: checks if kdeinit is running {{{2
5308" Returns 0: kdeinit not running
5309" 1: kdeinit is running
5310fun! s:CheckIfKde()
5311" call Dfunc("s:CheckIfKde()")
5312 " seems kde systems often have gnome-open due to dependencies, even though
5313 " gnome-open's subsidiary display tools are largely absent. Kde systems
5314 " usually have "kdeinit" running, though... (tnx Mikolaj Machowski)
5315 if !exists("s:haskdeinit")
5316 if has("unix") && executable("ps") && !has("win32unix")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005317 let s:haskdeinit= system("ps -e") =~ '\<kdeinit'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005318 if v:shell_error
5319 let s:haskdeinit = 0
5320 endif
5321 else
5322 let s:haskdeinit= 0
5323 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005324" call Decho("setting s:haskdeinit=".s:haskdeinit,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005325 endif
5326
5327" call Dret("s:CheckIfKde ".s:haskdeinit)
5328 return s:haskdeinit
5329endfun
5330
5331" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005332" s:NetrwClearExplore: clear explore variables (if any) {{{2
5333fun! s:NetrwClearExplore()
5334" call Dfunc("s:NetrwClearExplore()")
5335 2match none
5336 if exists("s:explore_match") |unlet s:explore_match |endif
5337 if exists("s:explore_indx") |unlet s:explore_indx |endif
5338 if exists("s:netrw_explore_prvdir") |unlet s:netrw_explore_prvdir |endif
5339 if exists("s:dirstarstar") |unlet s:dirstarstar |endif
5340 if exists("s:explore_prvdir") |unlet s:explore_prvdir |endif
5341 if exists("w:netrw_explore_indx") |unlet w:netrw_explore_indx |endif
5342 if exists("w:netrw_explore_listlen")|unlet w:netrw_explore_listlen|endif
5343 if exists("w:netrw_explore_list") |unlet w:netrw_explore_list |endif
5344 if exists("w:netrw_explore_bufnr") |unlet w:netrw_explore_bufnr |endif
5345" redraw!
Bram Moolenaar5c736222010-01-06 20:54:52 +01005346" call Dret("s:NetrwClearExplore")
5347endfun
5348
5349" ---------------------------------------------------------------------
Bram Moolenaar71badf92023-04-22 22:40:14 +01005350" s:NetrwEditBuf: decides whether or not to use keepalt to edit a buffer {{{2
5351fun! s:NetrwEditBuf(bufnum)
5352" call Dfunc("s:NetrwEditBuf(fname<".a:bufnum.">)")
5353 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5354" call Decho("exe sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum))
5355 exe "sil! NetrwKeepj keepalt noswapfile b ".fnameescape(a:bufnum)
5356 else
5357" call Decho("exe sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum))
Bram Moolenaarb7398fe2023-05-14 18:50:25 +01005358 exe "sil! NetrwKeepj noswapfile b ".fnameescape(a:bufnum)
Bram Moolenaar71badf92023-04-22 22:40:14 +01005359 endif
5360" call Dret("s:NetrwEditBuf")
5361endfun
5362
5363" ---------------------------------------------------------------------
5364" s:NetrwEditFile: decides whether or not to use keepalt to edit a file {{{2
5365" NetrwKeepj [keepalt] <OPT> <CMD> <FILENAME>
5366fun! s:NetrwEditFile(cmd,opt,fname)
5367" call Dfunc("s:NetrwEditFile(cmd<".a:cmd.">,opt<".a:opt.">,fname<".a:fname.">) ft<".&ft.">")
5368 if exists("g:netrw_altfile") && g:netrw_altfile && &ft == "netrw"
5369" call Decho("exe NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname))
5370 exe "NetrwKeepj keepalt ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5371 else
5372" call Decho("exe NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname))
Christian Brabandt98b73eb2024-06-04 18:15:57 +02005373 if a:cmd =~# 'e\%[new]!' && !&hidden && getbufvar(bufname('%'), '&modified', 0)
5374 call setbufvar(bufname('%'), '&bufhidden', 'hide')
5375 endif
Bram Moolenaar71badf92023-04-22 22:40:14 +01005376 exe "NetrwKeepj ".a:opt." ".a:cmd." ".fnameescape(a:fname)
5377 endif
5378" call Dret("s:NetrwEditFile")
5379endfun
5380
5381" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005382" s:NetrwExploreListUniq: {{{2
5383fun! s:NetrwExploreListUniq(explist)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005384 " this assumes that the list is already sorted
5385 let newexplist= []
5386 for member in a:explist
5387 if !exists("uniqmember") || member != uniqmember
5388 let uniqmember = member
5389 let newexplist = newexplist + [ member ]
5390 endif
5391 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01005392 return newexplist
5393endfun
5394
5395" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005396" s:NetrwForceChgDir: (gd support) Force treatment as a directory {{{2
5397fun! s:NetrwForceChgDir(islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005398 let ykeep= @@
Bram Moolenaaradc21822011-04-01 18:03:16 +02005399 if a:newdir !~ '/$'
5400 " ok, looks like force is needed to get directory-style treatment
5401 if a:newdir =~ '@$'
5402 let newdir= substitute(a:newdir,'@$','/','')
5403 elseif a:newdir =~ '[*=|\\]$'
5404 let newdir= substitute(a:newdir,'.$','/','')
5405 else
5406 let newdir= a:newdir.'/'
5407 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005408 else
5409 " should already be getting treatment as a directory
5410 let newdir= a:newdir
5411 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005412 let newdir= s:NetrwBrowseChgDir(a:islocal,newdir,0)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005413 call s:NetrwBrowse(a:islocal,newdir)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005414 let @@= ykeep
Bram Moolenaaradc21822011-04-01 18:03:16 +02005415endfun
5416
5417" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005418" s:NetrwGlob: does glob() if local, remote listing otherwise {{{2
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02005419" direntry: this is the name of the directory. Will be fnameescape'd to prevent wildcard handling by glob()
5420" expr : this is the expression to follow the directory. Will use s:ComposePath()
5421" pare =1: remove the current directory from the resulting glob() filelist
5422" =0: leave the current directory in the resulting glob() filelist
5423fun! s:NetrwGlob(direntry,expr,pare)
5424" call Dfunc("s:NetrwGlob(direntry<".a:direntry."> expr<".a:expr."> pare=".a:pare.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005425 if netrw#CheckIfRemote()
5426 keepalt 1sp
5427 keepalt enew
5428 let keep_liststyle = w:netrw_liststyle
5429 let w:netrw_liststyle = s:THINLIST
5430 if s:NetrwRemoteListing() == 0
5431 keepj keepalt %s@/@@
5432 let filelist= getline(1,$)
5433 q!
5434 else
5435 " remote listing error -- leave treedict unchanged
5436 let filelist= w:netrw_treedict[a:direntry]
5437 endif
5438 let w:netrw_liststyle= keep_liststyle
5439 else
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01005440 let path= s:ComposePath(fnameescape(a:direntry), a:expr)
Christian Brabandt44074612024-06-14 08:19:22 +02005441 if has("win32")
Christian Brabandt14879472024-06-13 21:25:35 +02005442 " escape [ so it is not detected as wildcard character, see :h wildcard
5443 let path= substitute(path, '[', '[[]', 'g')
5444 endif
5445 if v:version > 704 || (v:version == 704 && has("patch656"))
5446 let filelist= glob(path,0,1,1)
5447 else
5448 let filelist= glob(path,0,1)
5449 endif
5450 if a:pare
5451 let filelist= map(filelist,'substitute(v:val, "^.*/", "", "")')
5452 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005453 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005454 return filelist
5455endfun
5456
5457" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +02005458" s:NetrwForceFile: (gf support) Force treatment as a file {{{2
5459fun! s:NetrwForceFile(islocal,newfile)
Bram Moolenaaradc21822011-04-01 18:03:16 +02005460 if a:newfile =~ '[/@*=|\\]$'
5461 let newfile= substitute(a:newfile,'.$','','')
5462 else
5463 let newfile= a:newfile
5464 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005465 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01005466 call s:NetrwBrowseChgDir(a:islocal,newfile,0)
Bram Moolenaarff034192013-04-24 18:51:19 +02005467 else
Tom Benham64a536d2024-11-07 21:15:03 +01005468 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,newfile,0))
Bram Moolenaarff034192013-04-24 18:51:19 +02005469 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02005470endfun
5471
5472" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005473" s:NetrwHide: this function is invoked by the "a" map for browsing {{{2
5474" and switches the hiding mode. The actual hiding is done by
5475" s:NetrwListHide().
5476" g:netrw_hide= 0: show all
5477" 1: show not-hidden files
5478" 2: show hidden files only
5479fun! s:NetrwHide(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005480 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005481 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005482
5483 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005484
5485 " hide the files in the markfile list
5486 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00005487 if match(g:netrw_list_hide,'\<'.fname.'\>') != -1
5488 " remove fname from hiding list
5489 let g:netrw_list_hide= substitute(g:netrw_list_hide,'..\<'.escape(fname,g:netrw_fname_escape).'\>..','','')
5490 let g:netrw_list_hide= substitute(g:netrw_list_hide,',,',',','g')
5491 let g:netrw_list_hide= substitute(g:netrw_list_hide,'^,\|,$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00005492 else
5493 " append fname to hiding list
5494 if exists("g:netrw_list_hide") && g:netrw_list_hide != ""
5495 let g:netrw_list_hide= g:netrw_list_hide.',\<'.escape(fname,g:netrw_fname_escape).'\>'
5496 else
5497 let g:netrw_list_hide= '\<'.escape(fname,g:netrw_fname_escape).'\>'
5498 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005499 endif
5500 endfor
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005501 NetrwKeepj call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005502 let g:netrw_hide= 1
5503
5504 else
5505
5506 " switch between show-all/show-not-hidden/show-hidden
5507 let g:netrw_hide=(g:netrw_hide+1)%3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005508 exe "NetrwKeepj norm! 0"
Bram Moolenaar446cb832008-06-24 21:56:24 +00005509 if g:netrw_hide && g:netrw_list_hide == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005510 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"your hiding list is empty!",49)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005511 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005512 return
5513 endif
5514 endif
5515
Tom Benham64a536d2024-11-07 21:15:03 +01005516 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005517 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005518 let @@= ykeep
Bram Moolenaar9964e462007-05-05 17:54:07 +00005519endfun
5520
5521" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005522" s:NetrwHideEdit: allows user to edit the file/directory hiding list {{{2
5523fun! s:NetrwHideEdit(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005524 let ykeep= @@
5525 " save current cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005526 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005527
5528 " get new hiding list from user
5529 call inputsave()
5530 let newhide= input("Edit Hiding List: ",g:netrw_list_hide)
5531 call inputrestore()
5532 let g:netrw_list_hide= newhide
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005533
5534 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01005535 sil NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,"./",0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005536
5537 " restore cursor position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005538 call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005539 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005540endfun
5541
5542" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005543" s:NetrwHidden: invoked by "gh" {{{2
5544fun! s:NetrwHidden(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005545 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005546 " save current position
Bram Moolenaar85850f32019-07-19 22:05:51 +02005547 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005548
5549 if g:netrw_list_hide =~ '\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005550 " remove .file pattern from hiding list
Bram Moolenaar446cb832008-06-24 21:56:24 +00005551 let g:netrw_list_hide= substitute(g:netrw_list_hide,'\(^\|,\)\\(^\\|\\s\\s\\)\\zs\\.\\S\\+','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +01005552 elseif s:Strlen(g:netrw_list_hide) >= 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00005553 let g:netrw_list_hide= g:netrw_list_hide . ',\(^\|\s\s\)\zs\.\S\+'
5554 else
5555 let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
5556 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005557 if g:netrw_list_hide =~ '^,'
5558 let g:netrw_list_hide= strpart(g:netrw_list_hide,1)
5559 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005560
5561 " refresh screen and return to saved position
Tom Benham64a536d2024-11-07 21:15:03 +01005562 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005563 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +01005564 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005565endfun
5566
5567" ---------------------------------------------------------------------
Bram Moolenaar5c736222010-01-06 20:54:52 +01005568" s:NetrwHome: this function determines a "home" for saving bookmarks and history {{{2
5569fun! s:NetrwHome()
5570 if exists("g:netrw_home")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005571 let home= expand(g:netrw_home)
Bram Moolenaar5c736222010-01-06 20:54:52 +01005572 else
5573 " go to vim plugin home
5574 for home in split(&rtp,',') + ['']
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005575 if isdirectory(s:NetrwFile(home)) && filewritable(s:NetrwFile(home)) | break | endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01005576 let basehome= substitute(home,'[/\\]\.vim$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005577 if isdirectory(s:NetrwFile(basehome)) && filewritable(s:NetrwFile(basehome))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005578 let home= basehome."/.vim"
5579 break
5580 endif
5581 endfor
5582 if home == ""
5583 " just pick the first directory
5584 let home= substitute(&rtp,',.*$','','')
5585 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02005586 if has("win32")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005587 let home= substitute(home,'/','\\','g')
5588 endif
5589 endif
5590 " insure that the home directory exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005591 if g:netrw_dirhistmax > 0 && !isdirectory(s:NetrwFile(home))
Bram Moolenaar85850f32019-07-19 22:05:51 +02005592" call Decho("insure that the home<".home."> directory exists")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005593 if exists("g:netrw_mkdir")
Bram Moolenaar85850f32019-07-19 22:05:51 +02005594" call Decho("call system(".g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)).")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005595 call system(g:netrw_mkdir." ".s:ShellEscape(s:NetrwFile(home)))
Bram Moolenaar5c736222010-01-06 20:54:52 +01005596 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02005597" call Decho("mkdir(".home.")")
Bram Moolenaar5c736222010-01-06 20:54:52 +01005598 call mkdir(home)
5599 endif
5600 endif
5601 let g:netrw_home= home
5602 return home
5603endfun
5604
5605" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005606" s:NetrwLeftmouse: handles the <leftmouse> when in a netrw browsing window {{{2
5607fun! s:NetrwLeftmouse(islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02005608 if exists("s:netrwdrag")
5609 return
5610 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005611 if &ft != "netrw"
5612 return
5613 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005614
Bram Moolenaar97d62492012-11-15 21:28:22 +01005615 let ykeep= @@
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005616 " check if the status bar was clicked on instead of a file/directory name
Bram Moolenaaradc21822011-04-01 18:03:16 +02005617 while getchar(0) != 0
5618 "clear the input stream
5619 endwhile
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005620 call feedkeys("\<LeftMouse>")
Bram Moolenaaradc21822011-04-01 18:03:16 +02005621 let c = getchar()
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005622 let mouse_lnum = v:mouse_lnum
5623 let wlastline = line('w$')
5624 let lastline = line('$')
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005625 if mouse_lnum >= wlastline + 1 || v:mouse_win != winnr()
5626 " appears to be a status bar leftmouse click
Bram Moolenaar97d62492012-11-15 21:28:22 +01005627 let @@= ykeep
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005628 return
5629 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005630 " Dec 04, 2013: following test prevents leftmouse selection/deselection of directories and files in treelist mode
Bram Moolenaar8d043172014-01-23 14:24:41 +01005631 " 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 +01005632 " without this test when its disabled.
5633 " 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 +01005634 if v:mouse_col > virtcol('.')
5635 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005636 return
5637 endif
Bram Moolenaar00a927d2010-05-14 23:24:24 +02005638
Bram Moolenaar446cb832008-06-24 21:56:24 +00005639 if a:islocal
5640 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005641 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005642 endif
5643 else
5644 if exists("b:netrw_curdir")
Tom Benham64a536d2024-11-07 21:15:03 +01005645 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005646 endif
5647 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005648 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005649endfun
5650
5651" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005652" s:NetrwCLeftmouse: used to select a file/directory for a target {{{2
5653fun! s:NetrwCLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005654 if &ft != "netrw"
5655 return
5656 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005657 call s:NetrwMarkFileTgt(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005658endfun
5659
5660" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005661" s:NetrwServerEdit: edit file in a server gvim, usually NETRWSERVER (implements <c-r>){{{2
5662" a:islocal=0 : <c-r> not used, remote
Bram Moolenaar85850f32019-07-19 22:05:51 +02005663" a:islocal=1 : <c-r> not used, local
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005664" a:islocal=2 : <c-r> used, remote
5665" a:islocal=3 : <c-r> used, local
5666fun! s:NetrwServerEdit(islocal,fname)
5667" call Dfunc("s:NetrwServerEdit(islocal=".a:islocal.",fname<".a:fname.">)")
5668 let islocal = a:islocal%2 " =0: remote =1: local
5669 let ctrlr = a:islocal >= 2 " =0: <c-r> not used =1: <c-r> used
5670
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005671 if (islocal && isdirectory(s:NetrwFile(a:fname))) || (!islocal && a:fname =~ '/$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005672 " handle directories in the local window -- not in the remote vim server
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005673 " user must have closed the NETRWSERVER window. Treat as normal editing from netrw.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005674 let g:netrw_browse_split= 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005675 if exists("s:netrw_browse_split") && exists("s:netrw_browse_split_".winnr())
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005676 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5677 unlet s:netrw_browse_split_{winnr()}
5678 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005679 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005680 return
5681 endif
5682
5683 if has("clientserver") && executable("gvim")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005684
5685 if exists("g:netrw_browse_split") && type(g:netrw_browse_split) == 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005686 let srvrname = g:netrw_browse_split[0]
5687 let tabnum = g:netrw_browse_split[1]
5688 let winnum = g:netrw_browse_split[2]
5689
5690 if serverlist() !~ '\<'.srvrname.'\>'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005691 if !ctrlr
5692 " user must have closed the server window and the user did not use <c-r>, but
5693 " used something like <cr>.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005694 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005695 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005696 endif
5697 let g:netrw_browse_split= 0
5698 if exists("s:netrw_browse_split_".winnr())
5699 let g:netrw_browse_split= s:netrw_browse_split_{winnr()}
5700 endif
Tom Benham64a536d2024-11-07 21:15:03 +01005701 call s:NetrwBrowseChgDir(islocal,a:fname,0)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005702 return
5703
5704 elseif has("win32") && executable("start")
5705 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005706 call system("start gvim --servername ".srvrname)
5707
5708 else
5709 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005710 call system("gvim --servername ".srvrname)
5711 endif
5712 endif
5713
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005714 call remote_send(srvrname,":tabn ".tabnum."\<cr>")
5715 call remote_send(srvrname,":".winnum."wincmd w\<cr>")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005716 call remote_send(srvrname,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005717 else
5718
5719 if serverlist() !~ '\<'.g:netrw_servername.'\>'
5720
5721 if !ctrlr
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005722 if exists("g:netrw_browse_split")
K.Takata71d0ba02024-01-10 03:21:05 +09005723 unlet g:netrw_browse_split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005724 endif
5725 let g:netrw_browse_split= 0
Tom Benham64a536d2024-11-07 21:15:03 +01005726 call s:NetrwBrowse(islocal,s:NetrwBrowseChgDir(islocal,a:fname,0))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005727 return
5728
5729 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005730 if has("win32") && executable("start")
5731 " start up remote netrw server under windows
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005732 call system("start gvim --servername ".g:netrw_servername)
5733 else
5734 " start up remote netrw server under linux
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005735 call system("gvim --servername ".g:netrw_servername)
5736 endif
5737 endif
5738 endif
5739
5740 while 1
5741 try
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005742 call remote_send(g:netrw_servername,":e ".fnameescape(s:NetrwFile(a:fname))."\<cr>")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005743 break
5744 catch /^Vim\%((\a\+)\)\=:E241/
5745 sleep 200m
5746 endtry
5747 endwhile
5748
5749 if exists("g:netrw_browse_split")
5750 if type(g:netrw_browse_split) != 3
5751 let s:netrw_browse_split_{winnr()}= g:netrw_browse_split
5752 endif
5753 unlet g:netrw_browse_split
5754 endif
5755 let g:netrw_browse_split= [g:netrw_servername,1,1]
5756 endif
5757
5758 else
5759 call netrw#ErrorMsg(s:ERROR,"you need a gui-capable vim and client-server to use <ctrl-r>",98)
5760 endif
5761
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005762endfun
5763
5764" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005765" s:NetrwSLeftmouse: marks the file under the cursor. May be dragged to select additional files {{{2
5766fun! s:NetrwSLeftmouse(islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005767 if &ft != "netrw"
5768 return
5769 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005770" call Dfunc("s:NetrwSLeftmouse(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005771
Bram Moolenaar8d043172014-01-23 14:24:41 +01005772 let s:ngw= s:NetrwGetWord()
5773 call s:NetrwMarkFile(a:islocal,s:ngw)
5774
5775" call Dret("s:NetrwSLeftmouse")
Bram Moolenaarff034192013-04-24 18:51:19 +02005776endfun
5777
5778" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +01005779" s:NetrwSLeftdrag: invoked via a shift-leftmouse and dragging {{{2
5780" Used to mark multiple files.
5781fun! s:NetrwSLeftdrag(islocal)
5782" call Dfunc("s:NetrwSLeftdrag(islocal=".a:islocal.")")
5783 if !exists("s:netrwdrag")
5784 let s:netrwdrag = winnr()
5785 if a:islocal
5786 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(1)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005787 else
Bram Moolenaar8d043172014-01-23 14:24:41 +01005788 nno <silent> <s-leftrelease> <leftmouse>:<c-u>call <SID>NetrwSLeftrelease(0)<cr>
Bram Moolenaarff034192013-04-24 18:51:19 +02005789 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005790 endif
5791 let ngw = s:NetrwGetWord()
5792 if !exists("s:ngw") || s:ngw != ngw
5793 call s:NetrwMarkFile(a:islocal,ngw)
5794 endif
5795 let s:ngw= ngw
5796" call Dret("s:NetrwSLeftdrag : s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5797endfun
5798
5799" ---------------------------------------------------------------------
5800" s:NetrwSLeftrelease: terminates shift-leftmouse dragging {{{2
5801fun! s:NetrwSLeftrelease(islocal)
5802" call Dfunc("s:NetrwSLeftrelease(islocal=".a:islocal.") s:netrwdrag=".s:netrwdrag." buf#".bufnr("%"))
5803 if exists("s:netrwdrag")
5804 nunmap <s-leftrelease>
5805 let ngw = s:NetrwGetWord()
5806 if !exists("s:ngw") || s:ngw != ngw
5807 call s:NetrwMarkFile(a:islocal,ngw)
5808 endif
5809 if exists("s:ngw")
5810 unlet s:ngw
5811 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02005812 unlet s:netrwdrag
5813 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01005814" call Dret("s:NetrwSLeftrelease")
Bram Moolenaarff034192013-04-24 18:51:19 +02005815endfun
5816
5817" ---------------------------------------------------------------------
Bram Moolenaar91359012019-11-30 17:57:03 +01005818" s:NetrwListHide: uses [range]g~...~d to delete files that match {{{2
5819" comma-separated patterns given in g:netrw_list_hide
Bram Moolenaar446cb832008-06-24 21:56:24 +00005820fun! s:NetrwListHide()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005821" 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 +02005822" call Decho("initial: ".string(getline(w:netrw_bannercnt,'$')))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005823 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005824
5825 " 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 +02005826 " How-it-works: take the hiding command, convert it into a range.
5827 " Duplicate characters don't matter.
5828 " Remove all such characters from the '/~@#...890' string.
5829 " Use the first character left as a separator character.
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005830" call Decho("find a character not in the hide string to use as a separator",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005831 let listhide= g:netrw_list_hide
Bram Moolenaar91359012019-11-30 17:57:03 +01005832 let sep = strpart(substitute('~@#$%^&*{};:,<.>?|1234567890','['.escape(listhide,'-]^\').']','','ge'),1,1)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005833" call Decho("sep<".sep."> (sep not in hide string)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005834
5835 while listhide != ""
5836 if listhide =~ ','
5837 let hide = substitute(listhide,',.*$','','e')
5838 let listhide = substitute(listhide,'^.\{-},\(.*\)$','\1','e')
5839 else
5840 let hide = listhide
5841 let listhide = ""
5842 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005843" 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 +01005844 if g:netrw_sort_by =~ '^[ts]'
5845 if hide =~ '^\^'
5846" call Decho("..modify hide to handle a \"^...\" pattern",'~'.expand("<slnum>"))
5847 let hide= substitute(hide,'^\^','^\(\\d\\+/\)','')
5848 elseif hide =~ '^\\(\^'
5849 let hide= substitute(hide,'^\\(\^','\\(^\\(\\d\\+/\\)','')
5850 endif
5851" call Decho("..hide<".hide."> listhide<".listhide.'>','~'.expand("<slnum>"))
5852 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005853
5854 " Prune the list by hiding any files which match
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02005855" 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 +00005856 if g:netrw_hide == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02005857" call Decho("..hiding<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005858 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'d'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005859 elseif g:netrw_hide == 2
Bram Moolenaar85850f32019-07-19 22:05:51 +02005860" call Decho("..showing<".hide.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005861 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g'.sep.hide.sep.'s@^@ /-KEEP-/ @'
Bram Moolenaar446cb832008-06-24 21:56:24 +00005862 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005863" call Decho("..result: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005864 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02005865
Bram Moolenaar446cb832008-06-24 21:56:24 +00005866 if g:netrw_hide == 2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005867 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$v@^ /-KEEP-/ @d'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005868" call Decho("..v KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005869 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s@^\%( /-KEEP-/ \)\+@@e'
Bram Moolenaar85850f32019-07-19 22:05:51 +02005870" call Decho("..g KEEP: ".string(getline(w:netrw_bannercnt,'$')),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005871 endif
5872
Bram Moolenaaradc21822011-04-01 18:03:16 +02005873 " remove any blank lines that have somehow remained.
5874 " This seems to happen under Windows.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005875 exe 'sil! NetrwKeepj 1,$g@^\s*$@d'
Bram Moolenaaradc21822011-04-01 18:03:16 +02005876
Bram Moolenaar97d62492012-11-15 21:28:22 +01005877 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005878" call Dret("s:NetrwListHide")
Bram Moolenaar446cb832008-06-24 21:56:24 +00005879endfun
5880
5881" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00005882" s:NetrwMakeDir: this function makes a directory (both local and remote) {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005883" implements the "d" mapping.
Bram Moolenaar446cb832008-06-24 21:56:24 +00005884fun! s:NetrwMakeDir(usrhost)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005885
Bram Moolenaar97d62492012-11-15 21:28:22 +01005886 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00005887 " get name of new directory from user. A bare <CR> will skip.
5888 " if its currently a directory, also request will be skipped, but with
5889 " a message.
5890 call inputsave()
5891 let newdirname= input("Please give directory name: ")
5892 call inputrestore()
Bram Moolenaar446cb832008-06-24 21:56:24 +00005893
5894 if newdirname == ""
Bram Moolenaar97d62492012-11-15 21:28:22 +01005895 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005896 return
5897 endif
5898
5899 if a:usrhost == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00005900
5901 " Local mkdir:
5902 " sanity checks
5903 let fullnewdir= b:netrw_curdir.'/'.newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005904 if isdirectory(s:NetrwFile(fullnewdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005905 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005906 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a directory!",24)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005907 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005908 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005909 return
5910 endif
5911 if s:FileReadable(fullnewdir)
5912 if !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005913 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"<".newdirname."> is already a file!",25)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005914 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01005915 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00005916 return
5917 endif
5918
5919 " requested new local directory is neither a pre-existing file or
5920 " directory, so make it!
5921 if exists("*mkdir")
Bram Moolenaar8d043172014-01-23 14:24:41 +01005922 if has("unix")
5923 call mkdir(fullnewdir,"p",xor(0777, system("umask")))
5924 else
5925 call mkdir(fullnewdir,"p")
5926 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005927 else
5928 let netrw_origdir= s:NetrwGetcwd(1)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005929 if s:NetrwLcd(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005930 return
5931 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02005932 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(newdirname,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01005933 if v:shell_error != 0
5934 let @@= ykeep
5935 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 +01005936 return
5937 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005938 if !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02005939 if s:NetrwLcd(netrw_origdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02005940 return
5941 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005942 endif
5943 endif
5944
5945 if v:shell_error == 0
5946 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005947 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005948 call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005949 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005950 elseif !exists("g:netrw_quiet")
5951 call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",26)
5952 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005953
5954 elseif !exists("b:netrw_method") || b:netrw_method == 4
Bram Moolenaara6878372014-03-22 21:02:50 +01005955 " Remote mkdir: using ssh
Bram Moolenaar446cb832008-06-24 21:56:24 +00005956 let mkdircmd = s:MakeSshCmd(g:netrw_mkdir_cmd)
5957 let newdirname= substitute(b:netrw_curdir,'^\%(.\{-}/\)\{3}\(.*\)$','\1','').newdirname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01005958 call s:NetrwExe("sil! !".mkdircmd." ".s:ShellEscape(newdirname,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00005959 if v:shell_error == 0
5960 " refresh listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005961 let svpos= winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01005962 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005963 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005964 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01005965 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to make directory<".newdirname.">",27)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005966 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00005967
5968 elseif b:netrw_method == 2
Bram Moolenaara6878372014-03-22 21:02:50 +01005969 " Remote mkdir: using ftp+.netrc
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005970 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01005971 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01005972 let remotepath= b:netrw_fname
5973 else
5974 let remotepath= ""
5975 endif
5976 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01005977 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005978 NetrwKeepj call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01005979
Bram Moolenaar446cb832008-06-24 21:56:24 +00005980 elseif b:netrw_method == 3
Bram Moolenaara6878372014-03-22 21:02:50 +01005981 " Remote mkdir: using ftp + machine, id, passwd, and fname (ie. no .netrc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005982 let svpos= winsaveview()
Bram Moolenaara6878372014-03-22 21:02:50 +01005983 if exists("b:netrw_fname")
Bram Moolenaara6878372014-03-22 21:02:50 +01005984 let remotepath= b:netrw_fname
5985 else
5986 let remotepath= ""
5987 endif
5988 call s:NetrwRemoteFtpCmd(remotepath,g:netrw_remote_mkdir.' "'.newdirname.'"')
Tom Benham64a536d2024-11-07 21:15:03 +01005989 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01005990 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00005991 endif
5992
Bram Moolenaar97d62492012-11-15 21:28:22 +01005993 let @@= ykeep
Bram Moolenaara6878372014-03-22 21:02:50 +01005994endfun
5995
5996" ---------------------------------------------------------------------
5997" s:TreeSqueezeDir: allows a shift-cr (gvim only) to squeeze the current tree-listing directory {{{2
5998fun! s:TreeSqueezeDir(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01005999 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
6000 " its a tree-listing style
6001 let curdepth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara6878372014-03-22 21:02:50 +01006002 let stopline = (exists("w:netrw_bannercnt")? (w:netrw_bannercnt + 1) : 1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006003 let depth = strchars(substitute(curdepth,' ','','g'))
6004 let srch = -1
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006005 if depth >= 2
6006 NetrwKeepj norm! 0
6007 let curdepthm1= substitute(curdepth,'^'.s:treedepthstring,'','')
6008 let srch = search('^'.curdepthm1.'\%('.s:treedepthstring.'\)\@!','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006009 elseif depth == 1
6010 NetrwKeepj norm! 0
6011 let treedepthchr= substitute(s:treedepthstring,' ','','')
6012 let srch = search('^[^'.treedepthchr.']','bW',stopline)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006013 endif
6014 if srch > 0
Tom Benham64a536d2024-11-07 21:15:03 +01006015 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,s:NetrwGetWord(),1))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006016 exe srch
6017 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006018 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006019endfun
6020
6021" ---------------------------------------------------------------------
6022" s:NetrwMaps: {{{2
6023fun! s:NetrwMaps(islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01006024
Bram Moolenaar85850f32019-07-19 22:05:51 +02006025 " mouse <Plug> maps: {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006026 if g:netrw_mousemaps && g:netrw_retmap
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006027" call Decho("set up Rexplore 2-leftmouse",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006028 if !hasmapto("<Plug>NetrwReturn")
6029 if maparg("<2-leftmouse>","n") == "" || maparg("<2-leftmouse>","n") =~ '^-$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006030 nmap <unique> <silent> <2-leftmouse> <Plug>NetrwReturn
6031 elseif maparg("<c-leftmouse>","n") == ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006032 nmap <unique> <silent> <c-leftmouse> <Plug>NetrwReturn
6033 endif
6034 endif
6035 nno <silent> <Plug>NetrwReturn :Rexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006036 endif
6037
Bram Moolenaar85850f32019-07-19 22:05:51 +02006038 " generate default <Plug> maps {{{3
6039 if !hasmapto('<Plug>NetrwHide') |nmap <buffer> <silent> <nowait> a <Plug>NetrwHide_a|endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006040 if !hasmapto('<Plug>NetrwBrowseUpDir') |nmap <buffer> <silent> <nowait> - <Plug>NetrwBrowseUpDir|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006041 if !hasmapto('<Plug>NetrwOpenFile') |nmap <buffer> <silent> <nowait> % <Plug>NetrwOpenFile|endif
6042 if !hasmapto('<Plug>NetrwBadd_cb') |nmap <buffer> <silent> <nowait> cb <Plug>NetrwBadd_cb|endif
6043 if !hasmapto('<Plug>NetrwBadd_cB') |nmap <buffer> <silent> <nowait> cB <Plug>NetrwBadd_cB|endif
6044 if !hasmapto('<Plug>NetrwLcd') |nmap <buffer> <silent> <nowait> cd <Plug>NetrwLcd|endif
6045 if !hasmapto('<Plug>NetrwSetChgwin') |nmap <buffer> <silent> <nowait> C <Plug>NetrwSetChgwin|endif
6046 if !hasmapto('<Plug>NetrwRefresh') |nmap <buffer> <silent> <nowait> <c-l> <Plug>NetrwRefresh|endif
6047 if !hasmapto('<Plug>NetrwLocalBrowseCheck') |nmap <buffer> <silent> <nowait> <cr> <Plug>NetrwLocalBrowseCheck|endif
6048 if !hasmapto('<Plug>NetrwServerEdit') |nmap <buffer> <silent> <nowait> <c-r> <Plug>NetrwServerEdit|endif
6049 if !hasmapto('<Plug>NetrwMakeDir') |nmap <buffer> <silent> <nowait> d <Plug>NetrwMakeDir|endif
6050 if !hasmapto('<Plug>NetrwBookHistHandler_gb')|nmap <buffer> <silent> <nowait> gb <Plug>NetrwBookHistHandler_gb|endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006051
Bram Moolenaara6878372014-03-22 21:02:50 +01006052 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02006053 " local normal-mode maps {{{3
6054 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(1)<cr>
6055 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(1)<cr>
6056 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(1)<cr>
6057 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(1,0)<cr>
6058 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(1,1)<cr>
6059 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6060 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006061 nnoremap <buffer> <silent> <Plug>NetrwLocalBrowseCheck :<c-u>call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1,<SID>NetrwGetWord(),1))<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006062 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(3,<SID>NetrwGetWord())<cr>
6063 nnoremap <buffer> <silent> <Plug>NetrwMakeDir :<c-u>call <SID>NetrwMakeDir("")<cr>
6064 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6065" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006066 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(1,<SID>NetrwGetWord())<cr>
6067 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(1,<SID>NetrwGetWord())<cr>
6068 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(1)<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006069 nnoremap <buffer> <silent> <nowait> gn :<c-u>call netrw#SetTreetop(0,<SID>NetrwGetWord())<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006070 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(1,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006071 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6072 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(1)<cr>
6073 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(1,0)<cr>
6074 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(1,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006075 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
6076 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
6077 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(1)<cr>
6078 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(1)<cr>
6079 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(1)<cr>
6080 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(1,<SID>NetrwGetWord())<cr>
6081 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6082 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(1)<cr>
6083 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(1)<cr>
6084 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(1)<cr>
6085 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(1)<cr>
6086 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(1)<cr>
6087 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006088 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006089 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006090 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(1)<cr>
6091 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(1)<cr>
6092 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(1,0)<cr>
6093 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(1,1)<cr>
6094 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006095 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006096 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(3)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006097 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 +01006098 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006099 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
6100 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(1,<SID>NetrwGetWord())<cr>
6101 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(1,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006102 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(1,getloclist(v:count))<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006103 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(1)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006104 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(1)<cr>
6105 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(1,'b',v:count1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006106 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(4)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006107 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(1,'h',v:count)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006108 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,expand("%"))<cr>
6109 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,expand("%"))<cr>
6110 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(5)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006111 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 +01006112 nnoremap <buffer> <silent> <nowait> X :<c-u>call <SID>NetrwLocalExecute(expand("<cword>"))"<cr>
Bram Moolenaar85850f32019-07-19 22:05:51 +02006113
Tom Benham64a536d2024-11-07 21:15:03 +01006114 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 +01006115 if !hasmapto('<Plug>NetrwHideEdit')
6116 nmap <buffer> <unique> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006117 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006118 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006119 if !hasmapto('<Plug>NetrwRefresh')
6120 nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006121 endif
Tom Benham64a536d2024-11-07 21:15:03 +01006122 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 +01006123 if s:didstarstar || !mapcheck("<s-down>","n")
6124 nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006125 endif
6126 if s:didstarstar || !mapcheck("<s-up>","n")
6127 nnoremap <buffer> <silent> <s-up> :Pexplore<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006128 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006129 if !hasmapto('<Plug>NetrwTreeSqueeze')
6130 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006131 endif
6132 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(1)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006133 let mapsafecurdir = escape(b:netrw_curdir, s:netrw_map_escape)
6134 if g:netrw_mousemaps == 1
Bram Moolenaar85850f32019-07-19 22:05:51 +02006135 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
6136 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
6137 nmap <buffer> <middlemouse> <Plug>NetrwMiddlemouse
6138 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
6139 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
6140 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6141 imap <buffer> <leftmouse> <Plug>ILeftmouse
6142 imap <buffer> <middlemouse> <Plug>IMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006143 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(1)<cr>
6144 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(1)<cr>
6145 nno <buffer> <silent> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(1)<cr>
6146 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(1)<cr>
6147 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006148 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
user202729bdb9d9a2024-01-29 05:29:21 +07006149 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6150 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006151 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006152 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6153 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6154 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
6155 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("")<cr>'
6156 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6157 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwLocalRm("'.mapsafecurdir.'")<cr>'
6158 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwLocalRename("'.mapsafecurdir.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006159 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
6160
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006161 " support user-specified maps
6162 call netrw#UserMaps(1)
6163
Bram Moolenaar85850f32019-07-19 22:05:51 +02006164 else
6165 " remote normal-mode maps {{{3
Bram Moolenaara6878372014-03-22 21:02:50 +01006166 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006167 nnoremap <buffer> <silent> <Plug>NetrwHide_a :<c-u>call <SID>NetrwHide(0)<cr>
6168 nnoremap <buffer> <silent> <Plug>NetrwBrowseUpDir :<c-u>call <SID>NetrwBrowseUpDir(0)<cr>
6169 nnoremap <buffer> <silent> <Plug>NetrwOpenFile :<c-u>call <SID>NetrwOpenFile(0)<cr>
6170 nnoremap <buffer> <silent> <Plug>NetrwBadd_cb :<c-u>call <SID>NetrwBadd(0,0)<cr>
6171 nnoremap <buffer> <silent> <Plug>NetrwBadd_cB :<c-u>call <SID>NetrwBadd(0,1)<cr>
6172 nnoremap <buffer> <silent> <Plug>NetrwLcd :<c-u>call <SID>NetrwLcd(b:netrw_curdir)<cr>
6173 nnoremap <buffer> <silent> <Plug>NetrwSetChgwin :<c-u>call <SID>NetrwSetChgwin()<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006174 nnoremap <buffer> <silent> <Plug>NetrwRefresh :<c-u>call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
6175 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 +02006176 nnoremap <buffer> <silent> <Plug>NetrwServerEdit :<c-u>call <SID>NetrwServerEdit(2,<SID>NetrwGetWord())<cr>
6177 nnoremap <buffer> <silent> <Plug>NetrwBookHistHandler_gb :<c-u>call <SID>NetrwBookHistHandler(1,b:netrw_curdir)<cr>
6178" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006179 nnoremap <buffer> <silent> <nowait> gd :<c-u>call <SID>NetrwForceChgDir(0,<SID>NetrwGetWord())<cr>
6180 nnoremap <buffer> <silent> <nowait> gf :<c-u>call <SID>NetrwForceFile(0,<SID>NetrwGetWord())<cr>
6181 nnoremap <buffer> <silent> <nowait> gh :<c-u>call <SID>NetrwHidden(0)<cr>
6182 nnoremap <buffer> <silent> <nowait> gp :<c-u>call <SID>NetrwChgPerm(0,b:netrw_curdir)<cr>
6183 nnoremap <buffer> <silent> <nowait> I :<c-u>call <SID>NetrwBannerCtrl(1)<cr>
6184 nnoremap <buffer> <silent> <nowait> i :<c-u>call <SID>NetrwListStyle(0)<cr>
6185 nnoremap <buffer> <silent> <nowait> ma :<c-u>call <SID>NetrwMarkFileArgList(0,0)<cr>
6186 nnoremap <buffer> <silent> <nowait> mA :<c-u>call <SID>NetrwMarkFileArgList(0,1)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006187 nnoremap <buffer> <silent> <nowait> mb :<c-u>call <SID>NetrwBookHistHandler(0,b:netrw_curdir)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006188 nnoremap <buffer> <silent> <nowait> mB :<c-u>call <SID>NetrwBookHistHandler(6,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006189 nnoremap <buffer> <silent> <nowait> mc :<c-u>call <SID>NetrwMarkFileCopy(0)<cr>
6190 nnoremap <buffer> <silent> <nowait> md :<c-u>call <SID>NetrwMarkFileDiff(0)<cr>
6191 nnoremap <buffer> <silent> <nowait> me :<c-u>call <SID>NetrwMarkFileEdit(0)<cr>
6192 nnoremap <buffer> <silent> <nowait> mf :<c-u>call <SID>NetrwMarkFile(0,<SID>NetrwGetWord())<cr>
6193 nnoremap <buffer> <silent> <nowait> mF :<c-u>call <SID>NetrwUnmarkList(bufnr("%"),b:netrw_curdir)<cr>
6194 nnoremap <buffer> <silent> <nowait> mg :<c-u>call <SID>NetrwMarkFileGrep(0)<cr>
6195 nnoremap <buffer> <silent> <nowait> mh :<c-u>call <SID>NetrwMarkHideSfx(0)<cr>
6196 nnoremap <buffer> <silent> <nowait> mm :<c-u>call <SID>NetrwMarkFileMove(0)<cr>
6197 nnoremap <buffer> <silent> <nowait> mp :<c-u>call <SID>NetrwMarkFilePrint(0)<cr>
6198 nnoremap <buffer> <silent> <nowait> mr :<c-u>call <SID>NetrwMarkFileRegexp(0)<cr>
6199 nnoremap <buffer> <silent> <nowait> ms :<c-u>call <SID>NetrwMarkFileSource(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006200 nnoremap <buffer> <silent> <nowait> mT :<c-u>call <SID>NetrwMarkFileTag(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006201 nnoremap <buffer> <silent> <nowait> mt :<c-u>call <SID>NetrwMarkFileTgt(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006202 nnoremap <buffer> <silent> <nowait> mu :<c-u>call <SID>NetrwUnMarkFile(0)<cr>
6203 nnoremap <buffer> <silent> <nowait> mv :<c-u>call <SID>NetrwMarkFileVimCmd(0)<cr>
6204 nnoremap <buffer> <silent> <nowait> mx :<c-u>call <SID>NetrwMarkFileExe(0,0)<cr>
6205 nnoremap <buffer> <silent> <nowait> mX :<c-u>call <SID>NetrwMarkFileExe(0,1)<cr>
6206 nnoremap <buffer> <silent> <nowait> mz :<c-u>call <SID>NetrwMarkFileCompress(0)<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006207 nnoremap <buffer> <silent> <nowait> O :<c-u>call <SID>NetrwObtain(0)<cr>
6208 nnoremap <buffer> <silent> <nowait> o :call <SID>NetrwSplit(0)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006209 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 +01006210 nnoremap <buffer> <silent> <nowait> P :<c-u>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006211 nnoremap <buffer> <silent> <nowait> qb :<c-u>call <SID>NetrwBookHistHandler(2,b:netrw_curdir)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006212 nnoremap <buffer> <silent> <nowait> qf :<c-u>call <SID>NetrwFileInfo(0,<SID>NetrwGetWord())<cr>
6213 nnoremap <buffer> <silent> <nowait> qF :<c-u>call <SID>NetrwMarkFileQFEL(0,getqflist())<cr>
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006214 nnoremap <buffer> <silent> <nowait> qL :<c-u>call <SID>NetrwMarkFileQFEL(0,getloclist(v:count))<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006215 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 +01006216 nnoremap <buffer> <silent> <nowait> s :call <SID>NetrwSortStyle(0)<cr>
6217 nnoremap <buffer> <silent> <nowait> S :<c-u>call <SID>NetSortSequence(0)<cr>
6218 nnoremap <buffer> <silent> <nowait> Tb :<c-u>call <SID>NetrwSetTgt(0,'b',v:count1)<cr>
6219 nnoremap <buffer> <silent> <nowait> t :call <SID>NetrwSplit(1)<cr>
6220 nnoremap <buffer> <silent> <nowait> Th :<c-u>call <SID>NetrwSetTgt(0,'h',v:count)<cr>
6221 nnoremap <buffer> <silent> <nowait> u :<c-u>call <SID>NetrwBookHistHandler(4,b:netrw_curdir)<cr>
6222 nnoremap <buffer> <silent> <nowait> U :<c-u>call <SID>NetrwBookHistHandler(5,b:netrw_curdir)<cr>
6223 nnoremap <buffer> <silent> <nowait> v :call <SID>NetrwSplit(2)<cr>
Tom Benham64a536d2024-11-07 21:15:03 +01006224 nnoremap <buffer> <silent> <nowait> x :<c-u>call netrw#BrowseX(<SID>NetrwBrowseChgDir(0,<SID>NetrwGetWord(),1),1)<cr>
Konfekt3d7e5672024-10-27 22:16:49 +01006225 nmap <buffer> <nowait> gx x
Bram Moolenaara6878372014-03-22 21:02:50 +01006226 if !hasmapto('<Plug>NetrwHideEdit')
6227 nmap <buffer> <c-h> <Plug>NetrwHideEdit
Bram Moolenaara6878372014-03-22 21:02:50 +01006228 endif
6229 nnoremap <buffer> <silent> <Plug>NetrwHideEdit :call <SID>NetrwHideEdit(0)<cr>
6230 if !hasmapto('<Plug>NetrwRefresh')
6231 nmap <buffer> <c-l> <Plug>NetrwRefresh
Bram Moolenaara6878372014-03-22 21:02:50 +01006232 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006233 if !hasmapto('<Plug>NetrwTreeSqueeze')
6234 nmap <buffer> <silent> <nowait> <s-cr> <Plug>NetrwTreeSqueeze
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006235 endif
6236 nnoremap <buffer> <silent> <Plug>NetrwTreeSqueeze :call <SID>TreeSqueezeDir(0)<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006237
6238 let mapsafepath = escape(s:path, s:netrw_map_escape)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006239 let mapsafeusermach = escape(((s:user == "")? "" : s:user."@").s:machine, s:netrw_map_escape)
Bram Moolenaara6878372014-03-22 21:02:50 +01006240
Tom Benham64a536d2024-11-07 21:15:03 +01006241 nnoremap <buffer> <silent> <Plug>NetrwRefresh :call <SID>NetrwRefresh(0,<SID>NetrwBrowseChgDir(0,'./',0))<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006242 if g:netrw_mousemaps == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006243 nmap <buffer> <leftmouse> <Plug>NetrwLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006244 nno <buffer> <silent> <Plug>NetrwLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006245 nmap <buffer> <c-leftmouse> <Plug>NetrwCLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006246 nno <buffer> <silent> <Plug>NetrwCLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwCLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006247 nmap <buffer> <s-leftmouse> <Plug>NetrwSLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006248 nno <buffer> <silent> <Plug>NetrwSLeftmouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftmouse(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006249 nmap <buffer> <s-leftdrag> <Plug>NetrwSLeftdrag
user202729bdb9d9a2024-01-29 05:29:21 +07006250 nno <buffer> <silent> <Plug>NetrwSLeftdrag :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwSLeftdrag(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006251 nmap <middlemouse> <Plug>NetrwMiddlemouse
user202729bdb9d9a2024-01-29 05:29:21 +07006252 nno <buffer> <silent> <middlemouse> <Plug>NetrwMiddlemouse :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwPrevWinOpen(0)<cr>
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006253 nmap <buffer> <2-leftmouse> <Plug>Netrw2Leftmouse
6254 nmap <buffer> <silent> <Plug>Netrw2Leftmouse -
6255 imap <buffer> <leftmouse> <Plug>ILeftmouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006256 imap <buffer> <middlemouse> <Plug>IMiddlemouse
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006257 imap <buffer> <s-leftmouse> <Plug>ISLeftmouse
user202729bdb9d9a2024-01-29 05:29:21 +07006258 exe 'nnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6259 exe 'vnoremap <buffer> <silent> <rightmouse> :exec "norm! \<lt>leftmouse>"<bar>call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006260 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006261 exe 'nnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6262 exe 'nnoremap <buffer> <silent> <nowait> d :call <SID>NetrwMakeDir("'.mapsafeusermach.'")<cr>'
6263 exe 'nnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6264 exe 'nnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6265 exe 'vnoremap <buffer> <silent> <nowait> <del> :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6266 exe 'vnoremap <buffer> <silent> <nowait> D :call <SID>NetrwRemoteRm("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
6267 exe 'vnoremap <buffer> <silent> <nowait> R :call <SID>NetrwRemoteRename("'.mapsafeusermach.'","'.mapsafepath.'")<cr>'
Bram Moolenaara6878372014-03-22 21:02:50 +01006268 nnoremap <buffer> <F1> :he netrw-quickhelp<cr>
Bram Moolenaara6878372014-03-22 21:02:50 +01006269
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006270 " support user-specified maps
6271 call netrw#UserMaps(0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02006272 endif " }}}3
Bram Moolenaara6878372014-03-22 21:02:50 +01006273endfun
6274
6275" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006276" s:NetrwCommands: set up commands {{{2
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006277" If -buffer, the command is only available from within netrw buffers
6278" Otherwise, the command is available from any window, so long as netrw
6279" has been used at least once in the session.
Bram Moolenaara6878372014-03-22 21:02:50 +01006280fun! s:NetrwCommands(islocal)
6281" call Dfunc("s:NetrwCommands(islocal=".a:islocal.")")
6282
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006283 com! -nargs=* -complete=file -bang NetrwMB call s:NetrwBookmark(<bang>0,<f-args>)
6284 com! -nargs=* NetrwC call s:NetrwSetChgwin(<q-args>)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006285 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 +01006286 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006287 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(1,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006288 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006289 com! -buffer -nargs=+ -complete=file MF call s:NetrwMarkFiles(0,<f-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006290 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006291 com! -buffer -nargs=? -complete=file MT call s:NetrwMarkTarget(<q-args>)
Bram Moolenaara6878372014-03-22 21:02:50 +01006292
6293" call Dret("s:NetrwCommands")
6294endfun
6295
6296" ---------------------------------------------------------------------
6297" s:NetrwMarkFiles: apply s:NetrwMarkFile() to named file(s) {{{2
6298" glob()ing only works with local files
6299fun! s:NetrwMarkFiles(islocal,...)
6300" call Dfunc("s:NetrwMarkFiles(islocal=".a:islocal."...) a:0=".a:0)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006301 let curdir = s:NetrwGetCurdir(a:islocal)
6302 let i = 1
Bram Moolenaara6878372014-03-22 21:02:50 +01006303 while i <= a:0
6304 if a:islocal
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006305 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar91359012019-11-30 17:57:03 +01006306 let mffiles= glob(a:{i},0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006307 else
Bram Moolenaar91359012019-11-30 17:57:03 +01006308 let mffiles= glob(a:{i},0,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006309 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006310 else
6311 let mffiles= [a:{i}]
6312 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006313" call Decho("mffiles".string(mffiles),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006314 for mffile in mffiles
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006315" call Decho("mffile<".mffile.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01006316 call s:NetrwMarkFile(a:islocal,mffile)
6317 endfor
6318 let i= i + 1
6319 endwhile
6320" call Dret("s:NetrwMarkFiles")
6321endfun
6322
6323" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006324" s:NetrwMarkTarget: implements :MT (mark target) {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01006325fun! s:NetrwMarkTarget(...)
Bram Moolenaara6878372014-03-22 21:02:50 +01006326 if a:0 == 0 || (a:0 == 1 && a:1 == "")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006327 let curdir = s:NetrwGetCurdir(1)
6328 let tgt = b:netrw_curdir
Bram Moolenaara6878372014-03-22 21:02:50 +01006329 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006330 let curdir = s:NetrwGetCurdir((a:1 =~ '^\a\{3,}://')? 0 : 1)
6331 let tgt = a:1
Bram Moolenaara6878372014-03-22 21:02:50 +01006332 endif
Bram Moolenaara6878372014-03-22 21:02:50 +01006333 let s:netrwmftgt = tgt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006334 let s:netrwmftgt_islocal = tgt !~ '^\a\{3,}://'
6335 let curislocal = b:netrw_curdir !~ '^\a\{3,}://'
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006336 let svpos = winsaveview()
Tom Benham64a536d2024-11-07 21:15:03 +01006337 call s:NetrwRefresh(curislocal,s:NetrwBrowseChgDir(curislocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006338 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006339endfun
6340
6341" ---------------------------------------------------------------------
6342" s:NetrwMarkFile: (invoked by mf) This function is used to both {{{2
6343" mark and unmark files. If a markfile list exists,
6344" then the rename and delete functions will use it instead
6345" of whatever may happen to be under the cursor at that
6346" moment. When the mouse and gui are available,
6347" shift-leftmouse may also be used to mark files.
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006348"
6349" Creates two lists
6350" s:netrwmarkfilelist -- holds complete paths to all marked files
6351" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
6352"
6353" Creates a marked file match string
6354" s:netrwmarfilemtch_# -- used with 2match to display marked files
6355"
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006356" Creates a buffer version of islocal
6357" b:netrw_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006358fun! s:NetrwMarkFile(islocal,fname)
6359" call Dfunc("s:NetrwMarkFile(islocal=".a:islocal." fname<".a:fname.">)")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006360" call Decho("bufnr(%)=".bufnr("%").": ".bufname("%"),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006361
6362 " sanity check
6363 if empty(a:fname)
Bram Moolenaar6c391a72021-09-09 21:55:11 +02006364" call Dret("s:NetrwMarkFile : empty fname")
Bram Moolenaarff034192013-04-24 18:51:19 +02006365 return
6366 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006367 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006368
Bram Moolenaar97d62492012-11-15 21:28:22 +01006369 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00006370 let curbufnr= bufnr("%")
yasudac18a9d52024-09-19 18:09:51 +02006371 let leader= '\%(^\|\s\)\zs'
Bram Moolenaara6878372014-03-22 21:02:50 +01006372 if a:fname =~ '\a$'
6373 let trailer = '\>[@=|\/\*]\=\ze\%( \|\t\|$\)'
6374 else
6375 let trailer = '[@=|\/\*]\=\ze\%( \|\t\|$\)'
6376 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02006377
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006378 if exists("s:netrwmarkfilelist_".curbufnr)
Bram Moolenaaradc21822011-04-01 18:03:16 +02006379 " markfile list pre-exists
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006380" call Decho("case s:netrwmarkfilelist_".curbufnr." already exists",'~'.expand("<slnum>"))
6381" call Decho("starting s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
6382" call Decho("starting s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006383 let b:netrw_islocal= a:islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006384
6385 if index(s:netrwmarkfilelist_{curbufnr},a:fname) == -1
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006386 " append filename to buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006387" call Decho("append filename<".a:fname."> to local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006388 call add(s:netrwmarkfilelist_{curbufnr},a:fname)
Bram Moolenaara6878372014-03-22 21:02:50 +01006389 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006390
6391 else
Bram Moolenaared39e1d2008-08-09 17:55:22 +00006392 " remove filename from buffer's markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006393" call Decho("remove filename<".a:fname."> from local markfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006394 call filter(s:netrwmarkfilelist_{curbufnr},'v:val != a:fname')
6395 if s:netrwmarkfilelist_{curbufnr} == []
6396 " local markfilelist is empty; remove it entirely
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006397" call Decho("markfile list now empty",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006398 call s:NetrwUnmarkList(curbufnr,curdir)
6399 else
6400 " rebuild match list to display markings correctly
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006401" call Decho("rebuild s:netrwmarkfilemtch_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006402 let s:netrwmarkfilemtch_{curbufnr}= ""
Bram Moolenaara6878372014-03-22 21:02:50 +01006403 let first = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006404 for fname in s:netrwmarkfilelist_{curbufnr}
6405 if first
Bram Moolenaara6878372014-03-22 21:02:50 +01006406 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006407 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006408 let s:netrwmarkfilemtch_{curbufnr}= s:netrwmarkfilemtch_{curbufnr}.'\|'.leader.escape(fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006409 endif
6410 let first= 0
6411 endfor
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006412" call Decho("ending s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006413 endif
6414 endif
6415
6416 else
6417 " initialize new markfilelist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006418" call Decho("case: initialize new markfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006419
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006420" call Decho("add fname<".a:fname."> to new markfilelist_".curbufnr,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006421 let s:netrwmarkfilelist_{curbufnr}= []
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006422 call add(s:netrwmarkfilelist_{curbufnr},substitute(a:fname,'[|@]$','',''))
6423" call Decho("ending s:netrwmarkfilelist_{curbufnr}<".string(s:netrwmarkfilelist_{curbufnr}).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006424
6425 " build initial markfile matching pattern
6426 if a:fname =~ '/$'
Bram Moolenaara6878372014-03-22 21:02:50 +01006427 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006428 else
Bram Moolenaara6878372014-03-22 21:02:50 +01006429 let s:netrwmarkfilemtch_{curbufnr}= leader.escape(a:fname,g:netrw_markfileesc).trailer
Bram Moolenaar446cb832008-06-24 21:56:24 +00006430 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006431" call Decho("ending s:netrwmarkfilemtch_".curbufnr."<".s:netrwmarkfilemtch_{curbufnr}.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006432 endif
6433
6434 " handle global markfilelist
6435 if exists("s:netrwmarkfilelist")
6436 let dname= s:ComposePath(b:netrw_curdir,a:fname)
6437 if index(s:netrwmarkfilelist,dname) == -1
6438 " append new filename to global markfilelist
6439 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006440" call Decho("append filename<".a:fname."> to global s:markfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006441 else
6442 " remove new filename from global markfilelist
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006443" call Decho("remove new filename from global s:markfilelist",'~'.expand("<slnum>"))
6444" call Decho("..filter(".string(s:netrwmarkfilelist).",'v:val != '.".dname.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006445 call filter(s:netrwmarkfilelist,'v:val != "'.dname.'"')
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006446" call Decho("..ending s:netrwmarkfilelist <".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006447 if s:netrwmarkfilelist == []
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006448" call Decho("s:netrwmarkfilelist is empty; unlet it",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006449 unlet s:netrwmarkfilelist
6450 endif
6451 endif
6452 else
6453 " initialize new global-directory markfilelist
6454 let s:netrwmarkfilelist= []
6455 call add(s:netrwmarkfilelist,s:ComposePath(b:netrw_curdir,a:fname))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006456" call Decho("init s:netrwmarkfilelist<".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006457 endif
6458
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006459 " set up 2match'ing to netrwmarkfilemtch_# list
Bram Moolenaar85850f32019-07-19 22:05:51 +02006460 if has("syntax") && exists("g:syntax_on") && g:syntax_on
6461 if exists("s:netrwmarkfilemtch_{curbufnr}") && s:netrwmarkfilemtch_{curbufnr} != ""
6462" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/",'~'.expand("<slnum>"))
6463 if exists("g:did_drchip_netrwlist_syntax")
6464 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{curbufnr}."/"
6465 endif
6466 else
6467" " call Decho("2match none",'~'.expand("<slnum>"))
6468 2match none
Bram Moolenaar5c736222010-01-06 20:54:52 +01006469 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006470 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01006471 let @@= ykeep
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01006472" call Decho("s:netrwmarkfilelist[".(exists("s:netrwmarkfilelist")? string(s:netrwmarkfilelist) : "")."] (avail in all buffers)",'~'.expand("<slnum>"))
6473" 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 +00006474endfun
6475
6476" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006477" s:NetrwMarkFileArgList: ma: move the marked file list to the argument list (tomflist=0) {{{2
6478" mA: move the argument list to marked file list (tomflist=1)
6479" Uses the global marked file list
6480fun! s:NetrwMarkFileArgList(islocal,tomflist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006481 let svpos = winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006482 let curdir = s:NetrwGetCurdir(a:islocal)
6483 let curbufnr = bufnr("%")
6484
6485 if a:tomflist
6486 " mA: move argument list to marked file list
6487 while argc()
6488 let fname= argv(0)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006489 exe "argdel ".fnameescape(fname)
6490 call s:NetrwMarkFile(a:islocal,fname)
6491 endwhile
6492
6493 else
6494 " ma: move marked file list to argument list
6495 if exists("s:netrwmarkfilelist")
6496
6497 " for every filename in the marked list
6498 for fname in s:netrwmarkfilelist
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006499 exe "argadd ".fnameescape(fname)
6500 endfor " for every file in the marked list
6501
6502 " unmark list and refresh
6503 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006504 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006505 NetrwKeepj call winrestview(svpos)
6506 endif
6507 endif
6508
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006509endfun
6510
6511" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00006512" s:NetrwMarkFileCompress: (invoked by mz) This function is used to {{{2
6513" compress/decompress files using the programs
6514" in g:netrw_compress and g:netrw_uncompress,
6515" using g:netrw_compress_suffix to know which to
6516" do. By default:
6517" g:netrw_compress = "gzip"
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02006518" g:netrw_decompress = { ".gz" : "gunzip" , ".bz2" : "bunzip2" , ".zip" : "unzip" , ".tar" : "tar -xf", ".xz" : "unxz"}
Bram Moolenaar446cb832008-06-24 21:56:24 +00006519fun! s:NetrwMarkFileCompress(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006520 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006521 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006522 let curbufnr = bufnr("%")
6523
Bram Moolenaarff034192013-04-24 18:51:19 +02006524 " sanity check
6525 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006526 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006527 return
6528 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006529
Bram Moolenaar446cb832008-06-24 21:56:24 +00006530 if exists("s:netrwmarkfilelist_{curbufnr}") && exists("g:netrw_compress") && exists("g:netrw_decompress")
Bram Moolenaarff034192013-04-24 18:51:19 +02006531
6532 " for every filename in the marked list
Bram Moolenaar446cb832008-06-24 21:56:24 +00006533 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaarff034192013-04-24 18:51:19 +02006534 let sfx= substitute(fname,'^.\{-}\(\.\a\+\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006535 if exists("g:netrw_decompress['".sfx."']")
6536 " fname has a suffix indicating that its compressed; apply associated decompression routine
6537 let exe= g:netrw_decompress[sfx]
Bram Moolenaarff034192013-04-24 18:51:19 +02006538 let exe= netrw#WinPath(exe)
6539 if a:islocal
6540 if g:netrw_keepdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006541 let fname= s:ShellEscape(s:ComposePath(curdir,fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006542 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006543 call system(exe." ".fname)
6544 if v:shell_error
6545 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to apply<".exe."> to file<".fname.">",50)
Bram Moolenaar46973992017-12-14 19:56:46 +01006546 endif
6547 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006548 let fname= s:ShellEscape(b:netrw_curdir.fname,1)
6549 NetrwKeepj call s:RemoteSystem(exe." ".fname)
Bram Moolenaar46973992017-12-14 19:56:46 +01006550 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02006551
Bram Moolenaarff034192013-04-24 18:51:19 +02006552 endif
6553 unlet sfx
6554
Bram Moolenaar446cb832008-06-24 21:56:24 +00006555 if exists("exe")
6556 unlet exe
6557 elseif a:islocal
6558 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006559 call system(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(s:ComposePath(b:netrw_curdir,fname)))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006560 if v:shell_error
6561 call netrw#ErrorMsg(s:WARNING,"consider setting g:netrw_compress<".g:netrw_compress."> to something that works",104)
6562 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006563 else
6564 " fname not a compressed file, so compress it
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006565 NetrwKeepj call s:RemoteSystem(netrw#WinPath(g:netrw_compress)." ".s:ShellEscape(fname))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006566 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006567 endfor " for every file in the marked list
6568
Bram Moolenaar446cb832008-06-24 21:56:24 +00006569 call s:NetrwUnmarkList(curbufnr,curdir)
Tom Benham64a536d2024-11-07 21:15:03 +01006570 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006571 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006572 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006573endfun
6574
6575" ---------------------------------------------------------------------
6576" s:NetrwMarkFileCopy: (invoked by mc) copy marked files to target {{{2
6577" If no marked files, then set up directory as the
6578" target. Currently does not support copying entire
6579" directories. Uses the local-buffer marked file list.
6580" Returns 1=success (used by NetrwMarkFileMove())
6581" 0=failure
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006582fun! s:NetrwMarkFileCopy(islocal,...)
6583" call Dfunc("s:NetrwMarkFileCopy(islocal=".a:islocal.") target<".(exists("s:netrwmftgt")? s:netrwmftgt : '---')."> a:0=".a:0)
6584
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006585 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaarff034192013-04-24 18:51:19 +02006586 let curbufnr = bufnr("%")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006587 if b:netrw_curdir !~ '/$'
6588 if !exists("b:netrw_curdir")
6589 let b:netrw_curdir= curdir
6590 endif
6591 let b:netrw_curdir= b:netrw_curdir."/"
6592 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006593
Bram Moolenaarff034192013-04-24 18:51:19 +02006594 " sanity check
6595 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006596 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006597" call Dret("s:NetrwMarkFileCopy")
6598 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006599 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006600" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006601
Bram Moolenaar446cb832008-06-24 21:56:24 +00006602 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006603 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006604" call Dret("s:NetrwMarkFileCopy 0")
6605 return 0
6606 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006607" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006608
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006609 if a:islocal && s:netrwmftgt_islocal
Bram Moolenaar446cb832008-06-24 21:56:24 +00006610 " Copy marked files, local directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006611" call Decho("copy from local to local",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006612 if !executable(g:netrw_localcopycmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006613 call netrw#ErrorMsg(s:ERROR,"g:netrw_localcopycmd<".g:netrw_localcopycmd."> not executable on your system, aborting",91)
6614" call Dfunc("s:NetrwMarkFileMove : g:netrw_localcopycmd<".g:netrw_localcopycmd."> n/a!")
6615 return
6616 endif
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006617
6618 " copy marked files while within the same directory (ie. allow renaming)
Travis Sheltone34d0e32024-07-30 21:08:56 +02006619 if s:StripTrailingSlash(simplify(s:netrwmftgt)) == s:StripTrailingSlash(simplify(b:netrw_curdir))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006620 if len(s:netrwmarkfilelist_{bufnr('%')}) == 1
6621 " only one marked file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006622" call Decho("case: only one marked file",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006623 let args = s:ShellEscape(b:netrw_curdir.s:netrwmarkfilelist_{bufnr('%')}[0])
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006624 let oldname = s:netrwmarkfilelist_{bufnr('%')}[0]
6625 elseif a:0 == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006626" call Decho("case: handling one input argument",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006627 " this happens when the next case was used to recursively call s:NetrwMarkFileCopy()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006628 let args = s:ShellEscape(b:netrw_curdir.a:1)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006629 let oldname = a:1
6630 else
6631 " copy multiple marked files inside the same directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006632" call Decho("case: handling a multiple marked files",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006633 let s:recursive= 1
6634 for oldname in s:netrwmarkfilelist_{bufnr("%")}
6635 let ret= s:NetrwMarkFileCopy(a:islocal,oldname)
6636 if ret == 0
6637 break
6638 endif
6639 endfor
6640 unlet s:recursive
6641 call s:NetrwUnmarkList(curbufnr,curdir)
6642" call Dret("s:NetrwMarkFileCopy ".ret)
6643 return ret
6644 endif
6645
6646 call inputsave()
6647 let newname= input("Copy ".oldname." to : ",oldname,"file")
6648 call inputrestore()
6649 if newname == ""
6650" call Dret("s:NetrwMarkFileCopy 0")
6651 return 0
6652 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006653 let args= s:ShellEscape(oldname)
6654 let tgt = s:ShellEscape(s:netrwmftgt.'/'.newname)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006655 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006656 let args= join(map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),"s:ShellEscape(b:netrw_curdir.\"/\".v:val)"))
6657 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006658 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02006659 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02006660 let args= substitute(args,'/','\\','g')
6661 let tgt = substitute(tgt, '/','\\','g')
6662 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006663 if args =~ "'" |let args= substitute(args,"'\\(.*\\)'",'\1','')|endif
6664 if tgt =~ "'" |let tgt = substitute(tgt ,"'\\(.*\\)'",'\1','')|endif
6665 if args =~ '//'|let args= substitute(args,'//','/','g')|endif
6666 if tgt =~ '//'|let tgt = substitute(tgt ,'//','/','g')|endif
6667" call Decho("args <".args.">",'~'.expand("<slnum>"))
6668" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006669 if isdirectory(s:NetrwFile(args))
6670" call Decho("args<".args."> is a directory",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006671 let copycmd= g:netrw_localcopydircmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006672" call Decho("using copydircmd<".copycmd.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02006673 if !g:netrw_cygwin && has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006674 " window's xcopy doesn't copy a directory to a target properly. Instead, it copies a directory's
6675 " contents to a target. One must append the source directory name to the target to get xcopy to
6676 " do the right thing.
6677 let tgt= tgt.'\'.substitute(a:1,'^.*[\\/]','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006678" call Decho("modified tgt for xcopy",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006679 endif
6680 else
6681 let copycmd= g:netrw_localcopycmd
6682 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006683 if g:netrw_localcopycmd =~ '\s'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006684 let copycmd = substitute(copycmd,'\s.*$','','')
6685 let copycmdargs = substitute(copycmd,'^.\{-}\(\s.*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +02006686 let copycmd = netrw#WinPath(copycmd).copycmdargs
6687 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006688 let copycmd = netrw#WinPath(copycmd)
Bram Moolenaarff034192013-04-24 18:51:19 +02006689 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006690" call Decho("args <".args.">",'~'.expand("<slnum>"))
6691" call Decho("tgt <".tgt.">",'~'.expand("<slnum>"))
6692" call Decho("copycmd<".copycmd.">",'~'.expand("<slnum>"))
6693" call Decho("system(".copycmd." '".args."' '".tgt."')",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006694 call system(copycmd.g:netrw_localcopycmdopt." '".args."' '".tgt."'")
Bram Moolenaar97d62492012-11-15 21:28:22 +01006695 if v:shell_error != 0
Travis Sheltone34d0e32024-07-30 21:08:56 +02006696 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02006697 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 +01006698 else
6699 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localcopycmd<".g:netrw_localcopycmd.">; it doesn't work!",80)
6700 endif
6701" call Dret("s:NetrwMarkFileCopy 0 : failed: system(".g:netrw_localcopycmd." ".args." ".s:ShellEscape(s:netrwmftgt))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006702 return 0
6703 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006704
6705 elseif a:islocal && !s:netrwmftgt_islocal
6706 " Copy marked files, local directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006707" call Decho("copy from local to remote",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006708 NetrwKeepj call s:NetrwUpload(s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006709
6710 elseif !a:islocal && s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006711 " Copy marked files, remote directory to local directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006712" call Decho("copy from remote to local",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006713 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006714
6715 elseif !a:islocal && !s:netrwmftgt_islocal
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006716 " Copy marked files, remote directory to remote directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006717" call Decho("copy from remote to remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006718 let curdir = getcwd()
6719 let tmpdir = s:GetTempfile("")
6720 if tmpdir !~ '/'
6721 let tmpdir= curdir."/".tmpdir
6722 endif
6723 if exists("*mkdir")
6724 call mkdir(tmpdir)
6725 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006726 call s:NetrwExe("sil! !".g:netrw_localmkdir.g:netrw_localmkdiropt.' '.s:ShellEscape(tmpdir,1))
Bram Moolenaar97d62492012-11-15 21:28:22 +01006727 if v:shell_error != 0
6728 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 +01006729" call Dret("s:NetrwMarkFileCopy : failed: sil! !".g:netrw_localmkdir.' '.s:ShellEscape(tmpdir,1) )
Bram Moolenaar97d62492012-11-15 21:28:22 +01006730 return
6731 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006732 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006733 if isdirectory(s:NetrwFile(tmpdir))
Bram Moolenaar85850f32019-07-19 22:05:51 +02006734 if s:NetrwLcd(tmpdir)
6735" call Dret("s:NetrwMarkFileCopy : lcd failure")
6736 return
6737 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006738 NetrwKeepj call netrw#Obtain(a:islocal,s:netrwmarkfilelist_{bufnr('%')},tmpdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006739 let localfiles= map(deepcopy(s:netrwmarkfilelist_{bufnr('%')}),'substitute(v:val,"^.*/","","")')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006740 NetrwKeepj call s:NetrwUpload(localfiles,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006741 if getcwd() == tmpdir
6742 for fname in s:netrwmarkfilelist_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006743 NetrwKeepj call s:NetrwDelete(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006744 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +02006745 if s:NetrwLcd(curdir)
6746" call Dret("s:NetrwMarkFileCopy : lcd failure")
6747 return
6748 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01006749 if delete(tmpdir,"d")
6750 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".tmpdir.">!",103)
Bram Moolenaar97d62492012-11-15 21:28:22 +01006751 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006752 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02006753 if s:NetrwLcd(curdir)
6754" call Dret("s:NetrwMarkFileCopy : lcd failure")
6755 return
6756 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00006757 endif
6758 endif
6759 endif
6760
6761 " -------
6762 " cleanup
6763 " -------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006764" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02006765 " remove markings from local buffer
6766 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006767" call Decho(" g:netrw_fastbrowse =".g:netrw_fastbrowse,'~'.expand("<slnum>"))
6768" call Decho(" s:netrwmftgt =".s:netrwmftgt,'~'.expand("<slnum>"))
6769" call Decho(" s:netrwmftgt_islocal=".s:netrwmftgt_islocal,'~'.expand("<slnum>"))
6770" call Decho(" curdir =".curdir,'~'.expand("<slnum>"))
6771" call Decho(" a:islocal =".a:islocal,'~'.expand("<slnum>"))
6772" call Decho(" curbufnr =".curbufnr,'~'.expand("<slnum>"))
6773 if exists("s:recursive")
6774" call Decho(" s:recursive =".s:recursive,'~'.expand("<slnum>"))
6775 else
6776" call Decho(" s:recursive =n/a",'~'.expand("<slnum>"))
Bram Moolenaare6ae6222013-05-21 21:01:10 +02006777 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006778 " see s:LocalFastBrowser() for g:netrw_fastbrowse interpretation (refreshing done for both slow and medium)
Bram Moolenaar5c736222010-01-06 20:54:52 +01006779 if g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006780 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006781 else
6782 " refresh local and targets for fast browsing
6783 if !exists("s:recursive")
6784 " remove markings from local buffer
6785" call Decho(" remove markings from local buffer",'~'.expand("<slnum>"))
6786 NetrwKeepj call s:NetrwUnmarkList(curbufnr,curdir)
6787 endif
6788
6789 " refresh buffers
6790 if s:netrwmftgt_islocal
6791" call Decho(" refresh s:netrwmftgt=".s:netrwmftgt,'~'.expand("<slnum>"))
6792 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
6793 endif
6794 if a:islocal && s:netrwmftgt != curdir
6795" call Decho(" refresh curdir=".curdir,'~'.expand("<slnum>"))
6796 NetrwKeepj call s:NetrwRefreshDir(a:islocal,curdir)
6797 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01006798 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006799
Bram Moolenaar446cb832008-06-24 21:56:24 +00006800" call Dret("s:NetrwMarkFileCopy 1")
6801 return 1
6802endfun
6803
6804" ---------------------------------------------------------------------
6805" s:NetrwMarkFileDiff: (invoked by md) This function is used to {{{2
6806" invoke vim's diff mode on the marked files.
6807" Either two or three files can be so handled.
6808" Uses the global marked file list.
6809fun! s:NetrwMarkFileDiff(islocal)
6810" call Dfunc("s:NetrwMarkFileDiff(islocal=".a:islocal.") b:netrw_curdir<".b:netrw_curdir.">")
6811 let curbufnr= bufnr("%")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006812
Bram Moolenaarff034192013-04-24 18:51:19 +02006813 " sanity check
6814 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006815 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006816" call Dret("s:NetrwMarkFileDiff")
6817 return
6818 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006819 let curdir= s:NetrwGetCurdir(a:islocal)
6820" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006821
Bram Moolenaara6878372014-03-22 21:02:50 +01006822 if exists("s:netrwmarkfilelist_{".curbufnr."}")
Bram Moolenaar446cb832008-06-24 21:56:24 +00006823 let cnt = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00006824 for fname in s:netrwmarkfilelist
6825 let cnt= cnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00006826 if cnt == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006827" call Decho("diffthis: fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006828 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006829 diffthis
6830 elseif cnt == 2 || cnt == 3
KSR-Yasuda0e958412023-10-06 03:37:15 +09006831 below vsplit
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006832" call Decho("diffthis: ".fname,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006833 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006834 diffthis
6835 else
6836 break
6837 endif
6838 endfor
6839 call s:NetrwUnmarkList(curbufnr,curdir)
6840 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006841
Bram Moolenaar446cb832008-06-24 21:56:24 +00006842" call Dret("s:NetrwMarkFileDiff")
6843endfun
6844
6845" ---------------------------------------------------------------------
6846" s:NetrwMarkFileEdit: (invoked by me) put marked files on arg list and start editing them {{{2
6847" Uses global markfilelist
6848fun! s:NetrwMarkFileEdit(islocal)
6849" call Dfunc("s:NetrwMarkFileEdit(islocal=".a:islocal.")")
6850
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006851 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006852 let curbufnr = bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02006853
6854 " sanity check
6855 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006856 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02006857" call Dret("s:NetrwMarkFileEdit")
6858 return
6859 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006860" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006861
Bram Moolenaar446cb832008-06-24 21:56:24 +00006862 if exists("s:netrwmarkfilelist_{curbufnr}")
6863 call s:SetRexDir(a:islocal,curdir)
Bram Moolenaare37d50a2008-08-06 17:06:04 +00006864 let flist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00006865 " unmark markedfile list
6866" call s:NetrwUnmarkList(curbufnr,curdir)
6867 call s:NetrwUnmarkAll()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006868" call Decho("exe sil args ".flist,'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +02006869 exe "sil args ".flist
Bram Moolenaar446cb832008-06-24 21:56:24 +00006870 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006871 echo "(use :bn, :bp to navigate files; :Rex to return)"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006872
Bram Moolenaar446cb832008-06-24 21:56:24 +00006873" call Dret("s:NetrwMarkFileEdit")
6874endfun
6875
6876" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006877" s:NetrwMarkFileQFEL: convert a quickfix-error or location list into a marked file list {{{2
Bram Moolenaarff034192013-04-24 18:51:19 +02006878fun! s:NetrwMarkFileQFEL(islocal,qfel)
6879" call Dfunc("s:NetrwMarkFileQFEL(islocal=".a:islocal.",qfel)")
6880 call s:NetrwUnmarkAll()
6881 let curbufnr= bufnr("%")
6882
6883 if !empty(a:qfel)
6884 for entry in a:qfel
6885 let bufnmbr= entry["bufnr"]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006886" call Decho("bufname(".bufnmbr.")<".bufname(bufnmbr)."> line#".entry["lnum"]." text=".entry["text"],'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006887 if !exists("s:netrwmarkfilelist_{curbufnr}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006888" call Decho("case: no marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006889 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6890 elseif index(s:netrwmarkfilelist_{curbufnr},bufname(bufnmbr)) == -1
6891 " s:NetrwMarkFile will remove duplicate entries from the marked file list.
6892 " So, this test lets two or more hits on the same pattern to be ignored.
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006893" call Decho("case: ".bufname(bufnmbr)." not currently in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006894 call s:NetrwMarkFile(a:islocal,bufname(bufnmbr))
6895 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006896" call Decho("case: ".bufname(bufnmbr)." already in marked file list",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02006897 endif
6898 endfor
6899 echo "(use me to edit marked files)"
6900 else
6901 call netrw#ErrorMsg(s:WARNING,"can't convert quickfix error list; its empty!",92)
6902 endif
6903
6904" call Dret("s:NetrwMarkFileQFEL")
6905endfun
6906
6907" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006908" s:NetrwMarkFileExe: (invoked by mx and mX) execute arbitrary system command on marked files {{{2
6909" mx enbloc=0: Uses the local marked-file list, applies command to each file individually
6910" mX enbloc=1: Uses the global marked-file list, applies command to entire list
6911fun! s:NetrwMarkFileExe(islocal,enbloc)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006912 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006913 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006914 let curbufnr = bufnr("%")
6915
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006916 if a:enbloc == 0
6917 " individually apply command to files, one at a time
6918 " sanity check
6919 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
6920 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006921 return
6922 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02006923
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006924 if exists("s:netrwmarkfilelist_{curbufnr}")
6925 " get the command
6926 call inputsave()
6927 let cmd= input("Enter command: ","","file")
6928 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006929 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006930 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00006931 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006932
6933 " apply command to marked files, individually. Substitute: filename -> %
6934 " If no %, then append a space and the filename to the command
6935 for fname in s:netrwmarkfilelist_{curbufnr}
6936 if a:islocal
6937 if g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09006938 let fname= s:ShellEscape(netrw#WinPath(s:ComposePath(curdir,fname)))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006939 endif
6940 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006941 let fname= s:ShellEscape(netrw#WinPath(b:netrw_curdir.fname))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006942 endif
6943 if cmd =~ '%'
6944 let xcmd= substitute(cmd,'%',fname,'g')
6945 else
6946 let xcmd= cmd.' '.fname
6947 endif
6948 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006949 let ret= system(xcmd)
6950 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006951 let ret= s:RemoteSystem(xcmd)
6952 endif
6953 if v:shell_error < 0
6954 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6955 break
6956 else
yasudac75dad02024-08-22 21:06:32 +02006957 if ret !=# ''
6958 echo "\n"
6959 " skip trailing new line
6960 echo ret[0:-2]
6961 else
6962 echo ret
6963 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006964 endif
6965 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00006966
6967 " unmark marked file list
6968 call s:NetrwUnmarkList(curbufnr,curdir)
6969
6970 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01006971 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01006972 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006973 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006974 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00006975 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006976
6977 else " apply command to global list of files, en bloc
6978
6979 call inputsave()
6980 let cmd= input("Enter command: ","","file")
6981 call inputrestore()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006982 if cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006983 return
6984 endif
6985 if cmd =~ '%'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006986 let cmd= substitute(cmd,'%',join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' '),'g')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01006988 let cmd= cmd.' '.join(map(s:netrwmarkfilelist,'s:ShellEscape(v:val)'),' ')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01006989 endif
6990 if a:islocal
6991 call system(cmd)
6992 if v:shell_error < 0
6993 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"command<".xcmd."> failed, aborting",54)
6994 endif
6995 else
6996 let ret= s:RemoteSystem(cmd)
6997 endif
6998 call s:NetrwUnmarkAll()
6999
7000 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007001 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007002 NetrwKeepj call winrestview(svpos)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007003
7004 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007005endfun
7006
7007" ---------------------------------------------------------------------
7008" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7009" as the marked file(s) (toggles suffix presence)
7010" Uses the local marked file list.
7011fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007012 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007013 let curbufnr = bufnr("%")
7014
7015 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7016 if exists("s:netrwmarkfilelist_{curbufnr}")
7017
7018 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007019 " construct suffix pattern
7020 if fname =~ '\.'
7021 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7022 else
7023 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7024 endif
7025 " determine if its in the hiding list or not
7026 let inhidelist= 0
7027 if g:netrw_list_hide != ""
7028 let itemnum = 0
7029 let hidelist= split(g:netrw_list_hide,',')
7030 for hidepat in hidelist
7031 if sfxpat == hidepat
7032 let inhidelist= 1
7033 break
7034 endif
7035 let itemnum= itemnum + 1
7036 endfor
7037 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007038 if inhidelist
7039 " remove sfxpat from list
7040 call remove(hidelist,itemnum)
7041 let g:netrw_list_hide= join(hidelist,",")
7042 elseif g:netrw_list_hide != ""
7043 " append sfxpat to non-empty list
7044 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7045 else
7046 " set hiding list to sfxpat
7047 let g:netrw_list_hide= sfxpat
7048 endif
7049 endfor
7050
7051 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007052 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007053 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007054 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007055 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007056 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007057endfun
7058
7059" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007060" s:NetrwMarkFileVimCmd: (invoked by mv) execute arbitrary vim command on marked files, one at a time {{{2
Bram Moolenaar15146672011-10-20 22:22:38 +02007061" Uses the local marked-file list.
7062fun! s:NetrwMarkFileVimCmd(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007063 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007064 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar15146672011-10-20 22:22:38 +02007065 let curbufnr = bufnr("%")
7066
Bram Moolenaarff034192013-04-24 18:51:19 +02007067 " sanity check
7068 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007069 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007070 return
7071 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007072
Bram Moolenaar15146672011-10-20 22:22:38 +02007073 if exists("s:netrwmarkfilelist_{curbufnr}")
7074 " get the command
7075 call inputsave()
7076 let cmd= input("Enter vim command: ","","file")
7077 call inputrestore()
Bram Moolenaar15146672011-10-20 22:22:38 +02007078 if cmd == ""
Bram Moolenaar15146672011-10-20 22:22:38 +02007079 return
7080 endif
7081
7082 " apply command to marked files. Substitute: filename -> %
7083 " If no %, then append a space and the filename to the command
7084 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007085 if a:islocal
7086 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007087 exe "sil! NetrwKeepj keepalt e ".fnameescape(fname)
Bram Moolenaar15146672011-10-20 22:22:38 +02007088 exe cmd
7089 exe "sil! keepalt wq!"
7090 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007091 echo "sorry, \"mv\" not supported yet for remote files"
Bram Moolenaar15146672011-10-20 22:22:38 +02007092 endif
7093 endfor
7094
7095 " unmark marked file list
7096 call s:NetrwUnmarkList(curbufnr,curdir)
7097
7098 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007099 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007100 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007101 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007102 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007103 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007104endfun
7105
7106" ---------------------------------------------------------------------
7107" s:NetrwMarkHideSfx: (invoked by mh) (un)hide files having same suffix
7108" as the marked file(s) (toggles suffix presence)
7109" Uses the local marked file list.
7110fun! s:NetrwMarkHideSfx(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007111 let svpos = winsaveview()
Bram Moolenaar15146672011-10-20 22:22:38 +02007112 let curbufnr = bufnr("%")
7113
7114 " s:netrwmarkfilelist_{curbufnr}: the List of marked files
7115 if exists("s:netrwmarkfilelist_{curbufnr}")
7116
7117 for fname in s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar15146672011-10-20 22:22:38 +02007118 " construct suffix pattern
7119 if fname =~ '\.'
7120 let sfxpat= "^.*".substitute(fname,'^.*\(\.[^. ]\+\)$','\1','')
7121 else
7122 let sfxpat= '^\%(\%(\.\)\@!.\)*$'
7123 endif
7124 " determine if its in the hiding list or not
7125 let inhidelist= 0
7126 if g:netrw_list_hide != ""
7127 let itemnum = 0
7128 let hidelist= split(g:netrw_list_hide,',')
7129 for hidepat in hidelist
7130 if sfxpat == hidepat
7131 let inhidelist= 1
7132 break
7133 endif
7134 let itemnum= itemnum + 1
7135 endfor
7136 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007137 if inhidelist
7138 " remove sfxpat from list
7139 call remove(hidelist,itemnum)
7140 let g:netrw_list_hide= join(hidelist,",")
7141 elseif g:netrw_list_hide != ""
7142 " append sfxpat to non-empty list
7143 let g:netrw_list_hide= g:netrw_list_hide.",".sfxpat
7144 else
7145 " set hiding list to sfxpat
7146 let g:netrw_list_hide= sfxpat
7147 endif
7148 endfor
7149
7150 " refresh the listing
Tom Benham64a536d2024-11-07 21:15:03 +01007151 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007152 NetrwKeepj call winrestview(svpos)
Bram Moolenaar15146672011-10-20 22:22:38 +02007153 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007154 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"no files marked!",59)
Bram Moolenaar15146672011-10-20 22:22:38 +02007155 endif
Bram Moolenaar15146672011-10-20 22:22:38 +02007156endfun
7157
7158" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007159" s:NetrwMarkFileGrep: (invoked by mg) This function applies vimgrep to marked files {{{2
7160" Uses the global markfilelist
7161fun! s:NetrwMarkFileGrep(islocal)
7162" call Dfunc("s:NetrwMarkFileGrep(islocal=".a:islocal.")")
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007163 let svpos = winsaveview()
7164" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007165 let curbufnr = bufnr("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007166 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007167
7168 if exists("s:netrwmarkfilelist")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007169" call Decho("using s:netrwmarkfilelist".string(s:netrwmarkfilelist).">",'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00007170 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "fnameescape(v:val)"))
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007171" call Decho("keeping copy of s:netrwmarkfilelist in function-local variable,'~'.expand("<slnum>"))"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007172 call s:NetrwUnmarkAll()
Bram Moolenaarff034192013-04-24 18:51:19 +02007173 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007174" call Decho('no marked files, using "*"','~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007175 let netrwmarkfilelist= "*"
7176 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007177
Bram Moolenaarff034192013-04-24 18:51:19 +02007178 " ask user for pattern
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01007179" call Decho("ask user for search pattern",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007180 call inputsave()
7181 let pat= input("Enter pattern: ","")
7182 call inputrestore()
7183 let patbang = ""
7184 if pat =~ '^!'
7185 let patbang = "!"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007186 let pat = strpart(pat,2)
Bram Moolenaarff034192013-04-24 18:51:19 +02007187 endif
7188 if pat =~ '^\i'
7189 let pat = escape(pat,'/')
7190 let pat = '/'.pat.'/'
7191 else
7192 let nonisi = pat[0]
7193 endif
7194
7195 " use vimgrep for both local and remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007196" call Decho("exe vimgrep".patbang." ".pat." ".netrwmarkfilelist,'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007197 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007198 exe "NetrwKeepj noautocmd vimgrep".patbang." ".pat." ".netrwmarkfilelist
Bram Moolenaarff034192013-04-24 18:51:19 +02007199 catch /^Vim\%((\a\+)\)\=:E480/
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007200 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"no match with pattern<".pat.">",76)
Bram Moolenaarff034192013-04-24 18:51:19 +02007201" call Dret("s:NetrwMarkFileGrep : unable to find pattern<".pat.">")
7202 return
7203 endtry
7204 echo "(use :cn, :cp to navigate, :Rex to return)"
7205
7206 2match none
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007207" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
7208 NetrwKeepj call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007209
7210 if exists("nonisi")
7211 " original, user-supplied pattern did not begin with a character from isident
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007212" call Decho("looking for trailing nonisi<".nonisi."> followed by a j, gj, or jg",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007213 if pat =~# nonisi.'j$\|'.nonisi.'gj$\|'.nonisi.'jg$'
Bram Moolenaarff034192013-04-24 18:51:19 +02007214 call s:NetrwMarkFileQFEL(a:islocal,getqflist())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007215 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007216 endif
7217
7218" call Dret("s:NetrwMarkFileGrep")
7219endfun
7220
7221" ---------------------------------------------------------------------
7222" s:NetrwMarkFileMove: (invoked by mm) execute arbitrary command on marked files, one at a time {{{2
7223" uses the global marked file list
7224" s:netrwmfloc= 0: target directory is remote
7225" = 1: target directory is local
7226fun! s:NetrwMarkFileMove(islocal)
7227" call Dfunc("s:NetrwMarkFileMove(islocal=".a:islocal.")")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007228 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007229 let curbufnr = bufnr("%")
7230
7231 " sanity check
Bram Moolenaarff034192013-04-24 18:51:19 +02007232 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007233 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007234" call Dret("s:NetrwMarkFileMove")
7235 return
7236 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007237" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007238
Bram Moolenaar446cb832008-06-24 21:56:24 +00007239 if !exists("s:netrwmftgt")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007240 NetrwKeepj call netrw#ErrorMsg(2,"your marked file target is empty! (:help netrw-mt)",67)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007241" call Dret("s:NetrwMarkFileCopy 0")
7242 return 0
7243 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007244" call Decho("sanity chk passed: s:netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007245
7246 if a:islocal && s:netrwmftgt_islocal
7247 " move: local -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007248" call Decho("move from local to local",'~'.expand("<slnum>"))
7249" call Decho("local to local move",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007250 if !executable(g:netrw_localmovecmd)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007251 call netrw#ErrorMsg(s:ERROR,"g:netrw_localmovecmd<".g:netrw_localmovecmd."> not executable on your system, aborting",90)
7252" call Dfunc("s:NetrwMarkFileMove : g:netrw_localmovecmd<".g:netrw_localmovecmd."> n/a!")
7253 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007254 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007255 let tgt = s:ShellEscape(s:netrwmftgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007256" call Decho("tgt<".tgt.">",'~'.expand("<slnum>"))
Nir Lichtman1e34b952024-05-08 19:19:34 +02007257 if !g:netrw_cygwin && has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +02007258 let tgt= substitute(tgt, '/','\\','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007259" call Decho("windows exception: tgt<".tgt.">",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007260 if g:netrw_localmovecmd =~ '\s'
7261 let movecmd = substitute(g:netrw_localmovecmd,'\s.*$','','')
7262 let movecmdargs = substitute(g:netrw_localmovecmd,'^.\{-}\(\s.*\)$','\1','')
7263 let movecmd = netrw#WinPath(movecmd).movecmdargs
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007264" call Decho("windows exception: movecmd<".movecmd."> (#1: had a space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007265 else
MiguelBarro6e5a6c92024-01-17 21:35:36 +01007266 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007267" call Decho("windows exception: movecmd<".movecmd."> (#2: no space)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007268 endif
7269 else
7270 let movecmd = netrw#WinPath(g:netrw_localmovecmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007271" call Decho("movecmd<".movecmd."> (#3 linux or cygwin)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007272 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007273 for fname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar71badf92023-04-22 22:40:14 +01007274 if g:netrw_keepdir
7275 " Jul 19, 2022: fixing file move when g:netrw_keepdir is 1
7276 let fname= b:netrw_curdir."/".fname
7277 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +02007278 if !g:netrw_cygwin && has("win32")
Bram Moolenaarff034192013-04-24 18:51:19 +02007279 let fname= substitute(fname,'/','\\','g')
7280 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007281" call Decho("system(".movecmd." ".s:ShellEscape(fname)." ".tgt.")",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007282 let ret= system(movecmd.g:netrw_localmovecmdopt." ".s:ShellEscape(fname)." ".tgt)
Bram Moolenaarff034192013-04-24 18:51:19 +02007283 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007284 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
Bram Moolenaar85850f32019-07-19 22:05:51 +02007285 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 +01007286 else
7287 call netrw#ErrorMsg(s:ERROR,"tried using g:netrw_localmovecmd<".g:netrw_localmovecmd.">; it doesn't work!",54)
7288 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007289 break
7290 endif
7291 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007292
7293 elseif a:islocal && !s:netrwmftgt_islocal
7294 " move: local -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007295" call Decho("move from local to remote",'~'.expand("<slnum>"))
7296" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007297 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007298 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007299" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007300 for fname in mflist
7301 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7302 let ok = s:NetrwLocalRmFile(b:netrw_curdir,barefname,1)
7303 endfor
7304 unlet mflist
7305
7306 elseif !a:islocal && s:netrwmftgt_islocal
7307 " move: remote -> local
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007308" call Decho("move from remote to local",'~'.expand("<slnum>"))
7309" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007310 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007311 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007312" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007313 for fname in mflist
7314 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7315 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7316 endfor
7317 unlet mflist
7318
7319 elseif !a:islocal && !s:netrwmftgt_islocal
7320 " move: remote -> remote
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007321" call Decho("move from remote to remote",'~'.expand("<slnum>"))
7322" call Decho("copy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007323 let mflist= s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007324 NetrwKeepj call s:NetrwMarkFileCopy(a:islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007325" call Decho("remove",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007326 for fname in mflist
7327 let barefname = substitute(fname,'^\(.*/\)\(.\{-}\)$','\2','')
7328 let ok = s:NetrwRemoteRmFile(b:netrw_curdir,barefname,1)
7329 endfor
7330 unlet mflist
7331 endif
7332
7333 " -------
7334 " cleanup
7335 " -------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007336" call Decho("cleanup",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007337
7338 " remove markings from local buffer
7339 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
7340
7341 " refresh buffers
7342 if !s:netrwmftgt_islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007343" call Decho("refresh netrwmftgt<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007344 NetrwKeepj call s:NetrwRefreshDir(s:netrwmftgt_islocal,s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007345 endif
7346 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007347" call Decho("refresh b:netrw_curdir<".b:netrw_curdir.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007348 NetrwKeepj call s:NetrwRefreshDir(a:islocal,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007349 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007350 if g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007351" call Decho("since g:netrw_fastbrowse=".g:netrw_fastbrowse.", perform shell cmd refresh",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007352 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar5c736222010-01-06 20:54:52 +01007353 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007354
Bram Moolenaar446cb832008-06-24 21:56:24 +00007355" call Dret("s:NetrwMarkFileMove")
7356endfun
7357
7358" ---------------------------------------------------------------------
7359" s:NetrwMarkFilePrint: (invoked by mp) This function prints marked files {{{2
7360" using the hardcopy command. Local marked-file list only.
7361fun! s:NetrwMarkFilePrint(islocal)
7362" call Dfunc("s:NetrwMarkFilePrint(islocal=".a:islocal.")")
7363 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007364
7365 " sanity check
7366 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007367 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007368" call Dret("s:NetrwMarkFilePrint")
7369 return
7370 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007371" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7372 let curdir= s:NetrwGetCurdir(a:islocal)
7373
Bram Moolenaar446cb832008-06-24 21:56:24 +00007374 if exists("s:netrwmarkfilelist_{curbufnr}")
7375 let netrwmarkfilelist = s:netrwmarkfilelist_{curbufnr}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007376 call s:NetrwUnmarkList(curbufnr,curdir)
7377 for fname in netrwmarkfilelist
7378 if a:islocal
7379 if g:netrw_keepdir
7380 let fname= s:ComposePath(curdir,fname)
7381 endif
7382 else
7383 let fname= curdir.fname
7384 endif
7385 1split
7386 " the autocmds will handle both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007387" call Decho("exe sil e ".escape(fname,' '),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007388 exe "sil NetrwKeepj e ".fnameescape(fname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007389" call Decho("hardcopy",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007390 hardcopy
7391 q
7392 endfor
7393 2match none
7394 endif
7395" call Dret("s:NetrwMarkFilePrint")
7396endfun
7397
7398" ---------------------------------------------------------------------
7399" s:NetrwMarkFileRegexp: (invoked by mr) This function is used to mark {{{2
7400" files when given a regexp (for which a prompt is
Bram Moolenaarff034192013-04-24 18:51:19 +02007401" issued) (matches to name of files).
Bram Moolenaar446cb832008-06-24 21:56:24 +00007402fun! s:NetrwMarkFileRegexp(islocal)
7403" call Dfunc("s:NetrwMarkFileRegexp(islocal=".a:islocal.")")
7404
7405 " get the regular expression
7406 call inputsave()
7407 let regexp= input("Enter regexp: ","","file")
7408 call inputrestore()
7409
7410 if a:islocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007411 let curdir= s:NetrwGetCurdir(a:islocal)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007412" call Decho("curdir<".fnameescape(curdir).">")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007413 " get the matching list of files using local glob()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007414" call Decho("handle local regexp",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02007415 let dirname = escape(b:netrw_curdir,g:netrw_glob_escape)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007416 if v:version > 704 || (v:version == 704 && has("patch656"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02007417 let filelist= glob(s:ComposePath(dirname,regexp),0,1,1)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007418 else
7419 let files = glob(s:ComposePath(dirname,regexp),0,0)
Bram Moolenaar85850f32019-07-19 22:05:51 +02007420 let filelist= split(files,"\n")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007421 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007422" call Decho("files<".string(filelist).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007423
7424 " mark the list of files
Bram Moolenaar5c736222010-01-06 20:54:52 +01007425 for fname in filelist
Bram Moolenaar85850f32019-07-19 22:05:51 +02007426 if fname =~ '^'.fnameescape(curdir)
7427" call Decho("fname<".substitute(fname,'^'.fnameescape(curdir).'/','','').">",'~'.expand("<slnum>"))
7428 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^'.fnameescape(curdir).'/','',''))
7429 else
7430" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
7431 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(fname,'^.*/','',''))
7432 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01007433 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00007434
7435 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007436" call Decho("handle remote regexp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007437
7438 " convert displayed listing into a filelist
7439 let eikeep = &ei
7440 let areg = @a
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007441 sil NetrwKeepj %y a
Bram Moolenaara6878372014-03-22 21:02:50 +01007442 setl ei=all ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007443" call Decho("setl ei=all ma",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007444 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007445 NetrwKeepj call s:NetrwEnew()
Bram Moolenaar85850f32019-07-19 22:05:51 +02007446 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007447 sil NetrwKeepj norm! "ap
7448 NetrwKeepj 2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007449 let bannercnt= search('^" =====','W')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007450 exe "sil NetrwKeepj 1,".bannercnt."d"
Bram Moolenaara6878372014-03-22 21:02:50 +01007451 setl bt=nofile
Bram Moolenaar446cb832008-06-24 21:56:24 +00007452 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007453 sil NetrwKeepj %s/\s\{2,}\S.*$//e
Bram Moolenaar5c736222010-01-06 20:54:52 +01007454 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007455 elseif g:netrw_liststyle == s:WIDELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007456 sil NetrwKeepj %s/\s\{2,}/\r/ge
Bram Moolenaar5c736222010-01-06 20:54:52 +01007457 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007458 elseif g:netrw_liststyle == s:TREELIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007459 exe 'sil NetrwKeepj %s/^'.s:treedepthstring.' //e'
7460 sil! NetrwKeepj g/^ .*$/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01007461 call histdel("/",-1)
7462 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007463 endif
7464 " convert regexp into the more usual glob-style format
7465 let regexp= substitute(regexp,'\*','.*','g')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007466" call Decho("regexp<".regexp.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007467 exe "sil! NetrwKeepj v/".escape(regexp,'/')."/d"
Bram Moolenaar5c736222010-01-06 20:54:52 +01007468 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007469 let filelist= getline(1,line("$"))
7470 q!
7471 for filename in filelist
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007472 NetrwKeepj call s:NetrwMarkFile(a:islocal,substitute(filename,'^.*/','',''))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007473 endfor
7474 unlet filelist
7475 let @a = areg
7476 let &ei = eikeep
7477 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007478 echo " (use me to edit marked files)"
Bram Moolenaar446cb832008-06-24 21:56:24 +00007479
7480" call Dret("s:NetrwMarkFileRegexp")
7481endfun
7482
7483" ---------------------------------------------------------------------
7484" s:NetrwMarkFileSource: (invoked by ms) This function sources marked files {{{2
7485" Uses the local marked file list.
7486fun! s:NetrwMarkFileSource(islocal)
7487" call Dfunc("s:NetrwMarkFileSource(islocal=".a:islocal.")")
7488 let curbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02007489
7490 " sanity check
7491 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007492 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007493" call Dret("s:NetrwMarkFileSource")
7494 return
7495 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007496" call Decho("sanity chk passed: s:netrwmarkfilelist_".curbufnr."<".string(s:netrwmarkfilelist_{curbufnr}),'~'.expand("<slnum>"))
7497 let curdir= s:NetrwGetCurdir(a:islocal)
7498
Bram Moolenaar446cb832008-06-24 21:56:24 +00007499 if exists("s:netrwmarkfilelist_{curbufnr}")
7500 let netrwmarkfilelist = s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00007501 call s:NetrwUnmarkList(curbufnr,curdir)
7502 for fname in netrwmarkfilelist
7503 if a:islocal
7504 if g:netrw_keepdir
7505 let fname= s:ComposePath(curdir,fname)
7506 endif
7507 else
7508 let fname= curdir.fname
7509 endif
7510 " the autocmds will handle sourcing both local and remote files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007511" call Decho("exe so ".fnameescape(fname),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007512 exe "so ".fnameescape(fname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007513 endfor
7514 2match none
7515 endif
7516" call Dret("s:NetrwMarkFileSource")
7517endfun
7518
7519" ---------------------------------------------------------------------
7520" s:NetrwMarkFileTag: (invoked by mT) This function applies g:netrw_ctags to marked files {{{2
7521" Uses the global markfilelist
7522fun! s:NetrwMarkFileTag(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007523 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007524 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007525 let curbufnr = bufnr("%")
7526
Bram Moolenaarff034192013-04-24 18:51:19 +02007527 " sanity check
7528 if !exists("s:netrwmarkfilelist_{curbufnr}") || empty(s:netrwmarkfilelist_{curbufnr})
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007529 NetrwKeepj call netrw#ErrorMsg(2,"there are no marked files in this window (:help netrw-mf)",66)
Bram Moolenaarff034192013-04-24 18:51:19 +02007530 return
7531 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02007532
Bram Moolenaar446cb832008-06-24 21:56:24 +00007533 if exists("s:netrwmarkfilelist")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007534 let netrwmarkfilelist= join(map(deepcopy(s:netrwmarkfilelist), "s:ShellEscape(v:val,".!a:islocal.")"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007535 call s:NetrwUnmarkAll()
7536
7537 if a:islocal
Bram Moolenaar85850f32019-07-19 22:05:51 +02007538
Bram Moolenaar85850f32019-07-19 22:05:51 +02007539 call system(g:netrw_ctags." ".netrwmarkfilelist)
7540 if v:shell_error
Bram Moolenaar446cb832008-06-24 21:56:24 +00007541 call netrw#ErrorMsg(s:ERROR,"g:netrw_ctags<".g:netrw_ctags."> is not executable!",51)
7542 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02007543
Bram Moolenaar446cb832008-06-24 21:56:24 +00007544 else
Bram Moolenaarc236c162008-07-13 17:41:49 +00007545 let cmd = s:RemoteSystem(g:netrw_ctags." ".netrwmarkfilelist)
Bram Moolenaara6878372014-03-22 21:02:50 +01007546 call netrw#Obtain(a:islocal,"tags")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007547 let curdir= b:netrw_curdir
7548 1split
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007549 NetrwKeepj e tags
Bram Moolenaar446cb832008-06-24 21:56:24 +00007550 let path= substitute(curdir,'^\(.*\)/[^/]*$','\1/','')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007551 exe 'NetrwKeepj %s/\t\(\S\+\)\t/\t'.escape(path,"/\n\r\\").'\1\t/e'
Bram Moolenaar5c736222010-01-06 20:54:52 +01007552 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007553 wq!
7554 endif
7555 2match none
Tom Benham64a536d2024-11-07 21:15:03 +01007556 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007557 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007558 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007559endfun
7560
7561" ---------------------------------------------------------------------
7562" s:NetrwMarkFileTgt: (invoked by mt) This function sets up a marked file target {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007563" Sets up two variables,
Bram Moolenaarff034192013-04-24 18:51:19 +02007564" s:netrwmftgt : holds the target directory
Bram Moolenaar446cb832008-06-24 21:56:24 +00007565" s:netrwmftgt_islocal : 0=target directory is remote
Bram Moolenaarff034192013-04-24 18:51:19 +02007566" 1=target directory is local
Bram Moolenaar446cb832008-06-24 21:56:24 +00007567fun! s:NetrwMarkFileTgt(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007568 let svpos = winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007569 let curdir = s:NetrwGetCurdir(a:islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007570 let hadtgt = exists("s:netrwmftgt")
7571 if !exists("w:netrw_bannercnt")
7572 let w:netrw_bannercnt= b:netrw_bannercnt
7573 endif
7574
7575 " set up target
7576 if line(".") < w:netrw_bannercnt
Bram Moolenaarff034192013-04-24 18:51:19 +02007577 " if cursor in banner region, use b:netrw_curdir for the target unless its already the target
7578 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal") && s:netrwmftgt == b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007579 unlet s:netrwmftgt s:netrwmftgt_islocal
7580 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007581 call s:LocalBrowseRefresh()
Bram Moolenaarff034192013-04-24 18:51:19 +02007582 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007583 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007584 call winrestview(svpos)
Bram Moolenaarff034192013-04-24 18:51:19 +02007585 return
7586 else
7587 let s:netrwmftgt= b:netrw_curdir
Bram Moolenaarff034192013-04-24 18:51:19 +02007588 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007589
7590 else
7591 " get word under cursor.
7592 " * If directory, use it for the target.
7593 " * If file, use b:netrw_curdir for the target
7594 let curword= s:NetrwGetWord()
7595 let tgtdir = s:ComposePath(curdir,curword)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007596 if a:islocal && isdirectory(s:NetrwFile(tgtdir))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007597 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007598 elseif !a:islocal && tgtdir =~ '/$'
7599 let s:netrwmftgt = tgtdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007600 else
7601 let s:netrwmftgt = curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00007602 endif
7603 endif
7604 if a:islocal
7605 " simplify the target (eg. /abc/def/../ghi -> /abc/ghi)
7606 let s:netrwmftgt= simplify(s:netrwmftgt)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007607 endif
7608 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007609 let s:netrwmftgt= substitute(system("cygpath ".s:ShellEscape(s:netrwmftgt)),'\n$','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00007610 let s:netrwmftgt= substitute(s:netrwmftgt,'\n$','','')
7611 endif
7612 let s:netrwmftgt_islocal= a:islocal
7613
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007614 " need to do refresh so that the banner will be updated
7615 " s:LocalBrowseRefresh handles all local-browsing buffers when not fast browsing
Bram Moolenaar5c736222010-01-06 20:54:52 +01007616 if g:netrw_fastbrowse <= 1
Bram Moolenaara6878372014-03-22 21:02:50 +01007617 call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007618 endif
Tom Benham64a536d2024-11-07 21:15:03 +01007619" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007620 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Tom Benham64a536d2024-11-07 21:15:03 +01007621 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,w:netrw_treetop,0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007622 else
Tom Benham64a536d2024-11-07 21:15:03 +01007623 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007624 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007625 call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007626 if !hadtgt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007627 sil! NetrwKeepj norm! j
Bram Moolenaar446cb832008-06-24 21:56:24 +00007628 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007629endfun
7630
7631" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007632" s:NetrwGetCurdir: gets current directory and sets up b:netrw_curdir if necessary {{{2
7633fun! s:NetrwGetCurdir(islocal)
7634" call Dfunc("s:NetrwGetCurdir(islocal=".a:islocal.")")
7635
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007636 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007637 let b:netrw_curdir = s:NetrwTreePath(w:netrw_treetop)
7638" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used s:NetrwTreeDir)",'~'.expand("<slnum>"))
7639 elseif !exists("b:netrw_curdir")
7640 let b:netrw_curdir= getcwd()
7641" call Decho("set b:netrw_curdir<".b:netrw_curdir."> (used getcwd)",'~'.expand("<slnum>"))
7642 endif
7643
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007644" 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 +01007645 if b:netrw_curdir !~ '\<\a\{3,}://'
7646 let curdir= b:netrw_curdir
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007647" call Decho("g:netrw_keepdir=".g:netrw_keepdir,'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007648 if g:netrw_keepdir == 0
7649 call s:NetrwLcd(curdir)
7650 endif
7651 endif
7652
7653" call Dret("s:NetrwGetCurdir <".curdir.">")
7654 return b:netrw_curdir
7655endfun
7656
7657" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +00007658" s:NetrwOpenFile: query user for a filename and open it {{{2
7659fun! s:NetrwOpenFile(islocal)
7660" call Dfunc("s:NetrwOpenFile(islocal=".a:islocal.")")
Bram Moolenaar97d62492012-11-15 21:28:22 +01007661 let ykeep= @@
Bram Moolenaarc236c162008-07-13 17:41:49 +00007662 call inputsave()
7663 let fname= input("Enter filename: ")
7664 call inputrestore()
Bram Moolenaar89a9c152021-08-29 21:55:35 +02007665" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
7666
7667 " determine if Lexplore is in use
7668 if exists("t:netrw_lexbufnr")
7669 " check if t:netrw_lexbufnr refers to a netrw window
7670" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
7671 let lexwinnr = bufwinnr(t:netrw_lexbufnr)
7672 if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
7673" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
7674 exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
7675 exe "NetrwKeepj e ".fnameescape(fname)
7676 let @@= ykeep
7677" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
7678 endif
7679 endif
7680
7681 " Does the filename contain a path?
Bram Moolenaarc236c162008-07-13 17:41:49 +00007682 if fname !~ '[/\\]'
7683 if exists("b:netrw_curdir")
7684 if exists("g:netrw_quiet")
7685 let netrw_quiet_keep = g:netrw_quiet
7686 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007687 let g:netrw_quiet = 1
7688 " save position for benefit of Rexplore
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007689 let s:rexposn_{bufnr("%")}= winsaveview()
7690" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00007691 if b:netrw_curdir =~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007692 exe "NetrwKeepj e ".fnameescape(b:netrw_curdir.fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007693 else
7694 exe "e ".fnameescape(b:netrw_curdir."/".fname)
7695 endif
7696 if exists("netrw_quiet_keep")
7697 let g:netrw_quiet= netrw_quiet_keep
7698 else
7699 unlet g:netrw_quiet
7700 endif
7701 endif
7702 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01007703 exe "NetrwKeepj e ".fnameescape(fname)
Bram Moolenaarc236c162008-07-13 17:41:49 +00007704 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007705 let @@= ykeep
Bram Moolenaarc236c162008-07-13 17:41:49 +00007706" call Dret("s:NetrwOpenFile")
7707endfun
7708
7709" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007710" netrw#Shrink: shrinks/expands a netrw or Lexplorer window {{{2
7711" For the mapping to this function be made via
7712" netrwPlugin, you'll need to have had
7713" g:netrw_usetab set to non-zero.
7714fun! netrw#Shrink()
7715" call Dfunc("netrw#Shrink() ft<".&ft."> winwidth=".winwidth(0)." lexbuf#".((exists("t:netrw_lexbufnr"))? t:netrw_lexbufnr : 'n/a'))
7716 let curwin = winnr()
7717 let wiwkeep = &wiw
7718 set wiw=1
7719
7720 if &ft == "netrw"
7721 if winwidth(0) > g:netrw_wiw
7722 let t:netrw_winwidth= winwidth(0)
7723 exe "vert resize ".g:netrw_wiw
7724 wincmd l
7725 if winnr() == curwin
7726 wincmd h
7727 endif
7728" call Decho("vert resize 0",'~'.expand("<slnum>"))
7729 else
7730 exe "vert resize ".t:netrw_winwidth
7731" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
7732 endif
7733
7734 elseif exists("t:netrw_lexbufnr")
7735 exe bufwinnr(t:netrw_lexbufnr)."wincmd w"
7736 if winwidth(bufwinnr(t:netrw_lexbufnr)) > g:netrw_wiw
7737 let t:netrw_winwidth= winwidth(0)
7738 exe "vert resize ".g:netrw_wiw
7739 wincmd l
7740 if winnr() == curwin
7741 wincmd h
7742 endif
7743" call Decho("vert resize 0",'~'.expand("<slnum>"))
7744 elseif winwidth(bufwinnr(t:netrw_lexbufnr)) >= 0
7745 exe "vert resize ".t:netrw_winwidth
7746" call Decho("vert resize ".t:netrw_winwidth,'~'.expand("<slnum>"))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01007747 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007748 call netrw#Lexplore(0,0)
7749 endif
7750
7751 else
7752 call netrw#Lexplore(0,0)
7753 endif
7754 let wiw= wiwkeep
7755
7756" call Dret("netrw#Shrink")
7757endfun
7758
7759" ---------------------------------------------------------------------
7760" s:NetSortSequence: allows user to edit the sorting sequence {{{2
7761fun! s:NetSortSequence(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007762 let ykeep= @@
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007763 let svpos= winsaveview()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007764 call inputsave()
7765 let newsortseq= input("Edit Sorting Sequence: ",g:netrw_sort_sequence)
7766 call inputrestore()
7767
7768 " refresh the listing
7769 let g:netrw_sort_sequence= newsortseq
Tom Benham64a536d2024-11-07 21:15:03 +01007770 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007771 NetrwKeepj call winrestview(svpos)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007772 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007773endfun
7774
7775" ---------------------------------------------------------------------
7776" s:NetrwUnmarkList: delete local marked file list and remove their contents from the global marked-file list {{{2
7777" User access provided by the <mF> mapping. (see :help netrw-mF)
Bram Moolenaarff034192013-04-24 18:51:19 +02007778" Used by many MarkFile functions.
Bram Moolenaar446cb832008-06-24 21:56:24 +00007779fun! s:NetrwUnmarkList(curbufnr,curdir)
7780" call Dfunc("s:NetrwUnmarkList(curbufnr=".a:curbufnr." curdir<".a:curdir.">)")
7781
7782 " remove all files in local marked-file list from global list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007783 if exists("s:netrwmarkfilelist")
Bram Moolenaar446cb832008-06-24 21:56:24 +00007784 for mfile in s:netrwmarkfilelist_{a:curbufnr}
7785 let dfile = s:ComposePath(a:curdir,mfile) " prepend directory to mfile
7786 let idx = index(s:netrwmarkfilelist,dfile) " get index in list of dfile
7787 call remove(s:netrwmarkfilelist,idx) " remove from global list
7788 endfor
7789 if s:netrwmarkfilelist == []
7790 unlet s:netrwmarkfilelist
7791 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007792
Bram Moolenaar446cb832008-06-24 21:56:24 +00007793 " getting rid of the local marked-file lists is easy
7794 unlet s:netrwmarkfilelist_{a:curbufnr}
7795 endif
7796 if exists("s:netrwmarkfilemtch_{a:curbufnr}")
7797 unlet s:netrwmarkfilemtch_{a:curbufnr}
7798 endif
7799 2match none
7800" call Dret("s:NetrwUnmarkList")
7801endfun
7802
7803" ---------------------------------------------------------------------
7804" s:NetrwUnmarkAll: remove the global marked file list and all local ones {{{2
7805fun! s:NetrwUnmarkAll()
7806" call Dfunc("s:NetrwUnmarkAll()")
7807 if exists("s:netrwmarkfilelist")
7808 unlet s:netrwmarkfilelist
7809 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +02007810 sil call s:NetrwUnmarkAll2()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007811 2match none
7812" call Dret("s:NetrwUnmarkAll")
7813endfun
7814
7815" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02007816" s:NetrwUnmarkAll2: unmark all files from all buffers {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00007817fun! s:NetrwUnmarkAll2()
7818" call Dfunc("s:NetrwUnmarkAll2()")
7819 redir => netrwmarkfilelist_let
7820 let
7821 redir END
7822 let netrwmarkfilelist_list= split(netrwmarkfilelist_let,'\n') " convert let string into a let list
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007823 call filter(netrwmarkfilelist_list,"v:val =~ '^s:netrwmarkfilelist_'") " retain only those vars that start as s:netrwmarkfilelist_
Bram Moolenaar446cb832008-06-24 21:56:24 +00007824 call map(netrwmarkfilelist_list,"substitute(v:val,'\\s.*$','','')") " remove what the entries are equal to
7825 for flist in netrwmarkfilelist_list
7826 let curbufnr= substitute(flist,'s:netrwmarkfilelist_','','')
7827 unlet s:netrwmarkfilelist_{curbufnr}
7828 unlet s:netrwmarkfilemtch_{curbufnr}
7829 endfor
7830" call Dret("s:NetrwUnmarkAll2")
7831endfun
7832
7833" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007834" s:NetrwUnMarkFile: called via mu map; unmarks *all* marked files, both global and buffer-local {{{2
7835"
7836" Marked files are in two types of lists:
7837" s:netrwmarkfilelist -- holds complete paths to all marked files
7838" s:netrwmarkfilelist_# -- holds list of marked files in current-buffer's directory (#==bufnr())
7839"
7840" Marked files suitable for use with 2match are in:
7841" s:netrwmarkfilemtch_# -- used with 2match to display marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +00007842fun! s:NetrwUnMarkFile(islocal)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007843 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00007844 let curbufnr = bufnr("%")
7845
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007846 " unmark marked file list
7847 " (although I expect s:NetrwUpload() to do it, I'm just making sure)
7848 if exists("s:netrwmarkfilelist")
7849" " call Decho("unlet'ing: s:netrwmarkfilelist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007850 unlet s:netrwmarkfilelist
Bram Moolenaar446cb832008-06-24 21:56:24 +00007851 endif
7852
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007853 let ibuf= 1
7854 while ibuf < bufnr("$")
7855 if exists("s:netrwmarkfilelist_".ibuf)
7856 unlet s:netrwmarkfilelist_{ibuf}
7857 unlet s:netrwmarkfilemtch_{ibuf}
7858 endif
7859 let ibuf = ibuf + 1
7860 endwhile
7861 2match none
7862
Tom Benham64a536d2024-11-07 21:15:03 +01007863" call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01007864call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00007865endfun
7866
7867" ---------------------------------------------------------------------
7868" s:NetrwMenu: generates the menu for gvim and netrw {{{2
7869fun! s:NetrwMenu(domenu)
7870
7871 if !exists("g:NetrwMenuPriority")
7872 let g:NetrwMenuPriority= 80
7873 endif
7874
Bram Moolenaaradc21822011-04-01 18:03:16 +02007875 if has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaar446cb832008-06-24 21:56:24 +00007876" call Dfunc("NetrwMenu(domenu=".a:domenu.")")
7877
7878 if !exists("s:netrw_menu_enabled") && a:domenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007879" call Decho("initialize menu",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00007880 let s:netrw_menu_enabled= 1
Bram Moolenaarff034192013-04-24 18:51:19 +02007881 exe 'sil! menu '.g:NetrwMenuPriority.'.1 '.g:NetrwTopLvlMenu.'Help<tab><F1> <F1>'
7882 exe 'sil! menu '.g:NetrwMenuPriority.'.5 '.g:NetrwTopLvlMenu.'-Sep1- :'
7883 exe 'sil! menu '.g:NetrwMenuPriority.'.6 '.g:NetrwTopLvlMenu.'Go\ Up\ Directory<tab>- -'
7884 exe 'sil! menu '.g:NetrwMenuPriority.'.7 '.g:NetrwTopLvlMenu.'Apply\ Special\ Viewer<tab>x x'
7885 if g:netrw_dirhistmax > 0
7886 exe 'sil! menu '.g:NetrwMenuPriority.'.8.1 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Bookmark\ Current\ Directory<tab>mb mb'
7887 exe 'sil! menu '.g:NetrwMenuPriority.'.8.4 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Prev\ Dir\ (History)<tab>u u'
7888 exe 'sil! menu '.g:NetrwMenuPriority.'.8.5 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.Goto\ Next\ Dir\ (History)<tab>U U'
7889 exe 'sil! menu '.g:NetrwMenuPriority.'.8.6 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History.List<tab>qb qb'
7890 else
7891 exe 'sil! menu '.g:NetrwMenuPriority.'.8 '.g:NetrwTopLvlMenu.'Bookmarks\ and\ History :echo "(disabled)"'."\<cr>"
7892 endif
7893 exe 'sil! menu '.g:NetrwMenuPriority.'.9.1 '.g:NetrwTopLvlMenu.'Browsing\ Control.Horizontal\ Split<tab>o o'
7894 exe 'sil! menu '.g:NetrwMenuPriority.'.9.2 '.g:NetrwTopLvlMenu.'Browsing\ Control.Vertical\ Split<tab>v v'
7895 exe 'sil! menu '.g:NetrwMenuPriority.'.9.3 '.g:NetrwTopLvlMenu.'Browsing\ Control.New\ Tab<tab>t t'
7896 exe 'sil! menu '.g:NetrwMenuPriority.'.9.4 '.g:NetrwTopLvlMenu.'Browsing\ Control.Preview<tab>p p'
7897 exe 'sil! menu '.g:NetrwMenuPriority.'.9.5 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ File\ Hiding\ List<tab><ctrl-h>'." \<c-h>'"
7898 exe 'sil! menu '.g:NetrwMenuPriority.'.9.6 '.g:NetrwTopLvlMenu.'Browsing\ Control.Edit\ Sorting\ Sequence<tab>S S'
7899 exe 'sil! menu '.g:NetrwMenuPriority.'.9.7 '.g:NetrwTopLvlMenu.'Browsing\ Control.Quick\ Hide/Unhide\ Dot\ Files<tab>'."gh gh"
7900 exe 'sil! menu '.g:NetrwMenuPriority.'.9.8 '.g:NetrwTopLvlMenu.'Browsing\ Control.Refresh\ Listing<tab>'."<ctrl-l> \<c-l>"
7901 exe 'sil! menu '.g:NetrwMenuPriority.'.9.9 '.g:NetrwTopLvlMenu.'Browsing\ Control.Settings/Options<tab>:NetrwSettings '.":NetrwSettings\<cr>"
7902 exe 'sil! menu '.g:NetrwMenuPriority.'.10 '.g:NetrwTopLvlMenu.'Delete\ File/Directory<tab>D D'
7903 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Create\ New\ File<tab>% %'
7904 exe 'sil! menu '.g:NetrwMenuPriority.'.11.1 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Current\ Window<tab><cr> '."\<cr>"
7905 exe 'sil! menu '.g:NetrwMenuPriority.'.11.2 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.Preview\ File/Directory<tab>p p'
7906 exe 'sil! menu '.g:NetrwMenuPriority.'.11.3 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ Previous\ Window<tab>P P'
7907 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 +01007908 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 +02007909 exe 'sil! menu '.g:NetrwMenuPriority.'.11.5 '.g:NetrwTopLvlMenu.'Edit\ File/Dir.In\ New\ Vertical\ Window<tab>v v'
7910 exe 'sil! menu '.g:NetrwMenuPriority.'.12.1 '.g:NetrwTopLvlMenu.'Explore.Directory\ Name :Explore '
7911 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (curdir\ only)<tab>:Explore\ */ :Explore */'
7912 exe 'sil! menu '.g:NetrwMenuPriority.'.12.2 '.g:NetrwTopLvlMenu.'Explore.Filenames\ Matching\ Pattern\ (+subdirs)<tab>:Explore\ **/ :Explore **/'
7913 exe 'sil! menu '.g:NetrwMenuPriority.'.12.3 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (curdir\ only)<tab>:Explore\ *// :Explore *//'
7914 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Files\ Containing\ String\ Pattern\ (+subdirs)<tab>:Explore\ **// :Explore **//'
7915 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Next\ Match<tab>:Nexplore :Nexplore<cr>'
7916 exe 'sil! menu '.g:NetrwMenuPriority.'.12.4 '.g:NetrwTopLvlMenu.'Explore.Prev\ Match<tab>:Pexplore :Pexplore<cr>'
7917 exe 'sil! menu '.g:NetrwMenuPriority.'.13 '.g:NetrwTopLvlMenu.'Make\ Subdirectory<tab>d d'
7918 exe 'sil! menu '.g:NetrwMenuPriority.'.14.1 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ File<tab>mf mf'
7919 exe 'sil! menu '.g:NetrwMenuPriority.'.14.2 '.g:NetrwTopLvlMenu.'Marked\ Files.Mark\ Files\ by\ Regexp<tab>mr mr'
7920 exe 'sil! menu '.g:NetrwMenuPriority.'.14.3 '.g:NetrwTopLvlMenu.'Marked\ Files.Hide-Show-List\ Control<tab>a a'
7921 exe 'sil! menu '.g:NetrwMenuPriority.'.14.4 '.g:NetrwTopLvlMenu.'Marked\ Files.Copy\ To\ Target<tab>mc mc'
7922 exe 'sil! menu '.g:NetrwMenuPriority.'.14.5 '.g:NetrwTopLvlMenu.'Marked\ Files.Delete<tab>D D'
7923 exe 'sil! menu '.g:NetrwMenuPriority.'.14.6 '.g:NetrwTopLvlMenu.'Marked\ Files.Diff<tab>md md'
7924 exe 'sil! menu '.g:NetrwMenuPriority.'.14.7 '.g:NetrwTopLvlMenu.'Marked\ Files.Edit<tab>me me'
7925 exe 'sil! menu '.g:NetrwMenuPriority.'.14.8 '.g:NetrwTopLvlMenu.'Marked\ Files.Exe\ Cmd<tab>mx mx'
7926 exe 'sil! menu '.g:NetrwMenuPriority.'.14.9 '.g:NetrwTopLvlMenu.'Marked\ Files.Move\ To\ Target<tab>mm mm'
7927 exe 'sil! menu '.g:NetrwMenuPriority.'.14.10 '.g:NetrwTopLvlMenu.'Marked\ Files.Obtain<tab>O O'
7928 exe 'sil! menu '.g:NetrwMenuPriority.'.14.11 '.g:NetrwTopLvlMenu.'Marked\ Files.Print<tab>mp mp'
7929 exe 'sil! menu '.g:NetrwMenuPriority.'.14.12 '.g:NetrwTopLvlMenu.'Marked\ Files.Replace<tab>R R'
7930 exe 'sil! menu '.g:NetrwMenuPriority.'.14.13 '.g:NetrwTopLvlMenu.'Marked\ Files.Set\ Target<tab>mt mt'
7931 exe 'sil! menu '.g:NetrwMenuPriority.'.14.14 '.g:NetrwTopLvlMenu.'Marked\ Files.Tag<tab>mT mT'
7932 exe 'sil! menu '.g:NetrwMenuPriority.'.14.15 '.g:NetrwTopLvlMenu.'Marked\ Files.Zip/Unzip/Compress/Uncompress<tab>mz mz'
7933 exe 'sil! menu '.g:NetrwMenuPriority.'.15 '.g:NetrwTopLvlMenu.'Obtain\ File<tab>O O'
7934 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.thin<tab>i :let w:netrw_liststyle=0<cr><c-L>'
7935 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.long<tab>i :let w:netrw_liststyle=1<cr><c-L>'
7936 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.wide<tab>i :let w:netrw_liststyle=2<cr><c-L>'
7937 exe 'sil! menu '.g:NetrwMenuPriority.'.16.1.1 '.g:NetrwTopLvlMenu.'Style.Listing.tree<tab>i :let w:netrw_liststyle=3<cr><c-L>'
7938 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>'
7939 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>'
7940 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>'
7941 exe 'sil! menu '.g:NetrwMenuPriority.'.16.3 '.g:NetrwTopLvlMenu.'Style.Reverse\ Sorting\ Order<tab>'."r r"
7942 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>'
7943 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>'
7944 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 +01007945 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 +02007946 exe 'sil! menu '.g:NetrwMenuPriority.'.17 '.g:NetrwTopLvlMenu.'Rename\ File/Directory<tab>R R'
7947 exe 'sil! menu '.g:NetrwMenuPriority.'.18 '.g:NetrwTopLvlMenu.'Set\ Current\ Directory<tab>c c'
Bram Moolenaar446cb832008-06-24 21:56:24 +00007948 let s:netrw_menucnt= 28
Bram Moolenaarff034192013-04-24 18:51:19 +02007949 call s:NetrwBookmarkMenu() " provide some history! uses priorities 2,3, reserves 4, 8.2.x
7950 call s:NetrwTgtMenu() " let bookmarks and history be easy targets
Bram Moolenaar446cb832008-06-24 21:56:24 +00007951
7952 elseif !a:domenu
7953 let s:netrwcnt = 0
7954 let curwin = winnr()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02007955 windo if getline(2) =~# "Netrw" | let s:netrwcnt= s:netrwcnt + 1 | endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00007956 exe curwin."wincmd w"
7957
7958 if s:netrwcnt <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007959" call Decho("clear menus",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007960 exe 'sil! unmenu '.g:NetrwTopLvlMenu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007961" call Decho('exe sil! unmenu '.g:NetrwTopLvlMenu.'*','~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02007962 sil! unlet s:netrw_menu_enabled
Bram Moolenaar446cb832008-06-24 21:56:24 +00007963 endif
7964 endif
7965" call Dret("NetrwMenu")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02007966 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00007967 endif
7968
7969endfun
7970
7971" ---------------------------------------------------------------------
7972" s:NetrwObtain: obtain file under cursor or from markfile list {{{2
7973" Used by the O maps (as <SID>NetrwObtain())
7974fun! s:NetrwObtain(islocal)
7975" call Dfunc("NetrwObtain(islocal=".a:islocal.")")
7976
Bram Moolenaar97d62492012-11-15 21:28:22 +01007977 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00007978 if exists("s:netrwmarkfilelist_{bufnr('%')}")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01007979 let islocal= s:netrwmarkfilelist_{bufnr('%')}[1] !~ '^\a\{3,}://'
Bram Moolenaara6878372014-03-22 21:02:50 +01007980 call netrw#Obtain(islocal,s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaar446cb832008-06-24 21:56:24 +00007981 call s:NetrwUnmarkList(bufnr('%'),b:netrw_curdir)
7982 else
Bram Moolenaar85850f32019-07-19 22:05:51 +02007983 call netrw#Obtain(a:islocal,s:NetrwGetWord())
Bram Moolenaar446cb832008-06-24 21:56:24 +00007984 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01007985 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00007986
7987" call Dret("NetrwObtain")
7988endfun
7989
7990" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00007991" s:NetrwPrevWinOpen: open file/directory in previous window. {{{2
7992" If there's only one window, then the window will first be split.
7993" Returns:
7994" choice = 0 : didn't have to choose
7995" choice = 1 : saved modified file in window first
7996" choice = 2 : didn't save modified file, opened window
7997" choice = 3 : cancel open
7998fun! s:NetrwPrevWinOpen(islocal)
Bram Moolenaar97d62492012-11-15 21:28:22 +01007999 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008000 " grab a copy of the b:netrw_curdir to pass it along to newly split windows
Bram Moolenaara6878372014-03-22 21:02:50 +01008001 let curdir = b:netrw_curdir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008002
8003 " get last window number and the word currently under the cursor
Bram Moolenaar8d043172014-01-23 14:24:41 +01008004 let origwin = winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008005 let lastwinnr = winnr("$")
Bram Moolenaar71badf92023-04-22 22:40:14 +01008006 let curword = s:NetrwGetWord()
8007 let choice = 0
8008 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 +01008009 let s:treedir = s:NetrwTreeDir(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01008010 let curdir = s:treedir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008011
Bram Moolenaar8d043172014-01-23 14:24:41 +01008012 let didsplit = 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00008013 if lastwinnr == 1
8014 " if only one window, open a new one first
Bram Moolenaar85850f32019-07-19 22:05:51 +02008015 " g:netrw_preview=0: preview window shown in a horizontally split window
8016 " g:netrw_preview=1: preview window shown in a vertically split window
Bram Moolenaar446cb832008-06-24 21:56:24 +00008017 if g:netrw_preview
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008018 " vertically split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008019 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008020 exe (g:netrw_alto? "top " : "bot ")."vert ".winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008021 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008022 " horizontally split preview window
Bram Moolenaar85850f32019-07-19 22:05:51 +02008023 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar15146672011-10-20 22:22:38 +02008024 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008025 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008026 let didsplit = 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00008027
8028 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008029 NetrwKeepj call s:SaveBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008030 let eikeep= &ei
Bram Moolenaara6878372014-03-22 21:02:50 +01008031 setl ei=all
Bram Moolenaar446cb832008-06-24 21:56:24 +00008032 wincmd p
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +01008033
Bram Moolenaar71badf92023-04-22 22:40:14 +01008034 if exists("s:lexplore_win") && s:lexplore_win == winnr()
8035 " whoops -- user trying to open file in the Lexplore window.
8036 " Use Lexplore's opening-file window instead.
Bram Moolenaar71badf92023-04-22 22:40:14 +01008037" exe g:netrw_chgwin."wincmd w"
8038 wincmd p
Tom Benham64a536d2024-11-07 21:15:03 +01008039 call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar71badf92023-04-22 22:40:14 +01008040 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008041
8042 " prevwinnr: the window number of the "prev" window
8043 " prevbufnr: the buffer number of the buffer in the "prev" window
8044 " bnrcnt : the qty of windows open on the "prev" buffer
8045 let prevwinnr = winnr()
8046 let prevbufnr = bufnr("%")
8047 let prevbufname = bufname("%")
8048 let prevmod = &mod
8049 let bnrcnt = 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008050 NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008051
8052 " if the previous window's buffer has been changed (ie. its modified flag is set),
Bram Moolenaar446cb832008-06-24 21:56:24 +00008053 " and it doesn't appear in any other extant window, then ask the
8054 " user if s/he wants to abandon modifications therein.
Bram Moolenaar8d043172014-01-23 14:24:41 +01008055 if prevmod
Bram Moolenaar8d043172014-01-23 14:24:41 +01008056 windo if winbufnr(0) == prevbufnr | let bnrcnt=bnrcnt+1 | endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008057 exe prevwinnr."wincmd w"
8058
8059 if bnrcnt == 1 && &hidden == 0
8060 " only one copy of the modified buffer in a window, and
8061 " hidden not set, so overwriting will lose the modified file. Ask first...
8062 let choice = confirm("Save modified buffer<".prevbufname."> first?","&Yes\n&No\n&Cancel")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008063 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008064
8065 if choice == 1
8066 " Yes -- write file & then browse
8067 let v:errmsg= ""
Bram Moolenaaradc21822011-04-01 18:03:16 +02008068 sil w
Bram Moolenaar446cb832008-06-24 21:56:24 +00008069 if v:errmsg != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008070 call netrw#ErrorMsg(s:ERROR,"unable to write <".(exists("prevbufname")? prevbufname : 'n/a').">!",30)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008071 exe origwin."wincmd w"
8072 let &ei = eikeep
8073 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008074 return choice
8075 endif
8076
8077 elseif choice == 2
8078 " No -- don't worry about changed file, just browse anyway
Bram Moolenaar8d043172014-01-23 14:24:41 +01008079 echomsg "**note** changes to ".prevbufname." abandoned"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008080
8081 else
8082 " Cancel -- don't do this
Bram Moolenaar8d043172014-01-23 14:24:41 +01008083 exe origwin."wincmd w"
8084 let &ei= eikeep
8085 let @@ = ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008086 return choice
8087 endif
8088 endif
8089 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008090 let &ei= eikeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008091 endif
8092
8093 " restore b:netrw_curdir (window split/enew may have lost it)
8094 let b:netrw_curdir= curdir
8095 if a:islocal < 2
8096 if a:islocal
Tom Benham64a536d2024-11-07 21:15:03 +01008097 call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008098 else
Tom Benham64a536d2024-11-07 21:15:03 +01008099 call s:NetrwBrowse(a:islocal,s:NetrwBrowseChgDir(a:islocal,curword,0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008100 endif
8101 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +01008102 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008103 return choice
8104endfun
8105
8106" ---------------------------------------------------------------------
8107" s:NetrwUpload: load fname to tgt (used by NetrwMarkFileCopy()) {{{2
8108" Always assumed to be local -> remote
8109" call s:NetrwUpload(filename, target)
8110" call s:NetrwUpload(filename, target, fromdirectory)
8111fun! s:NetrwUpload(fname,tgt,...)
8112" call Dfunc("s:NetrwUpload(fname<".((type(a:fname) == 1)? a:fname : string(a:fname))."> tgt<".a:tgt.">) a:0=".a:0)
8113
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008114 if a:tgt =~ '^\a\{3,}://'
8115 let tgtdir= substitute(a:tgt,'^\a\{3,}://[^/]\+/\(.\{-}\)$','\1','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008116 else
8117 let tgtdir= substitute(a:tgt,'^\(.*\)/[^/]*$','\1','')
8118 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008119" call Decho("tgtdir<".tgtdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008120
8121 if a:0 > 0
8122 let fromdir= a:1
8123 else
8124 let fromdir= getcwd()
8125 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008126" call Decho("fromdir<".fromdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008127
8128 if type(a:fname) == 1
8129 " handle uploading a single file using NetWrite
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008130" call Decho("handle uploading a single file via NetWrite",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008131 1split
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008132" call Decho("exe e ".fnameescape(s:NetrwFile(a:fname)),'~'.expand("<slnum>"))
8133 exe "NetrwKeepj e ".fnameescape(s:NetrwFile(a:fname))
8134" call Decho("now locally editing<".expand("%").">, has ".line("$")." lines",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008135 if a:tgt =~ '/$'
8136 let wfname= substitute(a:fname,'^.*/','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008137" call Decho("exe w! ".fnameescape(wfname),'~'.expand("<slnum>"))
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008138 exe "w! ".fnameescape(a:tgt.wfname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008139 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008140" call Decho("writing local->remote: exe w ".fnameescape(a:tgt),'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00008141 exe "w ".fnameescape(a:tgt)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008142" call Decho("done writing local->remote",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008143 endif
8144 q!
8145
8146 elseif type(a:fname) == 3
8147 " handle uploading a list of files via scp
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008148" call Decho("handle uploading a list of files via scp",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008149 let curdir= getcwd()
8150 if a:tgt =~ '^scp:'
Bram Moolenaar85850f32019-07-19 22:05:51 +02008151 if s:NetrwLcd(fromdir)
8152" call Dret("s:NetrwUpload : lcd failure")
8153 return
8154 endif
Bram Moolenaare37d50a2008-08-06 17:06:04 +00008155 let filelist= deepcopy(s:netrwmarkfilelist_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008156 let args = join(map(filelist,"s:ShellEscape(v:val, 1)"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008157 if exists("g:netrw_port") && g:netrw_port != ""
8158 let useport= " ".g:netrw_scpport." ".g:netrw_port
8159 else
8160 let useport= ""
8161 endif
8162 let machine = substitute(a:tgt,'^scp://\([^/:]\+\).*$','\1','')
8163 let tgt = substitute(a:tgt,'^scp://[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008164 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 +02008165 if s:NetrwLcd(curdir)
8166" call Dret("s:NetrwUpload : lcd failure")
8167 return
8168 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008169
8170 elseif a:tgt =~ '^ftp:'
8171 call s:NetrwMethod(a:tgt)
8172
8173 if b:netrw_method == 2
8174 " handle uploading a list of files via ftp+.netrc
8175 let netrw_fname = b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008176 sil NetrwKeepj new
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008177" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008178
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008179 NetrwKeepj put =g:netrw_ftpmode
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008180" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008181
8182 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008183 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008184" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008185 endif
8186
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008187 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008188" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008189
Bram Moolenaaradc21822011-04-01 18:03:16 +02008190 if tgtdir == ""
8191 let tgtdir= '/'
8192 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008193 NetrwKeepj call setline(line("$")+1,'cd "'.tgtdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008194" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008195
8196 for fname in a:fname
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008197 NetrwKeepj call setline(line("$")+1,'put "'.s:NetrwFile(fname).'"')
8198" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008199 endfor
8200
8201 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008202 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 +00008203 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008204" call Decho("filter input window#".winnr(),'~'.expand("<slnum>"))
8205 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008206 endif
8207 " 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 +01008208 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008209 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008210 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8211 call netrw#ErrorMsg(s:ERROR,getline(1),14)
8212 else
8213 bw!|q
8214 endif
8215
8216 elseif b:netrw_method == 3
8217 " upload with ftp + machine, id, passwd, and fname (ie. no .netrc)
8218 let netrw_fname= b:netrw_fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008219 NetrwKeepj call s:SaveBufVars()|sil NetrwKeepj new|NetrwKeepj call s:RestoreBufVars()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008220 let tmpbufnr= bufnr("%")
Bram Moolenaarff034192013-04-24 18:51:19 +02008221 setl ff=unix
Bram Moolenaar446cb832008-06-24 21:56:24 +00008222
8223 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008224 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008225" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008226 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008227 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008228" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008229 endif
8230
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008231 if exists("g:netrw_uid") && g:netrw_uid != ""
8232 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008233 NetrwKeepj put =g:netrw_uid
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008234" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008235 if exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008236 NetrwKeepj call setline(line("$")+1,'"'.s:netrw_passwd.'"')
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008237 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008238" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008239 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008240 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008241" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008242 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008243 endif
8244
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008245 NetrwKeepj call setline(line("$")+1,'lcd "'.fromdir.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008246" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008247
8248 if exists("b:netrw_fname") && b:netrw_fname != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008249 NetrwKeepj call setline(line("$")+1,'cd "'.b:netrw_fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008250" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008251 endif
8252
8253 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008254 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008255" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008256 endif
8257
8258 for fname in a:fname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008259 NetrwKeepj call setline(line("$")+1,'put "'.fname.'"')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008260" call Decho("filter input: ".getline('$'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008261 endfor
8262
8263 " perform ftp:
8264 " -i : turns off interactive prompting from ftp
8265 " -n unix : DON'T use <.netrc>, even though it exists
8266 " -n win32: quit being obnoxious about password
Bram Moolenaar91359012019-11-30 17:57:03 +01008267 NetrwKeepj norm! 1G"_dd
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008268 call s:NetrwExe(s:netrw_silentxfer."%!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008269 " 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 +01008270 sil NetrwKeepj g/Local directory now/d
Bram Moolenaar5c736222010-01-06 20:54:52 +01008271 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008272 if getline(1) !~ "^$" && !exists("g:netrw_quiet") && getline(1) !~ '^Trying '
8273 let debugkeep= &debug
Bram Moolenaarff034192013-04-24 18:51:19 +02008274 setl debug=msg
Bram Moolenaar446cb832008-06-24 21:56:24 +00008275 call netrw#ErrorMsg(s:ERROR,getline(1),15)
8276 let &debug = debugkeep
8277 let mod = 1
8278 else
8279 bw!|q
8280 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01008281 elseif !exists("b:netrw_method") || b:netrw_method < 0
Bram Moolenaar85850f32019-07-19 22:05:51 +02008282" call Dret("s:#NetrwUpload : unsupported method")
Bram Moolenaar5c736222010-01-06 20:54:52 +01008283 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008284 endif
8285 else
8286 call netrw#ErrorMsg(s:ERROR,"can't obtain files with protocol from<".a:tgt.">",63)
8287 endif
8288 endif
8289
8290" call Dret("s:NetrwUpload")
8291endfun
8292
8293" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008294" s:NetrwPreview: supports netrw's "p" map {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008295fun! s:NetrwPreview(path) range
8296" call Dfunc("NetrwPreview(path<".a:path.">)")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008297" call Decho("g:netrw_alto =".(exists("g:netrw_alto")? g:netrw_alto : 'n/a'),'~'.expand("<slnum>"))
8298" call Decho("g:netrw_preview=".(exists("g:netrw_preview")? g:netrw_preview : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008299 let ykeep= @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008300 NetrwKeepj call s:NetrwOptionsSave("s:")
8301 if a:path !~ '^\*\{1,2}/' && a:path !~ '^\a\{3,}://'
8302 NetrwKeepj call s:NetrwOptionsSafe(1)
8303 else
8304 NetrwKeepj call s:NetrwOptionsSafe(0)
8305 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008306 if has("quickfix")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008307" call Decho("has quickfix",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008308 if !isdirectory(s:NetrwFile(a:path))
Bram Moolenaar85850f32019-07-19 22:05:51 +02008309" call Decho("good; not previewing a directory",'~'.expand("<slnum>"))
8310 if g:netrw_preview
8311 " vertical split
Bram Moolenaar15146672011-10-20 22:22:38 +02008312 let pvhkeep = &pvh
8313 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
8314 let &pvh = winwidth(0) - winsz
Bram Moolenaar85850f32019-07-19 22:05:51 +02008315" call Decho("g:netrw_preview: winsz=".winsz." &pvh=".&pvh." (temporarily) g:netrw_winsize=".g:netrw_winsize,'~'.expand("<slnum>"))
8316 else
8317 " horizontal split
8318 let pvhkeep = &pvh
8319 let winsz = (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
8320 let &pvh = winheight(0) - winsz
8321" 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 +02008322 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008323 " g:netrw_preview g:netrw_alto
8324 " 1 : vert 1: top -- preview window is vertically split off and on the left
8325 " 1 : vert 0: bot -- preview window is vertically split off and on the right
8326 " 0 : 1: top -- preview window is horizontally split off and on the top
8327 " 0 : 0: bot -- preview window is horizontally split off and on the bottom
8328 "
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008329 " 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 +02008330 " the BufEnter event set up in netrwPlugin.vim
8331" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
8332 let eikeep = &ei
8333 set ei=BufEnter
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008334 exe (g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008335 let &ei= eikeep
8336" call Decho("winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +02008337 if exists("pvhkeep")
8338 let &pvh= pvhkeep
8339 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008340 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008341 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"sorry, cannot preview a directory such as <".a:path.">",38)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008342 endif
8343 elseif !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008344 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 +00008345 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02008346 NetrwKeepj call s:NetrwOptionsRestore("s:")
Bram Moolenaar97d62492012-11-15 21:28:22 +01008347 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008348" call Dret("NetrwPreview")
8349endfun
8350
8351" ---------------------------------------------------------------------
8352" s:NetrwRefresh: {{{2
8353fun! s:NetrwRefresh(islocal,dirname)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008354" 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 +00008355 " at the current time (Mar 19, 2007) all calls to NetrwRefresh() call NetrwBrowseChgDir() first.
Bram Moolenaarff034192013-04-24 18:51:19 +02008356 setl ma noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008357" call Decho("setl ma noro",'~'.expand("<slnum>"))
8358" call Decho("clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01008359 let ykeep = @@
Bram Moolenaar85850f32019-07-19 22:05:51 +02008360 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
8361 if !exists("w:netrw_treetop")
8362 if exists("b:netrw_curdir")
8363 let w:netrw_treetop= b:netrw_curdir
8364 else
8365 let w:netrw_treetop= getcwd()
8366 endif
8367 endif
8368 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
8369 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008370
8371 " save the cursor position before refresh.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008372 let screenposn = winsaveview()
8373" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008374
8375" call Decho("win#".winnr().": ".winheight(0)."x".winwidth(0)." curfile<".expand("%").">",'~'.expand("<slnum>"))
8376" call Decho("clearing buffer prior to refresh",'~'.expand("<slnum>"))
8377 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008378 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008379 NetrwKeepj call netrw#LocalBrowseCheck(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008380 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008381 NetrwKeepj call s:NetrwBrowse(a:islocal,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008382 endif
Bram Moolenaar13600302014-05-22 18:26:40 +02008383
8384 " restore position
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008385" call Decho("restoring posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
8386 NetrwKeepj call winrestview(screenposn)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008387
8388 " restore file marks
Bram Moolenaar85850f32019-07-19 22:05:51 +02008389 if has("syntax") && exists("g:syntax_on") && g:syntax_on
8390 if exists("s:netrwmarkfilemtch_{bufnr('%')}") && s:netrwmarkfilemtch_{bufnr("%")} != ""
8391" " call Decho("exe 2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/",'~'.expand("<slnum>"))
8392 exe "2match netrwMarkFile /".s:netrwmarkfilemtch_{bufnr("%")}."/"
8393 else
8394" " call Decho("2match none (bufnr(%)=".bufnr("%")."<".bufname("%").">)",'~'.expand("<slnum>"))
8395 2match none
8396 endif
8397 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008398
Bram Moolenaar97d62492012-11-15 21:28:22 +01008399" restore
8400 let @@= ykeep
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008401" call Dret("s:NetrwRefresh")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008402endfun
8403
8404" ---------------------------------------------------------------------
8405" s:NetrwRefreshDir: refreshes a directory by name {{{2
8406" Called by NetrwMarkFileCopy()
Bram Moolenaara6878372014-03-22 21:02:50 +01008407" Interfaces to s:NetrwRefresh() and s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008408fun! s:NetrwRefreshDir(islocal,dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008409 if g:netrw_fastbrowse == 0
8410 " slowest mode (keep buffers refreshed, local or remote)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008411 let tgtwin= bufwinnr(a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008412
8413 if tgtwin > 0
8414 " tgtwin is being displayed, so refresh it
8415 let curwin= winnr()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008416 exe tgtwin."wincmd w"
Tom Benham64a536d2024-11-07 21:15:03 +01008417 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008418 exe curwin."wincmd w"
8419
8420 elseif bufnr(a:dirname) > 0
8421 let bn= bufnr(a:dirname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008422 exe "sil keepj bd ".bn
Bram Moolenaar446cb832008-06-24 21:56:24 +00008423 endif
8424
8425 elseif g:netrw_fastbrowse <= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008426 NetrwKeepj call s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008427 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008428endfun
8429
8430" ---------------------------------------------------------------------
Bram Moolenaar13600302014-05-22 18:26:40 +02008431" s:NetrwSetChgwin: set g:netrw_chgwin; a <cr> will use the specified
8432" window number to do its editing in.
8433" Supports [count]C where the count, if present, is used to specify
8434" a window to use for editing via the <cr> mapping.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008435fun! s:NetrwSetChgwin(...)
Bram Moolenaar13600302014-05-22 18:26:40 +02008436" call Dfunc("s:NetrwSetChgwin() v:count=".v:count)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008437 if a:0 > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008438" call Decho("a:1<".a:1.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008439 if a:1 == "" " :NetrwC win#
8440 let g:netrw_chgwin= winnr()
8441 else " :NetrwC
8442 let g:netrw_chgwin= a:1
8443 endif
8444 elseif v:count > 0 " [count]C
Bram Moolenaar13600302014-05-22 18:26:40 +02008445 let g:netrw_chgwin= v:count
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008446 else " C
Bram Moolenaar13600302014-05-22 18:26:40 +02008447 let g:netrw_chgwin= winnr()
8448 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008449 echo "editing window now set to window#".g:netrw_chgwin
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008450" call Dret("s:NetrwSetChgwin : g:netrw_chgwin=".g:netrw_chgwin)
Bram Moolenaar13600302014-05-22 18:26:40 +02008451endfun
8452
8453" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008454" s:NetrwSetSort: sets up the sort based on the g:netrw_sort_sequence {{{2
8455" What this function does is to compute a priority for the patterns
8456" in the g:netrw_sort_sequence. It applies a substitute to any
8457" "files" that satisfy each pattern, putting the priority / in
8458" front. An "*" pattern handles the default priority.
8459fun! s:NetrwSetSort()
8460" call Dfunc("SetSort() bannercnt=".w:netrw_bannercnt)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008461 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008462 if w:netrw_liststyle == s:LONGLIST
8463 let seqlist = substitute(g:netrw_sort_sequence,'\$','\\%(\t\\|\$\\)','ge')
8464 else
8465 let seqlist = g:netrw_sort_sequence
8466 endif
8467 " sanity check -- insure that * appears somewhere
8468 if seqlist == ""
8469 let seqlist= '*'
8470 elseif seqlist !~ '\*'
8471 let seqlist= seqlist.',*'
8472 endif
8473 let priority = 1
8474 while seqlist != ""
8475 if seqlist =~ ','
8476 let seq = substitute(seqlist,',.*$','','e')
8477 let seqlist = substitute(seqlist,'^.\{-},\(.*\)$','\1','e')
8478 else
8479 let seq = seqlist
8480 let seqlist = ""
8481 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008482 if priority < 10
Bram Moolenaar5c736222010-01-06 20:54:52 +01008483 let spriority= "00".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008484 elseif priority < 100
Bram Moolenaar5c736222010-01-06 20:54:52 +01008485 let spriority= "0".priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008486 else
Bram Moolenaar5c736222010-01-06 20:54:52 +01008487 let spriority= priority.g:netrw_sepchr
Bram Moolenaar446cb832008-06-24 21:56:24 +00008488 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008489" call Decho("priority=".priority." spriority<".spriority."> seq<".seq."> seqlist<".seqlist.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008490
8491 " sanity check
8492 if w:netrw_bannercnt > line("$")
8493 " apparently no files were left after a Hiding pattern was used
8494" call Dret("SetSort : no files left after hiding")
8495 return
8496 endif
8497 if seq == '*'
8498 let starpriority= spriority
8499 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008500 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/'.seq.'/s/^/'.spriority.'/'
Bram Moolenaar5c736222010-01-06 20:54:52 +01008501 call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008502 " sometimes multiple sorting patterns will match the same file or directory.
8503 " The following substitute is intended to remove the excess matches.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008504 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^\d\{3}'.g:netrw_sepchr.'\d\{3}\//s/^\d\{3}'.g:netrw_sepchr.'\(\d\{3}\/\).\@=/\1/e'
8505 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008506 endif
8507 let priority = priority + 1
8508 endwhile
8509 if exists("starpriority")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008510 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v/^\d\{3}'.g:netrw_sepchr.'/s/^/'.starpriority.'/e'
8511 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008512 endif
8513
8514 " Following line associated with priority -- items that satisfy a priority
8515 " pattern get prefixed by ###/ which permits easy sorting by priority.
8516 " Sometimes files can satisfy multiple priority patterns -- only the latest
8517 " priority pattern needs to be retained. So, at this point, these excess
8518 " priority prefixes need to be removed, but not directories that happen to
8519 " be just digits themselves.
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008520 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\d\{3}'.g:netrw_sepchr.'\)\%(\d\{3}'.g:netrw_sepchr.'\)\+\ze./\1/e'
8521 NetrwKeepj call histdel("/",-1)
Bram Moolenaar97d62492012-11-15 21:28:22 +01008522 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008523
8524" call Dret("SetSort")
8525endfun
8526
Bram Moolenaarff034192013-04-24 18:51:19 +02008527" ---------------------------------------------------------------------
8528" s:NetrwSetTgt: sets the target to the specified choice index {{{2
8529" Implements [count]Tb (bookhist<b>)
8530" [count]Th (bookhist<h>)
8531" See :help netrw-qb for how to make the choice.
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008532fun! s:NetrwSetTgt(islocal,bookhist,choice)
8533" call Dfunc("s:NetrwSetTgt(islocal=".a:islocal." bookhist<".a:bookhist."> choice#".a:choice.")")
Bram Moolenaarff034192013-04-24 18:51:19 +02008534
8535 if a:bookhist == 'b'
8536 " supports choosing a bookmark as a target using a qb-generated list
8537 let choice= a:choice - 1
8538 if exists("g:netrw_bookmarklist[".choice."]")
Bram Moolenaara6878372014-03-22 21:02:50 +01008539 call netrw#MakeTgt(g:netrw_bookmarklist[choice])
Bram Moolenaarff034192013-04-24 18:51:19 +02008540 else
8541 echomsg "Sorry, bookmark#".a:choice." doesn't exist!"
8542 endif
8543
8544 elseif a:bookhist == 'h'
8545 " supports choosing a history stack entry as a target using a qb-generated list
8546 let choice= (a:choice % g:netrw_dirhistmax) + 1
8547 if exists("g:netrw_dirhist_".choice)
8548 let histentry = g:netrw_dirhist_{choice}
Bram Moolenaara6878372014-03-22 21:02:50 +01008549 call netrw#MakeTgt(histentry)
Bram Moolenaarff034192013-04-24 18:51:19 +02008550 else
8551 echomsg "Sorry, history#".a:choice." not available!"
8552 endif
8553 endif
8554
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008555 " refresh the display
8556 if !exists("b:netrw_curdir")
8557 let b:netrw_curdir= getcwd()
8558 endif
8559 call s:NetrwRefresh(a:islocal,b:netrw_curdir)
8560
Bram Moolenaarff034192013-04-24 18:51:19 +02008561" call Dret("s:NetrwSetTgt")
8562endfun
8563
Bram Moolenaar446cb832008-06-24 21:56:24 +00008564" =====================================================================
Bram Moolenaar85850f32019-07-19 22:05:51 +02008565" s:NetrwSortStyle: change sorting style (name - time - size - exten) and refresh display {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +00008566fun! s:NetrwSortStyle(islocal)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008567 NetrwKeepj call s:NetrwSaveWordPosn()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008568 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008569
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008570 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 +01008571 NetrwKeepj norm! 0
Tom Benham64a536d2024-11-07 21:15:03 +01008572 NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008573 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008574endfun
8575
8576" ---------------------------------------------------------------------
8577" s:NetrwSplit: mode {{{2
8578" =0 : net and o
8579" =1 : net and t
8580" =2 : net and v
8581" =3 : local and o
8582" =4 : local and t
8583" =5 : local and v
8584fun! s:NetrwSplit(mode)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008585
Bram Moolenaar97d62492012-11-15 21:28:22 +01008586 let ykeep= @@
Bram Moolenaar446cb832008-06-24 21:56:24 +00008587 call s:SaveWinVars()
8588
8589 if a:mode == 0
8590 " remote and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008591 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008592 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008593 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008594 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008595 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008596 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008597 unlet s:didsplit
8598
8599 elseif a:mode == 1
8600 " remote and t
Tom Benham64a536d2024-11-07 21:15:03 +01008601 let newdir = s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008602 tabnew
8603 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008604 NetrwKeepj call s:RestoreWinVars()
8605 NetrwKeepj call s:NetrwBrowse(0,newdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008606 unlet s:didsplit
8607
8608 elseif a:mode == 2
8609 " remote and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008610 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008611 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008612 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008613 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008614 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008615 NetrwKeepj call s:NetrwBrowse(0,s:NetrwBrowseChgDir(0,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008616 unlet s:didsplit
8617
8618 elseif a:mode == 3
8619 " local and o
Bram Moolenaar15146672011-10-20 22:22:38 +02008620 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winheight(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008621 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008622 exe (g:netrw_alto? "bel " : "abo ").winsz."wincmd s"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008623 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008624 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008625 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008626 unlet s:didsplit
8627
8628 elseif a:mode == 4
8629 " local and t
Bram Moolenaar446cb832008-06-24 21:56:24 +00008630 let cursorword = s:NetrwGetWord()
Bram Moolenaar8d043172014-01-23 14:24:41 +01008631 let eikeep = &ei
8632 let netrw_winnr = winnr()
8633 let netrw_line = line(".")
8634 let netrw_col = virtcol(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008635 NetrwKeepj norm! H0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008636 let netrw_hline = line(".")
Bram Moolenaara6878372014-03-22 21:02:50 +01008637 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008638 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8639 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008640 let &ei = eikeep
8641 let netrw_curdir = s:NetrwTreeDir(0)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008642 tabnew
Bram Moolenaar8d043172014-01-23 14:24:41 +01008643 let b:netrw_curdir = netrw_curdir
8644 let s:didsplit = 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008645 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008646 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,cursorword,0))
Bram Moolenaar8d043172014-01-23 14:24:41 +01008647 if &ft == "netrw"
Bram Moolenaara6878372014-03-22 21:02:50 +01008648 setl ei=all
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008649 exe "NetrwKeepj norm! ".netrw_hline."G0z\<CR>"
8650 exe "NetrwKeepj norm! ".netrw_line."G0".netrw_col."\<bar>"
Bram Moolenaar8d043172014-01-23 14:24:41 +01008651 let &ei= eikeep
8652 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008653 unlet s:didsplit
8654
8655 elseif a:mode == 5
8656 " local and v
Bram Moolenaar15146672011-10-20 22:22:38 +02008657 let winsz= (g:netrw_winsize > 0)? (g:netrw_winsize*winwidth(0))/100 : -g:netrw_winsize
Bram Moolenaar13600302014-05-22 18:26:40 +02008658 if winsz == 0|let winsz= ""|endif
Bram Moolenaar251e1912011-06-19 05:09:16 +02008659 exe (g:netrw_altv? "rightb " : "lefta ").winsz."wincmd v"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008660 let s:didsplit= 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008661 NetrwKeepj call s:RestoreWinVars()
Tom Benham64a536d2024-11-07 21:15:03 +01008662 NetrwKeepj call netrw#LocalBrowseCheck(s:NetrwBrowseChgDir(1,s:NetrwGetWord(),1))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008663 unlet s:didsplit
8664
8665 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008666 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"(NetrwSplit) unsupported mode=".a:mode,45)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008667 endif
8668
Bram Moolenaar97d62492012-11-15 21:28:22 +01008669 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +00008670endfun
8671
8672" ---------------------------------------------------------------------
Bram Moolenaarff034192013-04-24 18:51:19 +02008673" s:NetrwTgtMenu: {{{2
8674fun! s:NetrwTgtMenu()
8675 if !exists("s:netrw_menucnt")
8676 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008677 endif
Bram Moolenaarff034192013-04-24 18:51:19 +02008678" call Dfunc("s:NetrwTgtMenu()")
8679
8680 " the following test assures that gvim is running, has menus available, and has menus enabled.
8681 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
8682 if exists("g:NetrwTopLvlMenu")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008683" call Decho("removing ".g:NetrwTopLvlMenu."Bookmarks menu item(s)",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008684 exe 'sil! unmenu '.g:NetrwTopLvlMenu.'Targets'
8685 endif
8686 if !exists("s:netrw_initbookhist")
8687 call s:NetrwBookHistRead()
8688 endif
8689
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008690 " try to cull duplicate entries
8691 let tgtdict={}
8692
Bram Moolenaarff034192013-04-24 18:51:19 +02008693 " target bookmarked places
8694 if exists("g:netrw_bookmarklist") && g:netrw_bookmarklist != [] && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008695" call Decho("installing bookmarks as easy targets",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008696 let cnt= 1
8697 for bmd in g:netrw_bookmarklist
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008698 if has_key(tgtdict,bmd)
8699 let cnt= cnt + 1
8700 continue
8701 endif
8702 let tgtdict[bmd]= cnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008703 let ebmd= escape(bmd,g:netrw_menu_escape)
8704 " show bookmarks for goto menu
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008705" call Decho("menu: Targets: ".bmd,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008706 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 +02008707 let cnt= cnt + 1
8708 endfor
8709 endif
8710
8711 " target directory browsing history
8712 if exists("g:netrw_dirhistmax") && g:netrw_dirhistmax > 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008713" call Decho("installing history as easy targets (histmax=".g:netrw_dirhistmax.")",'~'.expand("<slnum>"))
Bram Moolenaarff034192013-04-24 18:51:19 +02008714 let histcnt = 1
8715 while histcnt <= g:netrw_dirhistmax
Bram Moolenaar85850f32019-07-19 22:05:51 +02008716 let priority = g:netrw_dirhistcnt + histcnt
Bram Moolenaarff034192013-04-24 18:51:19 +02008717 if exists("g:netrw_dirhist_{histcnt}")
8718 let histentry = g:netrw_dirhist_{histcnt}
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008719 if has_key(tgtdict,histentry)
8720 let histcnt = histcnt + 1
8721 continue
8722 endif
8723 let tgtdict[histentry] = histcnt
8724 let ehistentry = escape(histentry,g:netrw_menu_escape)
8725" call Decho("menu: Targets: ".histentry,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008726 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 +02008727 endif
8728 let histcnt = histcnt + 1
8729 endwhile
8730 endif
8731 endif
8732" call Dret("s:NetrwTgtMenu")
Bram Moolenaar446cb832008-06-24 21:56:24 +00008733endfun
8734
8735" ---------------------------------------------------------------------
8736" s:NetrwTreeDir: determine tree directory given current cursor position {{{2
8737" (full path directory with trailing slash returned)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008738fun! s:NetrwTreeDir(islocal)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008739
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008740 if exists("s:treedir") && exists("s:prevwinopen")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008741 " s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
8742 let treedir= s:treedir
8743 unlet s:treedir
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008744 unlet s:prevwinopen
Bram Moolenaar8d043172014-01-23 14:24:41 +01008745 return treedir
8746 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008747 if exists("s:prevwinopen")
8748 unlet s:prevwinopen
8749 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008750
Bram Moolenaar8d043172014-01-23 14:24:41 +01008751 if !exists("b:netrw_curdir") || b:netrw_curdir == ""
8752 let b:netrw_curdir= getcwd()
8753 endif
8754 let treedir = b:netrw_curdir
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008755 let s:treecurpos= winsaveview()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008756
8757 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar5c736222010-01-06 20:54:52 +01008758
8759 " extract tree directory if on a line specifying a subdirectory (ie. ends with "/")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008760 let curline= substitute(getline('.'),"\t -->.*$",'','')
8761 if curline =~ '/$'
Bram Moolenaar8d043172014-01-23 14:24:41 +01008762 let treedir= substitute(getline('.'),'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008763 elseif curline =~ '@$'
Tom Benham64a536d2024-11-07 21:15:03 +01008764 let potentialdir= resolve(s:NetrwTreePath(w:netrw_treetop))
Bram Moolenaar446cb832008-06-24 21:56:24 +00008765 else
8766 let treedir= ""
8767 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008768
8769 " detect user attempting to close treeroot
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008770 if curline !~ '^'.s:treedepthstring && getline('.') != '..'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008771 " now force a refresh
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008772 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00008773 return b:netrw_curdir
8774 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008775
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008776 " COMBAK: a symbolic link may point anywhere -- so it will be used to start a new treetop
8777" if a:islocal && curline =~ '@$' && isdirectory(s:NetrwFile(potentialdir))
8778" let newdir = w:netrw_treetop.'/'.potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008779 if a:islocal && curline =~ '@$'
8780 if isdirectory(s:NetrwFile(potentialdir))
Tom Benham64a536d2024-11-07 21:15:03 +01008781 let treedir = potentialdir
Christian Brabandt56b7da32024-02-29 17:48:14 +01008782 let w:netrw_treetop = treedir
8783 endif
8784 else
8785 let potentialdir= s:NetrwFile(substitute(curline,'^'.s:treedepthstring.'\+ \(.*\)@$','\1',''))
8786 let treedir = s:NetrwTreePath(w:netrw_treetop)
8787 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008788 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +01008789
8790 " sanity maintenance: keep those //s away...
Bram Moolenaar446cb832008-06-24 21:56:24 +00008791 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008792 return treedir
8793endfun
8794
8795" ---------------------------------------------------------------------
8796" s:NetrwTreeDisplay: recursive tree display {{{2
8797fun! s:NetrwTreeDisplay(dir,depth)
Tom Benham64a536d2024-11-07 21:15:03 +01008798 " ensure that there are no folds
Bram Moolenaarff034192013-04-24 18:51:19 +02008799 setl nofen
Bram Moolenaar446cb832008-06-24 21:56:24 +00008800
8801 " install ../ and shortdir
8802 if a:depth == ""
8803 call setline(line("$")+1,'../')
Bram Moolenaar446cb832008-06-24 21:56:24 +00008804 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008805 if a:dir =~ '^\a\{3,}://'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008806 if a:dir == w:netrw_treetop
8807 let shortdir= a:dir
8808 else
8809 let shortdir= substitute(a:dir,'^.*/\([^/]\+\)/$','\1/','e')
8810 endif
8811 call setline(line("$")+1,a:depth.shortdir)
8812 else
8813 let shortdir= substitute(a:dir,'^.*/','','e')
8814 call setline(line("$")+1,a:depth.shortdir.'/')
8815 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008816 " append a / to dir if its missing one
8817 let dir= a:dir
Bram Moolenaar446cb832008-06-24 21:56:24 +00008818
8819 " display subtrees (if any)
Bram Moolenaar8d043172014-01-23 14:24:41 +01008820 let depth= s:treedepthstring.a:depth
Bram Moolenaar446cb832008-06-24 21:56:24 +00008821
Bram Moolenaar85850f32019-07-19 22:05:51 +02008822 " implement g:netrw_hide for tree listings (uses g:netrw_list_hide)
8823 if g:netrw_hide == 1
8824 " hide given patterns
8825 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008826 for pat in listhide
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02008827 call filter(w:netrw_treedict[dir],'v:val !~ "'.escape(pat,'\\').'"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008828 endfor
8829
8830 elseif g:netrw_hide == 2
8831 " show given patterns (only)
8832 let listhide= split(g:netrw_list_hide,',')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008833 let entries=[]
8834 for entry in w:netrw_treedict[dir]
8835 for pat in listhide
8836 if entry =~ pat
8837 call add(entries,entry)
8838 break
8839 endif
8840 endfor
8841 endfor
8842 let w:netrw_treedict[dir]= entries
8843 endif
8844 if depth != ""
8845 " always remove "." and ".." entries when there's depth
8846 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008847 call filter(w:netrw_treedict[dir],'v:val !~ "\\.\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008848 call filter(w:netrw_treedict[dir],'v:val !~ "\\.$"')
Tom Benham64a536d2024-11-07 21:15:03 +01008849 call filter(w:netrw_treedict[dir],'v:val !~ "\\./$"')
Bram Moolenaar85850f32019-07-19 22:05:51 +02008850 endif
8851
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008852 for entry in w:netrw_treedict[dir]
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008853 if dir =~ '/$'
8854 let direntry= substitute(dir.entry,'[@/]$','','e')
8855 else
8856 let direntry= substitute(dir.'/'.entry,'[@/]$','','e')
8857 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008858 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008859 NetrwKeepj call s:NetrwTreeDisplay(direntry,depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008860 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008861 NetrwKeepj call s:NetrwTreeDisplay(direntry.'/',depth)
8862 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Tom Benham64a536d2024-11-07 21:15:03 +01008863 NetrwKeepj call s:NetrwTreeDisplay(direntry.'@',depth)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008864 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008865 sil! NetrwKeepj call setline(line("$")+1,depth.entry)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008866 endif
8867 endfor
Bram Moolenaar446cb832008-06-24 21:56:24 +00008868endfun
8869
8870" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008871" s:NetrwRefreshTreeDict: updates the contents information for a tree (w:netrw_treedict) {{{2
8872fun! s:NetrwRefreshTreeDict(dir)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008873 if !exists("w:netrw_treedict")
Bram Moolenaar85850f32019-07-19 22:05:51 +02008874 return
8875 endif
8876
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008877 for entry in w:netrw_treedict[a:dir]
8878 let direntry= substitute(a:dir.'/'.entry,'[@/]$','','e')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008879
8880 if entry =~ '/$' && has_key(w:netrw_treedict,direntry)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008881 NetrwKeepj call s:NetrwRefreshTreeDict(direntry)
Tom Benham64a536d2024-11-07 21:15:03 +01008882 let filelist = s:NetrwLocalListingList(direntry,0)
8883 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008884
8885 elseif entry =~ '/$' && has_key(w:netrw_treedict,direntry.'/')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008886 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Tom Benham64a536d2024-11-07 21:15:03 +01008887 let filelist = s:NetrwLocalListingList(direntry.'/',0)
8888 let w:netrw_treedict[direntry] = sort(filelist)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008889
8890 elseif entry =~ '@$' && has_key(w:netrw_treedict,direntry.'@')
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008891 NetrwKeepj call s:NetrwRefreshTreeDict(direntry.'/')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02008892 let liststar = s:NetrwGlob(direntry.'/','*',1)
8893 let listdotstar= s:NetrwGlob(direntry.'/','.*',1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008894
8895 else
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008896 endif
8897 endfor
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008898endfun
8899
8900" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00008901" s:NetrwTreeListing: displays tree listing from treetop on down, using NetrwTreeDisplay() {{{2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008902" Called by s:PerformListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00008903fun! s:NetrwTreeListing(dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008904 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaar446cb832008-06-24 21:56:24 +00008905
8906 " update the treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008907 if !exists("w:netrw_treetop")
8908 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008909 let s:netrw_treetop= w:netrw_treetop
Tom Benham4d618002024-10-31 10:47:23 +01008910 " use \V in case the directory contains specials chars like '$' or '~'
8911 elseif (w:netrw_treetop =~ ('^'.'\V'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop))
8912 \ || a:dirname !~ ('^'.'\V'.w:netrw_treetop)
Bram Moolenaar446cb832008-06-24 21:56:24 +00008913 let w:netrw_treetop= a:dirname
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008914 let s:netrw_treetop= w:netrw_treetop
Bram Moolenaar446cb832008-06-24 21:56:24 +00008915 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +02008916 if exists("w:netrw_treetop")
8917 let s:netrw_treetop= w:netrw_treetop
8918 else
8919 let w:netrw_treetop= getcwd()
8920 let s:netrw_treetop= w:netrw_treetop
8921 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008922
Bram Moolenaar446cb832008-06-24 21:56:24 +00008923 if !exists("w:netrw_treedict")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008924 " insure that we have a treedict, albeit empty
Bram Moolenaar446cb832008-06-24 21:56:24 +00008925 let w:netrw_treedict= {}
8926 endif
8927
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008928 " update the dictionary for the current directory
Christian Brabandta063b222024-11-07 14:30:30 +01008929 exe "sil! NetrwKeepj keepp ".w:netrw_bannercnt.',$g@^\.\.\=/$@d _'
Bram Moolenaar446cb832008-06-24 21:56:24 +00008930 let w:netrw_treedict[a:dirname]= getline(w:netrw_bannercnt,line("$"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008931 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaar446cb832008-06-24 21:56:24 +00008932
8933 " if past banner, record word
8934 if exists("w:netrw_bannercnt") && line(".") > w:netrw_bannercnt
8935 let fname= expand("<cword>")
8936 else
8937 let fname= ""
8938 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00008939
8940 " display from treetop on down
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01008941 NetrwKeepj call s:NetrwTreeDisplay(w:netrw_treetop,"")
Bram Moolenaar8d043172014-01-23 14:24:41 +01008942
8943 " remove any blank line remaining as line#1 (happens in treelisting mode with banner suppressed)
8944 while getline(1) =~ '^\s*$' && byte2line(1) > 0
Bram Moolenaar8d043172014-01-23 14:24:41 +01008945 1d
8946 endwhile
8947
Bram Moolenaar13600302014-05-22 18:26:40 +02008948 exe "setl ".g:netrw_bufsettings
Bram Moolenaar446cb832008-06-24 21:56:24 +00008949
Bram Moolenaar5b435d62012-04-05 17:33:26 +02008950 return
Bram Moolenaar446cb832008-06-24 21:56:24 +00008951 endif
8952endfun
8953
8954" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +02008955" s:NetrwTreePath: returns path to current file/directory in tree listing {{{2
Bram Moolenaara6878372014-03-22 21:02:50 +01008956" Normally, treetop is w:netrw_treetop, but a
8957" user of the function ( netrw#SetTreetop() )
8958" wipes that out prior to calling this function
8959fun! s:NetrwTreePath(treetop)
Bram Moolenaar85850f32019-07-19 22:05:51 +02008960" call Dfunc("s:NetrwTreePath(treetop<".a:treetop.">) line#".line(".")."<".getline(".").">")
8961 if line(".") < w:netrw_bannercnt + 2
8962 let treedir= a:treetop
8963 if treedir !~ '/$'
8964 let treedir= treedir.'/'
8965 endif
8966" call Dret("s:NetrwTreePath ".treedir." : line#".line(".")." ≤ ".(w:netrw_bannercnt+2))
8967 return treedir
8968 endif
8969
Bram Moolenaare0fa3742016-02-20 15:47:01 +01008970 let svpos = winsaveview()
8971" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008972 let depth = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008973" call Decho("depth<".depth."> 1st subst",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008974 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008975" call Decho("depth<".depth."> 2nd subst (first depth removed)",'~'.expand("<slnum>"))
8976 let curline= getline('.')
8977" call Decho("curline<".curline.'>','~'.expand("<slnum>"))
8978 if curline =~ '/$'
8979" call Decho("extract tree directory from current line",'~'.expand("<slnum>"))
8980 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8981" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
8982 elseif curline =~ '@\s\+-->'
8983" call Decho("extract tree directory using symbolic link",'~'.expand("<slnum>"))
8984 let treedir= substitute(curline,'^\%('.s:treedepthstring.'\)*\([^'.s:treedepthstring.'].\{-}\)$','\1','e')
8985 let treedir= substitute(treedir,'@\s\+-->.*$','','e')
8986" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008987 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008988" call Decho("do not extract tree directory from current line and set treedir to empty",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008989 let treedir= ""
8990 endif
8991 " construct treedir by searching backwards at correct depth
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008992" call Decho("construct treedir by searching backwards for correct depth",'~'.expand("<slnum>"))
8993" call Decho("initial treedir<".treedir."> depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008994 while depth != "" && search('^'.depth.'[^'.s:treedepthstring.'].\{-}/$','bW')
8995 let dirname= substitute(getline('.'),'^\('.s:treedepthstring.'\)*','','e')
8996 let treedir= dirname.treedir
8997 let depth = substitute(depth,'^'.s:treedepthstring,'','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01008998" call Decho("constructing treedir<".treedir.">: dirname<".dirname."> while depth<".depth.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01008999 endwhile
Bram Moolenaar85850f32019-07-19 22:05:51 +02009000" call Decho("treedir#1<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009001 if a:treetop =~ '/$'
9002 let treedir= a:treetop.treedir
9003 else
9004 let treedir= a:treetop.'/'.treedir
9005 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009006" call Decho("treedir#2<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009007 let treedir= substitute(treedir,'//$','/','')
Bram Moolenaar85850f32019-07-19 22:05:51 +02009008" call Decho("treedir#3<".treedir.">",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009009" call Decho("restoring posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))"
9010 call winrestview(svpos)
Bram Moolenaara6878372014-03-22 21:02:50 +01009011" call Dret("s:NetrwTreePath <".treedir.">")
9012 return treedir
9013endfun
9014
9015" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009016" s:NetrwWideListing: {{{2
9017fun! s:NetrwWideListing()
9018
9019 if w:netrw_liststyle == s:WIDELIST
9020" call Dfunc("NetrwWideListing() w:netrw_liststyle=".w:netrw_liststyle.' fo='.&fo.' l:fo='.&l:fo)
9021 " look for longest filename (cpf=characters per filename)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009022 " cpf: characters per filename
9023 " fpl: filenames per line
9024 " fpc: filenames per column
Bram Moolenaarff034192013-04-24 18:51:19 +02009025 setl ma noro
Christian Brabandt62f7b552024-06-23 20:23:40 +02009026 let dict={}
9027 " save the unnamed register and register 0-9 and a
9028 let dict.a=[getreg('a'), getregtype('a')]
9029 for i in range(0, 9)
9030 let dict[i] = [getreg(i), getregtype(i)]
9031 endfor
9032 let dict.unnamed = [getreg(''), getregtype('')]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009033" call Decho("setl ma noro",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009034 let b:netrw_cpf= 0
9035 if line("$") >= w:netrw_bannercnt
Bram Moolenaar29634562020-01-09 21:46:04 +01009036 " determine the maximum filename size; use that to set cpf
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009037 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g/^./if virtcol("$") > b:netrw_cpf|let b:netrw_cpf= virtcol("$")|endif'
9038 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009039 else
Christian Brabandt62f7b552024-06-23 20:23:40 +02009040 " restore stored registers
9041 call s:RestoreRegister(dict)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009042" call Dret("NetrwWideListing")
9043 return
9044 endif
Bram Moolenaar29634562020-01-09 21:46:04 +01009045 " allow for two spaces to separate columns
Bram Moolenaar5c736222010-01-06 20:54:52 +01009046 let b:netrw_cpf= b:netrw_cpf + 2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009047" call Decho("b:netrw_cpf=max_filename_length+2=".b:netrw_cpf,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009048
9049 " determine qty files per line (fpl)
9050 let w:netrw_fpl= winwidth(0)/b:netrw_cpf
9051 if w:netrw_fpl <= 0
9052 let w:netrw_fpl= 1
9053 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009054" call Decho("fpl= [winwidth=".winwidth(0)."]/[b:netrw_cpf=".b:netrw_cpf.']='.w:netrw_fpl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009055
9056 " make wide display
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009057 " fpc: files per column of wide listing
9058 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^.*$/\=escape(printf("%-'.b:netrw_cpf.'S",submatch(0)),"\\")/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009059 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009060 let fpc = (line("$") - w:netrw_bannercnt + w:netrw_fpl)/w:netrw_fpl
9061 let newcolstart = w:netrw_bannercnt + fpc
9062 let newcolend = newcolstart + fpc - 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009063" call Decho("bannercnt=".w:netrw_bannercnt." fpl=".w:netrw_fpl." fpc=".fpc." newcol[".newcolstart.",".newcolend."]",'~'.expand("<slnum>"))
Bram Moolenaar89a9c152021-08-29 21:55:35 +02009064 if has("clipboard") && g:netrw_clipboard
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009065" call Decho("(s:NetrwWideListing) save @* and @+",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009066 sil! let keepregstar = @*
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009067 sil! let keepregplus = @+
Bram Moolenaara6878372014-03-22 21:02:50 +01009068 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009069 while line("$") >= newcolstart
9070 if newcolend > line("$") | let newcolend= line("$") | endif
9071 let newcolqty= newcolend - newcolstart
9072 exe newcolstart
Bram Moolenaar29634562020-01-09 21:46:04 +01009073 " COMBAK: both of the visual-mode using lines below are problematic vis-a-vis @*
Bram Moolenaar446cb832008-06-24 21:56:24 +00009074 if newcolqty == 0
Bram Moolenaar91359012019-11-30 17:57:03 +01009075 exe "sil! NetrwKeepj norm! 0\<c-v>$h\"ax".w:netrw_bannercnt."G$\"ap"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009076 else
Bram Moolenaar29634562020-01-09 21:46:04 +01009077 exe "sil! NetrwKeepj norm! 0\<c-v>".newcolqty.'j$h"ax'.w:netrw_bannercnt.'G$"ap'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009078 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009079 exe "sil! NetrwKeepj ".newcolstart.','.newcolend.'d _'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009080 exe 'sil! NetrwKeepj '.w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009081 endwhile
Bram Moolenaara6878372014-03-22 21:02:50 +01009082 if has("clipboard")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +01009083" call Decho("(s:NetrwWideListing) restore @* and @+",'~'.expand("<slnum>"))
Bram Moolenaar0c0734d2019-11-26 21:44:46 +01009084 if @* != keepregstar | sil! let @* = keepregstar | endif
9085 if @+ != keepregplus | sil! let @+ = keepregplus | endif
Bram Moolenaara6878372014-03-22 21:02:50 +01009086 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009087 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/\s\+$//e'
9088 NetrwKeepj call histdel("/",-1)
9089 exe 'nno <buffer> <silent> w :call search(''^.\\|\s\s\zs\S'',''W'')'."\<cr>"
9090 exe 'nno <buffer> <silent> b :call search(''^.\\|\s\s\zs\S'',''bW'')'."\<cr>"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009091" call Decho("NetrwWideListing) setl noma nomod ro",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +02009092 exe "setl ".g:netrw_bufsettings
Christian Brabandt62f7b552024-06-23 20:23:40 +02009093 call s:RestoreRegister(dict)
Bram Moolenaar85850f32019-07-19 22:05:51 +02009094" 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 +00009095" call Dret("NetrwWideListing")
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009096 return
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009097 else
9098 if hasmapto("w","n")
9099 sil! nunmap <buffer> w
9100 endif
9101 if hasmapto("b","n")
9102 sil! nunmap <buffer> b
9103 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009104 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009105endfun
9106
9107" ---------------------------------------------------------------------
9108" s:PerformListing: {{{2
9109fun! s:PerformListing(islocal)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009110" call Dfunc("s:PerformListing(islocal=".a:islocal.")")
9111" 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 +02009112" 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>"))
9113 sil! NetrwKeepj %d _
9114" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009115
Bram Moolenaar15146672011-10-20 22:22:38 +02009116 " set up syntax highlighting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009117" call Decho("--set up syntax highlighting (ie. setl ft=netrw)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009118 sil! setl ft=netrw
Bram Moolenaar15146672011-10-20 22:22:38 +02009119
Bram Moolenaar85850f32019-07-19 22:05:51 +02009120 NetrwKeepj call s:NetrwOptionsSafe(a:islocal)
Bram Moolenaara6878372014-03-22 21:02:50 +01009121 setl noro ma
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009122" call Decho("setl noro ma bh=".&bh,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009123
9124" if exists("g:netrw_silent") && g:netrw_silent == 0 && &ch >= 1 " Decho
Bram Moolenaar85850f32019-07-19 22:05:51 +02009125" call Decho("Processing your browsing request...",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009126" endif " Decho
9127
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009128" call Decho('w:netrw_liststyle='.(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009129 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict")
9130 " force a refresh for tree listings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009131" call Decho("force refresh for treelisting: clear buffer<".expand("%")."> with :%d",'~'.expand("<slnum>"))
9132 sil! NetrwKeepj %d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009133 endif
9134
9135 " save current directory on directory history list
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009136 NetrwKeepj call s:NetrwBookHistHandler(3,b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009137
9138 " Set up the banner {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009139 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009140" call Decho("--set up banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009141 NetrwKeepj call setline(1,'" ============================================================================')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009142 if exists("g:netrw_pchk")
9143 " this undocumented option allows pchk to run with different versions of netrw without causing spurious
9144 " failure detections.
9145 NetrwKeepj call setline(2,'" Netrw Directory Listing')
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009146 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009147 NetrwKeepj call setline(2,'" Netrw Directory Listing (netrw '.g:loaded_netrw.')')
9148 endif
9149 if exists("g:netrw_pchk")
9150 let curdir= substitute(b:netrw_curdir,expand("$HOME"),'~','')
9151 else
9152 let curdir= b:netrw_curdir
9153 endif
9154 if exists("g:netrw_bannerbackslash") && g:netrw_bannerbackslash
9155 NetrwKeepj call setline(3,'" '.substitute(curdir,'/','\\','g'))
9156 else
9157 NetrwKeepj call setline(3,'" '.curdir)
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009158 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009159 let w:netrw_bannercnt= 3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009160 NetrwKeepj exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009161 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009162" call Decho("--no banner",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009163 NetrwKeepj 1
Bram Moolenaar5c736222010-01-06 20:54:52 +01009164 let w:netrw_bannercnt= 1
9165 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009166" call Decho("w:netrw_bannercnt=".w:netrw_bannercnt." win#".winnr(),'~'.expand("<slnum>"))
9167" 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 +00009168
Bram Moolenaar85850f32019-07-19 22:05:51 +02009169 " construct sortby string: [name|time|size|exten] [reversed]
Bram Moolenaar446cb832008-06-24 21:56:24 +00009170 let sortby= g:netrw_sort_by
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009171 if g:netrw_sort_direction =~# "^r"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009172 let sortby= sortby." reversed"
9173 endif
9174
9175 " Sorted by... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009176 if g:netrw_banner
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009177" call Decho("--handle specified sorting: g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009178 if g:netrw_sort_by =~# "^n"
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009179" call Decho("directories will be sorted by name",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009180 " sorted by name (also includes the sorting sequence in the banner)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009181 NetrwKeepj put ='\" Sorted by '.sortby
9182 NetrwKeepj put ='\" Sort sequence: '.g:netrw_sort_sequence
Bram Moolenaar5c736222010-01-06 20:54:52 +01009183 let w:netrw_bannercnt= w:netrw_bannercnt + 2
9184 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009185" call Decho("directories will be sorted by size or time",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009186 " sorted by time, size, exten
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009187 NetrwKeepj put ='\" Sorted by '.sortby
Bram Moolenaar5c736222010-01-06 20:54:52 +01009188 let w:netrw_bannercnt= w:netrw_bannercnt + 1
9189 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009190 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar8d043172014-01-23 14:24:41 +01009191" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009192" 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 +00009193 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009194
Bram Moolenaar85850f32019-07-19 22:05:51 +02009195 " show copy/move target, if any {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009196 if g:netrw_banner
9197 if exists("s:netrwmftgt") && exists("s:netrwmftgt_islocal")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009198" call Decho("--show copy/move target<".s:netrwmftgt.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009199 NetrwKeepj put =''
Bram Moolenaar5c736222010-01-06 20:54:52 +01009200 if s:netrwmftgt_islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009201 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (local)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009202 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009203 sil! NetrwKeepj call setline(line("."),'" Copy/Move Tgt: '.s:netrwmftgt.' (remote)')
Bram Moolenaar5c736222010-01-06 20:54:52 +01009204 endif
9205 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009206 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009207" call Decho("s:netrwmftgt does not exist, don't make Copy/Move Tgt",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009208 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009209 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009210 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009211
9212 " Hiding... -or- Showing... {{{3
Bram Moolenaar5c736222010-01-06 20:54:52 +01009213 if g:netrw_banner
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009214" 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 +01009215 if g:netrw_list_hide != "" && g:netrw_hide
9216 if g:netrw_hide == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009217 NetrwKeepj put ='\" Hiding: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009218 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009219 NetrwKeepj put ='\" Showing: '.g:netrw_list_hide
Bram Moolenaar5c736222010-01-06 20:54:52 +01009220 endif
9221 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009222 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009223 exe "NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009224
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009225" 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 +01009226 let quickhelp = g:netrw_quickhelp%len(s:QuickHelp)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009227" call Decho("quickhelp =".quickhelp,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009228 NetrwKeepj put ='\" Quick Help: <F1>:help '.s:QuickHelp[quickhelp]
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009229" 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 +01009230 NetrwKeepj put ='\" =============================================================================='
Bram Moolenaar5c736222010-01-06 20:54:52 +01009231 let w:netrw_bannercnt= w:netrw_bannercnt + 2
Bram Moolenaar8d043172014-01-23 14:24:41 +01009232" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009233" 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 +00009234 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009235
9236 " bannercnt should index the line just after the banner
Bram Moolenaar5c736222010-01-06 20:54:52 +01009237 if g:netrw_banner
9238 let w:netrw_bannercnt= w:netrw_bannercnt + 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009239 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009240" 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 +01009241" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009242" 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 +01009243 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009244
Bram Moolenaar446cb832008-06-24 21:56:24 +00009245 " get list of files
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009246" call Decho("--Get list of files - islocal=".a:islocal,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009247 if a:islocal
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009248 NetrwKeepj call s:LocalListing()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009249 else " remote
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009250 NetrwKeepj let badresult= s:NetrwRemoteListing()
Bram Moolenaara6878372014-03-22 21:02:50 +01009251 if badresult
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009252" 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 +01009253" call Dret("s:PerformListing : error detected by NetrwRemoteListing")
9254 return
9255 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009256 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009257
9258 " manipulate the directory listing (hide, sort) {{{3
Bram Moolenaar5b435d62012-04-05 17:33:26 +02009259 if !exists("w:netrw_bannercnt")
9260 let w:netrw_bannercnt= 0
9261 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009262" call Decho("--manipulate directory listing (hide, sort)",'~'.expand("<slnum>"))
9263" call Decho("g:netrw_banner=".g:netrw_banner." w:netrw_bannercnt=".w:netrw_bannercnt." (banner complete)",'~'.expand("<slnum>"))
9264" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009265
Bram Moolenaar5c736222010-01-06 20:54:52 +01009266 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaar1d59aa12020-09-19 18:50:13 +02009267" call Decho("manipulate directory listing (support hide)",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009268" 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 +00009269 if g:netrw_hide && g:netrw_list_hide != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009270 NetrwKeepj call s:NetrwListHide()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009271 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +01009272 if !g:netrw_banner || line("$") >= w:netrw_bannercnt
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009273" call Decho("manipulate directory listing (sort) : g:netrw_sort_by<".g:netrw_sort_by.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009274
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009275 if g:netrw_sort_by =~# "^n"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009276 " sort by name
Bram Moolenaar85850f32019-07-19 22:05:51 +02009277" call Decho("sort by name",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009278 NetrwKeepj call s:NetrwSetSort()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009279
Bram Moolenaar5c736222010-01-06 20:54:52 +01009280 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009281" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009282 if g:netrw_sort_direction =~# 'n'
Bram Moolenaar85850f32019-07-19 22:05:51 +02009283 " name: sort by name of file
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009284 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009285 else
9286 " reverse direction sorting
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009287 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009288 endif
9289 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009290
Bram Moolenaar446cb832008-06-24 21:56:24 +00009291 " remove priority pattern prefix
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009292" call Decho("remove priority pattern prefix",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009293 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{3}'.g:netrw_sepchr.'//e'
9294 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009295
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009296 elseif g:netrw_sort_by =~# "^ext"
Bram Moolenaar85850f32019-07-19 22:05:51 +02009297 " exten: sort by extension
9298 " The histdel(...,-1) calls remove the last search from the search history
9299" call Decho("sort by extension",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009300 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$g+/+s/^/001'.g:netrw_sepchr.'/'
9301 NetrwKeepj call histdel("/",-1)
9302 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+[./]+s/^/002'.g:netrw_sepchr.'/'
9303 NetrwKeepj call histdel("/",-1)
9304 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$v+['.g:netrw_sepchr.'/]+s/^\(.*\.\)\(.\{-\}\)$/\2'.g:netrw_sepchr.'&/e'
9305 NetrwKeepj call histdel("/",-1)
9306 if !g:netrw_banner || w:netrw_bannercnt < line("$")
9307" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction." (bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009308 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009309 " normal direction sorting
9310 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
9311 else
9312 " reverse direction sorting
9313 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
9314 endif
9315 endif
9316 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^.\{-}'.g:netrw_sepchr.'//e'
9317 NetrwKeepj call histdel("/",-1)
9318
Bram Moolenaar446cb832008-06-24 21:56:24 +00009319 elseif a:islocal
Bram Moolenaar5c736222010-01-06 20:54:52 +01009320 if !g:netrw_banner || w:netrw_bannercnt < line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009321" call Decho("g:netrw_sort_direction=".g:netrw_sort_direction,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009322 if g:netrw_sort_direction =~# 'n'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009323" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009324 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009325 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009326" call Decho('exe sil NetrwKeepj '.w:netrw_bannercnt.',$sort!','~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009327 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$sort!'.' '.g:netrw_sort_options
Bram Moolenaar446cb832008-06-24 21:56:24 +00009328 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009329" call Decho("remove leading digits/ (sorting) information from listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009330 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{-}\///e'
9331 NetrwKeepj call histdel("/",-1)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009332 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009333 endif
9334
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009335 elseif g:netrw_sort_direction =~# 'r'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009336" call Decho('(s:PerformListing) reverse the sorted listing','~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +01009337 if !g:netrw_banner || w:netrw_bannercnt < line('$')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009338 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$g/^/m '.w:netrw_bannercnt
Bram Moolenaar5c736222010-01-06 20:54:52 +01009339 call histdel("/",-1)
9340 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009341 endif
9342 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009343" 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 +00009344
9345 " convert to wide/tree listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009346" call Decho("--modify display if wide/tree listing style",'~'.expand("<slnum>"))
9347" 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 +01009348 NetrwKeepj call s:NetrwWideListing()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009349" 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 +01009350 NetrwKeepj call s:NetrwTreeListing(b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009351" 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 +00009352
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009353 " resolve symbolic links if local and (thin or tree)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009354 if a:islocal && (w:netrw_liststyle == s:THINLIST || (exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST))
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009355" call Decho("--resolve symbolic links if local and thin|tree",'~'.expand("<slnum>"))
Christian Brabandta063b222024-11-07 14:30:30 +01009356 sil! keepp g/@$/call s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009357 endif
9358
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009359 if exists("w:netrw_bannercnt") && (line("$") >= w:netrw_bannercnt || !g:netrw_banner)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009360 " place cursor on the top-left corner of the file listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009361" call Decho("--place cursor on top-left corner of file listing",'~'.expand("<slnum>"))
9362 exe 'sil! '.w:netrw_bannercnt
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009363 sil! NetrwKeepj norm! 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009364" call Decho(" tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol()." line($)=".line("$"),'~'.expand("<slnum>"))
9365 else
9366" call Decho("--did NOT place cursor on top-left corner",'~'.expand("<slnum>"))
9367" call Decho(" w:netrw_bannercnt=".(exists("w:netrw_bannercnt")? w:netrw_bannercnt : 'n/a'),'~'.expand("<slnum>"))
9368" call Decho(" line($)=".line("$"),'~'.expand("<slnum>"))
9369" call Decho(" g:netrw_banner=".(exists("g:netrw_banner")? g:netrw_banner : 'n/a'),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009370 endif
9371
9372 " record previous current directory
9373 let w:netrw_prvdir= b:netrw_curdir
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009374" call Decho("--record netrw_prvdir<".w:netrw_prvdir.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009375
9376 " save certain window-oriented variables into buffer-oriented variables {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009377" call Decho("--save some window-oriented variables into buffer oriented variables",'~'.expand("<slnum>"))
9378" 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 +01009379 NetrwKeepj call s:SetBufWinVars()
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009380" 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 +02009381 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009382" 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 +00009383
9384 " set display to netrw display settings
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009385" call Decho("--set display to netrw display settings (".g:netrw_bufsettings.")",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +02009386 exe "setl ".g:netrw_bufsettings
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#7)",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009388 if g:netrw_liststyle == s:LONGLIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009389" call Decho("exe setl ts=".(g:netrw_maxfilenamelen+1),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +01009390 exe "setl ts=".(g:netrw_maxfilenamelen+1)
9391 endif
Bram Moolenaar91359012019-11-30 17:57:03 +01009392" call Decho("PerformListing buffer:",'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +02009393" call DechoBuf(bufnr("%"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009394
Bram Moolenaar8d043172014-01-23 14:24:41 +01009395 if exists("s:treecurpos")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009396" call Decho("s:treecurpos exists; restore posn",'~'.expand("<slnum>"))
9397" 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 +01009398" call Decho("restoring posn to s:treecurpos<".string(s:treecurpos).">",'~'.expand("<slnum>"))
9399 NetrwKeepj call winrestview(s:treecurpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009400 unlet s:treecurpos
9401 endif
9402
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009403" 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>"))
9404" 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 +00009405" call Dret("s:PerformListing : curpos<".string(getpos(".")).">")
9406endfun
9407
9408" ---------------------------------------------------------------------
9409" s:SetupNetrwStatusLine: {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +00009410fun! s:SetupNetrwStatusLine(statline)
9411" call Dfunc("SetupNetrwStatusLine(statline<".a:statline.">)")
9412
9413 if !exists("s:netrw_setup_statline")
9414 let s:netrw_setup_statline= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009415" call Decho("do first-time status line setup",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +00009416
9417 if !exists("s:netrw_users_stl")
9418 let s:netrw_users_stl= &stl
9419 endif
9420 if !exists("s:netrw_users_ls")
9421 let s:netrw_users_ls= &laststatus
9422 endif
9423
9424 " set up User9 highlighting as needed
Christian Brabandt62f7b552024-06-23 20:23:40 +02009425 let dict={}
9426 let dict.a=[getreg('a'), getregtype('a')]
Bram Moolenaar9964e462007-05-05 17:54:07 +00009427 redir @a
9428 try
9429 hi User9
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009430 catch /^Vim\%((\a\{3,})\)\=:E411/
Bram Moolenaar9964e462007-05-05 17:54:07 +00009431 if &bg == "dark"
9432 hi User9 ctermfg=yellow ctermbg=blue guifg=yellow guibg=blue
9433 else
9434 hi User9 ctermbg=yellow ctermfg=blue guibg=yellow guifg=blue
9435 endif
9436 endtry
9437 redir END
Christian Brabandt62f7b552024-06-23 20:23:40 +02009438 call s:RestoreRegister(dict)
Bram Moolenaar9964e462007-05-05 17:54:07 +00009439 endif
9440
9441 " set up status line (may use User9 highlighting)
9442 " insure that windows have a statusline
9443 " make sure statusline is displayed
K.Takataa262d3f2024-01-25 04:10:19 +09009444 let &l:stl=a:statline
Bram Moolenaarff034192013-04-24 18:51:19 +02009445 setl laststatus=2
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009446" call Decho("stl=".&stl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009447 redraw
Bram Moolenaar9964e462007-05-05 17:54:07 +00009448
9449" call Dret("SetupNetrwStatusLine : stl=".&stl)
9450endfun
9451
Bram Moolenaar85850f32019-07-19 22:05:51 +02009452" =========================================
9453" Remote Directory Browsing Support: {{{1
9454" =========================================
Bram Moolenaar9964e462007-05-05 17:54:07 +00009455
9456" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +01009457" s:NetrwRemoteFtpCmd: unfortunately, not all ftp servers honor options for ls {{{2
9458" This function assumes that a long listing will be received. Size, time,
9459" and reverse sorts will be requested of the server but not otherwise
9460" enforced here.
9461fun! s:NetrwRemoteFtpCmd(path,listcmd)
9462" 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 +01009463" call Decho("line($)=".line("$")." win#".winnr()." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009464 " sanity check: {{{3
9465 if !exists("w:netrw_method")
9466 if exists("b:netrw_method")
9467 let w:netrw_method= b:netrw_method
9468 else
9469 call netrw#ErrorMsg(2,"(s:NetrwRemoteFtpCmd) internal netrw error",93)
9470" call Dret("NetrwRemoteFtpCmd")
9471 return
9472 endif
9473 endif
9474
9475 " WinXX ftp uses unix style input, so set ff to unix " {{{3
9476 let ffkeep= &ff
9477 setl ma ff=unix noro
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009478" call Decho("setl ma ff=unix noro",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009479
9480 " clear off any older non-banner lines " {{{3
9481 " note that w:netrw_bannercnt indexes the line after the banner
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009482" call Decho('exe sil! NetrwKeepj '.w:netrw_bannercnt.",$d _ (clear off old non-banner lines)",'~'.expand("<slnum>"))
9483 exe "sil! NetrwKeepj ".w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009484
9485 ".........................................
9486 if w:netrw_method == 2 || w:netrw_method == 5 " {{{3
9487 " ftp + <.netrc>: Method #2
9488 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009489 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009490 endif
9491 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009492 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009493" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009494 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009495 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009496" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaara6878372014-03-22 21:02:50 +01009497 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009498" 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>"))
9499 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 +01009500 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009501" call Decho("exe ".s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." -i ".s:ShellEscape(g:netrw_machine,1),'~'.expand("<slnum>"))
9502 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 +01009503 endif
9504
9505 ".........................................
9506 elseif w:netrw_method == 3 " {{{3
9507 " ftp + machine,id,passwd,filename: Method #3
9508 setl ff=unix
9509 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009510 NetrwKeepj put ='open '.g:netrw_machine.' '.g:netrw_port
Bram Moolenaara6878372014-03-22 21:02:50 +01009511 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009512 NetrwKeepj put ='open '.g:netrw_machine
Bram Moolenaara6878372014-03-22 21:02:50 +01009513 endif
9514
9515 " handle userid and password
9516 let host= substitute(g:netrw_machine,'\..*$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009517" call Decho("host<".host.">",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009518 if exists("s:netrw_hup") && exists("s:netrw_hup[host]")
9519 call NetUserPass("ftp:".host)
9520 endif
9521 if exists("g:netrw_uid") && g:netrw_uid != ""
9522 if exists("g:netrw_ftp") && g:netrw_ftp == 1
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009523 NetrwKeepj put =g:netrw_uid
Bram Moolenaara6878372014-03-22 21:02:50 +01009524 if exists("s:netrw_passwd") && s:netrw_passwd != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009525 NetrwKeepj put ='\"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009526 endif
9527 elseif exists("s:netrw_passwd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009528 NetrwKeepj put ='user \"'.g:netrw_uid.'\" \"'.s:netrw_passwd.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009529 endif
9530 endif
9531
9532 if a:path != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009533 NetrwKeepj put ='cd \"'.a:path.'\"'
Bram Moolenaara6878372014-03-22 21:02:50 +01009534 endif
9535 if exists("g:netrw_ftpextracmd")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009536 NetrwKeepj put =g:netrw_ftpextracmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009537" call Decho("filter input: ".getline('.'),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009538 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009539 NetrwKeepj call setline(line("$")+1,a:listcmd)
Bram Moolenaara6878372014-03-22 21:02:50 +01009540
9541 " perform ftp:
9542 " -i : turns off interactive prompting from ftp
9543 " -n unix : DON'T use <.netrc>, even though it exists
9544 " -n win32: quit being obnoxious about password
9545 if exists("w:netrw_bannercnt")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009546" exe w:netrw_bannercnt.',$g/^./call Decho("ftp#".line(".").": ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009547 call s:NetrwExe(s:netrw_silentxfer.w:netrw_bannercnt.",$!".s:netrw_ftp_cmd." ".g:netrw_ftp_options)
Bram Moolenaara6878372014-03-22 21:02:50 +01009548" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009549" call Decho("WARNING: w:netrw_bannercnt doesn't exist!",'~'.expand("<slnum>"))
9550" g/^./call Decho("SKIPPING ftp#".line(".").": ".getline("."),'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +01009551 endif
9552
9553 ".........................................
9554 elseif w:netrw_method == 9 " {{{3
9555 " sftp username@machine: Method #9
9556 " s:netrw_sftp_cmd
9557 setl ff=unix
9558
9559 " restore settings
K.Takataa262d3f2024-01-25 04:10:19 +09009560 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009561" call Dret("NetrwRemoteFtpCmd")
9562 return
9563
9564 ".........................................
9565 else " {{{3
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009566 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"unable to comply with your request<" . bufname("%") . ">",23)
Bram Moolenaara6878372014-03-22 21:02:50 +01009567 endif
9568
9569 " cleanup for Windows " {{{3
Nir Lichtman1e34b952024-05-08 19:19:34 +02009570 if has("win32")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009571 sil! NetrwKeepj %s/\r$//e
9572 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009573 endif
9574 if a:listcmd == "dir"
9575 " infer directory/link based on the file permission string
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009576 sil! NetrwKeepj g/d\%([-r][-w][-x]\)\{3}/NetrwKeepj s@$@/@e
9577 sil! NetrwKeepj g/l\%([-r][-w][-x]\)\{3}/NetrwKeepj s/$/@/e
9578 NetrwKeepj call histdel("/",-1)
9579 NetrwKeepj call histdel("/",-1)
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009580 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 +01009581 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$s/^\%(\S\+\s\+\)\{8}//e'
9582 NetrwKeepj call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +01009583 endif
9584 endif
9585
9586 " ftp's listing doesn't seem to include ./ or ../ " {{{3
9587 if !search('^\.\/$\|\s\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009588 exe 'NetrwKeepj '.w:netrw_bannercnt
9589 NetrwKeepj put ='./'
Bram Moolenaara6878372014-03-22 21:02:50 +01009590 endif
9591 if !search('^\.\.\/$\|\s\.\.\/$','wn')
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009592 exe 'NetrwKeepj '.w:netrw_bannercnt
9593 NetrwKeepj put ='../'
Bram Moolenaara6878372014-03-22 21:02:50 +01009594 endif
9595
9596 " restore settings " {{{3
K.Takataa262d3f2024-01-25 04:10:19 +09009597 let &l:ff= ffkeep
Bram Moolenaara6878372014-03-22 21:02:50 +01009598" call Dret("NetrwRemoteFtpCmd")
9599endfun
9600
9601" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009602" s:NetrwRemoteListing: {{{2
9603fun! s:NetrwRemoteListing()
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009604" call Dfunc("s:NetrwRemoteListing() b:netrw_curdir<".b:netrw_curdir.">) win#".winnr())
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00009605
Bram Moolenaara6878372014-03-22 21:02:50 +01009606 if !exists("w:netrw_bannercnt") && exists("s:bannercnt")
9607 let w:netrw_bannercnt= s:bannercnt
9608 endif
9609 if !exists("w:netrw_bannercnt") && exists("b:bannercnt")
KSR-Yasudab52e7ac2023-12-12 01:11:43 +09009610 let w:netrw_bannercnt= b:bannercnt
Bram Moolenaara6878372014-03-22 21:02:50 +01009611 endif
9612
Bram Moolenaar446cb832008-06-24 21:56:24 +00009613 call s:RemotePathAnalysis(b:netrw_curdir)
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009614
Bram Moolenaar446cb832008-06-24 21:56:24 +00009615 " sanity check:
9616 if exists("b:netrw_method") && b:netrw_method =~ '[235]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009617" call Decho("b:netrw_method=".b:netrw_method,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009618 if !executable("ftp")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009619" call Decho("ftp is not executable",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009620 if !exists("g:netrw_quiet")
9621 call netrw#ErrorMsg(s:ERROR,"this system doesn't support remote directory listing via ftp",18)
9622 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009623 call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009624" call Dret("s:NetrwRemoteListing -1")
9625 return -1
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00009626 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +00009627
Bram Moolenaar8d043172014-01-23 14:24:41 +01009628 elseif !exists("g:netrw_list_cmd") || g:netrw_list_cmd == ''
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009629" call Decho("g:netrw_list_cmd<",(exists("g:netrw_list_cmd")? 'n/a' : "-empty-").">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009630 if !exists("g:netrw_quiet")
Bram Moolenaar8d043172014-01-23 14:24:41 +01009631 if g:netrw_list_cmd == ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009632 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 +00009633 else
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009634 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 +00009635 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009636 endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009637
Bram Moolenaar85850f32019-07-19 22:05:51 +02009638 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009639" call Dret("s:NetrwRemoteListing -1")
9640 return -1
Bram Moolenaar446cb832008-06-24 21:56:24 +00009641 endif " (remote handling sanity check)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009642" call Decho("passed remote listing sanity checks",'~'.expand("<slnum>"))
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009643
Bram Moolenaar446cb832008-06-24 21:56:24 +00009644 if exists("b:netrw_method")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009645" call Decho("setting w:netrw_method to b:netrw_method<".b:netrw_method.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009646 let w:netrw_method= b:netrw_method
9647 endif
9648
Bram Moolenaar13600302014-05-22 18:26:40 +02009649 if s:method == "ftp"
Bram Moolenaaradc21822011-04-01 18:03:16 +02009650 " use ftp to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009651" call Decho("use ftp to get remote file listing",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +01009652 let s:method = "ftp"
9653 let listcmd = g:netrw_ftp_list_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009654 if g:netrw_sort_by =~# '^t'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009655 let listcmd= g:netrw_ftp_timelist_cmd
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009656 elseif g:netrw_sort_by =~# '^s'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009657 let listcmd= g:netrw_ftp_sizelist_cmd
9658 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009659" call Decho("listcmd<".listcmd."> (using g:netrw_ftp_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009660 call s:NetrwRemoteFtpCmd(s:path,listcmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009661" exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("raw listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009662
Bram Moolenaara6878372014-03-22 21:02:50 +01009663 " report on missing file or directory messages
9664 if search('[Nn]o such file or directory\|Failed to change directory')
9665 let mesg= getline(".")
9666 if exists("w:netrw_bannercnt")
9667 setl ma
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009668 exe w:netrw_bannercnt.",$d _"
Bram Moolenaara6878372014-03-22 21:02:50 +01009669 setl noma
9670 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +02009671 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaara6878372014-03-22 21:02:50 +01009672 call netrw#ErrorMsg(s:WARNING,mesg,96)
9673" call Dret("s:NetrwRemoteListing : -1")
9674 return -1
9675 endif
9676
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009677 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 +00009678 " shorten the listing
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009679" call Decho("generate short listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009680 exe "sil! keepalt NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar446cb832008-06-24 21:56:24 +00009681
9682 " cleanup
9683 if g:netrw_ftp_browse_reject != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009684 exe "sil! keepalt NetrwKeepj g/".g:netrw_ftp_browse_reject."/NetrwKeepj d"
9685 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009686 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009687 sil! NetrwKeepj %s/\r$//e
9688 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009689
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009690 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009691 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009692 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaar97d62492012-11-15 21:28:22 +01009693 let line2= search('\.\.\/\%(\s\|$\)','cnW')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009694" call Decho("search(".'\.\.\/\%(\s\|$\)'."','cnW')=".line2." w:netrw_bannercnt=".w:netrw_bannercnt,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009695 if line2 == 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009696" call Decho("netrw is putting ../ into listing",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009697 sil! NetrwKeepj put='../'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009698 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009699 exe "sil! NetrwKeepj ".line1
9700 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009701
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009702" call Decho("line1=".line1." line2=".line2." line(.)=".line("."),'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009703 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009704" call Decho("M$ ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009705 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\d\{2}-\d\{2}-\d\{2}\s\+\d\+:\d\+[AaPp][Mm]\s\+\%(<DIR>\|\d\+\)\s\+//'
9706 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009707 else " normal ftp cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009708" call Decho("normal ftp cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009709 exe 'sil! NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2/e'
9710 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*/$#/#e'
9711 exe "sil! NetrwKeepj ".w:netrw_bannercnt.',$g/ -> /s# -> .*$#/#e'
9712 NetrwKeepj call histdel("/",-1)
9713 NetrwKeepj call histdel("/",-1)
9714 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009715 endif
9716 endif
9717
Bram Moolenaar13600302014-05-22 18:26:40 +02009718 else
Bram Moolenaar446cb832008-06-24 21:56:24 +00009719 " use ssh to get remote file listing {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009720" call Decho("use ssh to get remote file listing: s:path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009721 let listcmd= s:MakeSshCmd(g:netrw_list_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009722" call Decho("listcmd<".listcmd."> (using g:netrw_list_cmd)",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009723 if g:netrw_scp_cmd =~ '^pscp'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009724" call Decho("1: exe r! ".s:ShellEscape(listcmd.s:path, 1),'~'.expand("<slnum>"))
9725 exe "NetrwKeepj r! ".listcmd.s:ShellEscape(s:path, 1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009726 " remove rubbish and adjust listing format of 'pscp' to 'ssh ls -FLa' like
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009727 sil! NetrwKeepj g/^Listing directory/NetrwKeepj d
9728 sil! NetrwKeepj g/^d[-rwx][-rwx][-rwx]/NetrwKeepj s+$+/+e
9729 sil! NetrwKeepj g/^l[-rwx][-rwx][-rwx]/NetrwKeepj s+$+@+e
9730 NetrwKeepj call histdel("/",-1)
9731 NetrwKeepj call histdel("/",-1)
9732 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009733 if g:netrw_liststyle != s:LONGLIST
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009734 sil! NetrwKeepj g/^[dlsp-][-rwx][-rwx][-rwx]/NetrwKeepj s/^.*\s\(\S\+\)$/\1/e
9735 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009736 endif
9737 else
9738 if s:path == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009739" call Decho("2: exe r! ".listcmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009740 exe "NetrwKeepj keepalt r! ".listcmd
Bram Moolenaar446cb832008-06-24 21:56:24 +00009741 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009742" call Decho("3: exe r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1),'~'.expand("<slnum>"))
9743 exe "NetrwKeepj keepalt r! ".listcmd.' '.s:ShellEscape(fnameescape(s:path),1)
9744" call Decho("listcmd<".listcmd."> path<".s:path.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009745 endif
9746 endif
9747
9748 " cleanup
Bram Moolenaara6878372014-03-22 21:02:50 +01009749 if g:netrw_ssh_browse_reject != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009750" call Decho("cleanup: exe sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009751 exe "sil! g/".g:netrw_ssh_browse_reject."/NetrwKeepj d"
9752 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009753 endif
9754 endif
9755
9756 if w:netrw_liststyle == s:LONGLIST
9757 " do a long listing; these substitutions need to be done prior to sorting {{{3
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009758" call Decho("fix long listing:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009759
9760 if s:method == "ftp"
9761 " cleanup
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009762 exe "sil! NetrwKeepj ".w:netrw_bannercnt
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009763 while getline('.') =~# g:netrw_ftp_browse_reject
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009764 sil! NetrwKeepj d
Bram Moolenaar446cb832008-06-24 21:56:24 +00009765 endwhile
Bram Moolenaare6ae6222013-05-21 21:01:10 +02009766 " if there's no ../ listed, then put ../ in
Bram Moolenaar446cb832008-06-24 21:56:24 +00009767 let line1= line(".")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009768 sil! NetrwKeepj 1
9769 sil! NetrwKeepj call search('^\.\.\/\%(\s\|$\)','W')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009770 let line2= line(".")
9771 if line2 == 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009772 if b:netrw_curdir != '/'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009773 exe 'sil! NetrwKeepj '.w:netrw_bannercnt."put='../'"
Bram Moolenaar446cb832008-06-24 21:56:24 +00009774 endif
9775 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009776 exe "sil! NetrwKeepj ".line1
9777 sil! NetrwKeepj norm! 0
Bram Moolenaar446cb832008-06-24 21:56:24 +00009778 endif
9779
9780 if search('^\d\{2}-\d\{2}-\d\{2}\s','n') " M$ ftp site cleanup
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009781" call Decho("M$ ftp site listing cleanup",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009782 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 +00009783 elseif exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$")
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009784" call Decho("normal ftp site listing cleanup: bannercnt=".w:netrw_bannercnt." line($)=".line("$"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009785 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/ -> .*$//e'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009786 exe 'sil NetrwKeepj '.w:netrw_bannercnt.',$s/^\(\%(\S\+\s\+\)\{7}\S\+\)\s\+\(\S.*\)$/\2 \t\1/e'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009787 exe 'sil NetrwKeepj '.w:netrw_bannercnt
9788 NetrwKeepj call histdel("/",-1)
9789 NetrwKeepj call histdel("/",-1)
9790 NetrwKeepj call histdel("/",-1)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009791 endif
9792 endif
9793
9794" if exists("w:netrw_bannercnt") && w:netrw_bannercnt <= line("$") " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009795" exe "NetrwKeepj ".w:netrw_bannercnt.',$g/^./call Decho("listing: ".getline("."),''~''.expand("<slnum>"))'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009796" endif " Decho
Bram Moolenaara6878372014-03-22 21:02:50 +01009797
9798" call Dret("s:NetrwRemoteListing 0")
9799 return 0
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00009800endfun
9801
Bram Moolenaar446cb832008-06-24 21:56:24 +00009802" ---------------------------------------------------------------------
9803" s:NetrwRemoteRm: remove/delete a remote file or directory {{{2
9804fun! s:NetrwRemoteRm(usrhost,path) range
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009805 let svpos= winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +00009806
9807 let all= 0
9808 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9809 " remove all marked files
9810 for fname in s:netrwmarkfilelist_{bufnr("%")}
9811 let ok= s:NetrwRemoteRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009812 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009813 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009814 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009815 let all= 1
9816 endif
9817 endfor
Bram Moolenaar5c736222010-01-06 20:54:52 +01009818 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009819
9820 else
9821 " remove files specified by range
9822
9823 " preparation for removing multiple files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009824 let keepsol = &l:sol
9825 setl nosol
9826 let ctr = a:firstline
Bram Moolenaar446cb832008-06-24 21:56:24 +00009827
9828 " remove multiple files and directories
9829 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009830 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +00009831 let ok= s:NetrwRemoteRmFile(a:path,s:NetrwGetWord(),all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009832 if ok =~# 'q\%[uit]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009833 break
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009834 elseif ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009835 let all= 1
9836 endif
9837 let ctr= ctr + 1
9838 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009839 let &l:sol = keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +00009840 endif
9841
9842 " refresh the (remote) directory listing
Tom Benham64a536d2024-11-07 21:15:03 +01009843 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009844 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009845endfun
9846
9847" ---------------------------------------------------------------------
9848" s:NetrwRemoteRmFile: {{{2
9849fun! s:NetrwRemoteRmFile(path,rmfile,all)
9850" call Dfunc("s:NetrwRemoteRmFile(path<".a:path."> rmfile<".a:rmfile.">) all=".a:all)
9851
9852 let all= a:all
9853 let ok = ""
9854
9855 if a:rmfile !~ '^"' && (a:rmfile =~ '@$' || a:rmfile !~ '[\/]$')
9856 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009857" call Decho("attempt to remove file (all=".all.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009858 if !all
9859 echohl Statement
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009860" call Decho("case all=0:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009861 call inputsave()
9862 let ok= input("Confirm deletion of file<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9863 call inputrestore()
9864 echohl NONE
9865 if ok == ""
9866 let ok="no"
9867 endif
9868 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009869 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009870 let all= 1
9871 endif
9872 endif
9873
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009874 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009875" 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 +00009876 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009877" call Decho("case ftp:",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009878 let path= a:path
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009879 if path =~ '^\a\{3,}://'
9880 let path= substitute(path,'^\a\{3,}://[^/]\+/','','')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009881 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009882 sil! NetrwKeepj .,$d _
Bram Moolenaar446cb832008-06-24 21:56:24 +00009883 call s:NetrwRemoteFtpCmd(path,"delete ".'"'.a:rmfile.'"')
9884 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009885" call Decho("case ssh: g:netrw_rm_cmd<".g:netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009886 let netrw_rm_cmd= s:MakeSshCmd(g:netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009887" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009888 if !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009889 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009890 let ok="q"
9891 else
MiguelBarroc46c21b2024-01-31 20:07:17 +01009892 let remotedir= substitute(b:netrw_curdir,'^.\{-}//[^/]\+/\(.*\)$','\1','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009893" call Decho("netrw_rm_cmd<".netrw_rm_cmd.">",'~'.expand("<slnum>"))
9894" call Decho("remotedir<".remotedir.">",'~'.expand("<slnum>"))
9895" call Decho("rmfile<".a:rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009896 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009897 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(remotedir.a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009898 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009899 let netrw_rm_cmd= netrw_rm_cmd." ".s:ShellEscape(fnameescape(a:rmfile))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009900 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009901" call Decho("call system(".netrw_rm_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009902 let ret= system(netrw_rm_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009903 if v:shell_error != 0
9904 if exists("b:netrw_curdir") && b:netrw_curdir != getcwd() && !g:netrw_keepdir
K.Takata71d0ba02024-01-10 03:21:05 +09009905 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 +01009906 else
9907 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
9908 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009909 elseif ret != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009910 call netrw#ErrorMsg(s:WARNING,"cmd<".netrw_rm_cmd."> failed",60)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009911 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009912" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009913 endif
9914 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009915 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009916" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009917 endif
9918
9919 else
9920 " attempt to remove directory
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009921" call Decho("attempt to remove directory",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009922 if !all
9923 call inputsave()
9924 let ok= input("Confirm deletion of directory<".a:rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
9925 call inputrestore()
9926 if ok == ""
9927 let ok="no"
9928 endif
9929 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009930 if ok =~# 'a\%[ll]'
Bram Moolenaar446cb832008-06-24 21:56:24 +00009931 let all= 1
9932 endif
9933 endif
9934
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009935 if all || ok =~# 'y\%[es]' || ok == ""
Bram Moolenaar446cb832008-06-24 21:56:24 +00009936 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009937 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rmdir ".a:rmfile)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009938 else
9939 let rmfile = substitute(a:path.a:rmfile,'/$','','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009940 let netrw_rmdir_cmd = s:MakeSshCmd(netrw#WinPath(g:netrw_rmdir_cmd)).' '.s:ShellEscape(netrw#WinPath(rmfile))
9941" call Decho("attempt to remove dir: system(".netrw_rmdir_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009942 let ret= system(netrw_rmdir_cmd)
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009943" call Decho("returned=".ret." errcode=".v:shell_error,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009944
9945 if v:shell_error != 0
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009946" call Decho("v:shell_error not 0",'~'.expand("<slnum>"))
9947 let netrw_rmf_cmd= s:MakeSshCmd(netrw#WinPath(g:netrw_rmf_cmd)).' '.s:ShellEscape(netrw#WinPath(substitute(rmfile,'[\/]$','','e')))
9948" call Decho("2nd attempt to remove dir: system(".netrw_rmf_cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +00009949 let ret= system(netrw_rmf_cmd)
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
9952 if v:shell_error != 0 && !exists("g:netrw_quiet")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009953 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"unable to remove directory<".rmfile."> -- is it empty?",22)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009954 endif
9955 endif
9956 endif
9957
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +02009958 elseif ok =~# 'q\%[uit]'
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009959" call Decho("ok==".ok,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009960 endif
9961 endif
9962
9963" call Dret("s:NetrwRemoteRmFile ".ok)
9964 return ok
9965endfun
9966
9967" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +00009968" s:NetrwRemoteRename: rename a remote file or directory {{{2
9969fun! s:NetrwRemoteRename(usrhost,path) range
Bram Moolenaar446cb832008-06-24 21:56:24 +00009970
9971 " preparation for removing multiple files/directories
Bram Moolenaare0fa3742016-02-20 15:47:01 +01009972 let svpos = winsaveview()
9973" call Decho("saving posn to svpos<".string(svpos).">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +00009974 let ctr = a:firstline
9975 let rename_cmd = s:MakeSshCmd(g:netrw_rename_cmd)
9976
9977 " rename files given by the markfilelist
9978 if exists("s:netrwmarkfilelist_{bufnr('%')}")
9979 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar446cb832008-06-24 21:56:24 +00009980 if exists("subfrom")
9981 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009982 else
9983 call inputsave()
9984 let newname= input("Moving ".oldname." to : ",oldname)
9985 call inputrestore()
9986 if newname =~ '^s/'
9987 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
9988 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
9989 let newname = substitute(oldname,subfrom,subto,'')
Bram Moolenaar446cb832008-06-24 21:56:24 +00009990 endif
9991 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009992
Bram Moolenaar446cb832008-06-24 21:56:24 +00009993 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +01009994 NetrwKeepj call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009995 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +01009996 let oldname= s:ShellEscape(a:path.oldname)
9997 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +01009998 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +00009999 endif
10000
10001 endfor
10002 call s:NetrwUnMarkFile(1)
10003
10004 else
10005
10006 " attempt to rename files/directories
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010007 let keepsol= &l:sol
10008 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010009 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010010 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010011
10012 let oldname= s:NetrwGetWord()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010013
10014 call inputsave()
10015 let newname= input("Moving ".oldname." to : ",oldname)
10016 call inputrestore()
10017
10018 if exists("w:netrw_method") && (w:netrw_method == 2 || w:netrw_method == 3)
10019 call s:NetrwRemoteFtpCmd(a:path,"rename ".oldname." ".newname)
10020 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010021 let oldname= s:ShellEscape(a:path.oldname)
10022 let newname= s:ShellEscape(a:path.newname)
Bram Moolenaar5c736222010-01-06 20:54:52 +010010023 let ret = system(netrw#WinPath(rename_cmd).' '.oldname.' '.newname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010024 endif
10025
10026 let ctr= ctr + 1
10027 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010028 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010029 endif
10030
10031 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010032 NetrwKeepj call s:NetrwRefresh(0,s:NetrwBrowseChgDir(0,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010033 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010034endfun
10035
Bram Moolenaar85850f32019-07-19 22:05:51 +020010036" ==========================================
Bram Moolenaar446cb832008-06-24 21:56:24 +000010037" Local Directory Browsing Support: {{{1
10038" ==========================================
10039
10040" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010041" netrw#FileUrlEdit: handles editing file://* files {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010042" Should accept: file://localhost/etc/fstab
10043" file:///etc/fstab
10044" file:///c:/WINDOWS/clock.avi
10045" file:///c|/WINDOWS/clock.avi
10046" file://localhost/c:/WINDOWS/clock.avi
10047" file://localhost/c|/WINDOWS/clock.avi
10048" file://c:/foo.txt
10049" file:///c:/foo.txt
10050" 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 +020010051fun! netrw#FileUrlEdit(fname)
10052" call Dfunc("netrw#FileUrlEdit(fname<".a:fname.">)")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010053 let fname = a:fname
10054 if fname =~ '^file://localhost/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010055" call Decho('converting file://localhost/ -to- file:///','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010056 let fname= substitute(fname,'^file://localhost/','file:///','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010057" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010058 endif
Nir Lichtman1e34b952024-05-08 19:19:34 +020010059 if has("win32")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010060 if fname =~ '^file:///\=\a[|:]/'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010061" call Decho('converting file:///\a|/ -to- file://\a:/','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010062 let fname = substitute(fname,'^file:///\=\(\a\)[|:]/','file://\1:/','')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010063" call Decho("fname<".fname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010064 endif
10065 endif
10066 let fname2396 = netrw#RFC2396(fname)
10067 let fname2396e= fnameescape(fname2396)
10068 let plainfname= substitute(fname2396,'file://\(.*\)','\1',"")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010069 if has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010070" call Decho("windows exception for plainfname",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010071 if plainfname =~ '^/\+\a:'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010072" call Decho('removing leading "/"s','~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010073 let plainfname= substitute(plainfname,'^/\+\(\a:\)','\1','')
10074 endif
10075 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020010076
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010077" call Decho("fname2396<".fname2396.">",'~'.expand("<slnum>"))
10078" call Decho("plainfname<".plainfname.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010079 exe "sil doau BufReadPre ".fname2396e
Bram Moolenaar85850f32019-07-19 22:05:51 +020010080 exe 'NetrwKeepj keepalt edit '.plainfname
10081 exe 'sil! NetrwKeepj keepalt bdelete '.fnameescape(a:fname)
10082
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010083" 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 +020010084" call Dret("netrw#FileUrlEdit")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010085 exe "sil doau BufReadPost ".fname2396e
10086endfun
10087
10088" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010089" netrw#LocalBrowseCheck: {{{2
10090fun! netrw#LocalBrowseCheck(dirname)
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010091 " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
Bram Moolenaar85850f32019-07-19 22:05:51 +020010092 " and by <cr> when atop a listed file/directory (via a buffer-local map)
10093 "
10094 " unfortunate interaction -- split window debugging can't be used here, must use
10095 " D-echoRemOn or D-echoTabOn as the BufEnter event triggers
10096 " another call to LocalBrowseCheck() when attempts to write
10097 " to the DBG buffer are made.
10098 "
Bram Moolenaar446cb832008-06-24 21:56:24 +000010099 " The &ft == "netrw" test was installed because the BufEnter event
10100 " would hit when re-entering netrw windows, creating unexpected
10101 " refreshes (and would do so in the middle of NetrwSaveOptions(), too)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010102" call Dfunc("netrw#LocalBrowseCheck(dirname<".a:dirname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010103" call Decho("isdir<".a:dirname."> =".isdirectory(s:NetrwFile(a:dirname)).((exists("s:treeforceredraw")? " treeforceredraw" : "")).'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010104" 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 +010010105 " getting E930: Cannot use :redir inside execute
10106"" call Dredir("ls!","netrw#LocalBrowseCheck")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010107" call Decho("tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> line#".line(".")." col#".col(".")." winline#".winline()." wincol#".wincol(),'~'.expand("<slnum>"))
10108" call Decho("current buffer#".bufnr("%")."<".bufname("%")."> ft=".&ft,'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010010109
Bram Moolenaar97d62492012-11-15 21:28:22 +010010110 let ykeep= @@
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010111 if isdirectory(s:NetrwFile(a:dirname))
10112" 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 +010010113
Bram Moolenaar97d62492012-11-15 21:28:22 +010010114 if &ft != "netrw" || (exists("b:netrw_curdir") && b:netrw_curdir != a:dirname) || g:netrw_fastbrowse <= 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010115" call Decho("case 1 : ft=".&ft,'~'.expand("<slnum>"))
10116" call Decho("s:rexposn_".bufnr("%")."<".bufname("%")."> ".(exists("s:rexposn_".bufnr("%"))? "exists" : "does not exist"),'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010117 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010118
Bram Moolenaar446cb832008-06-24 21:56:24 +000010119 elseif &ft == "netrw" && line("$") == 1
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010120" call Decho("case 2 (ft≡netrw && line($)≡1)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010121 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar8d043172014-01-23 14:24:41 +010010122
Bram Moolenaar5c736222010-01-06 20:54:52 +010010123 elseif exists("s:treeforceredraw")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010124" call Decho("case 3 (treeforceredraw)",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010125 unlet s:treeforceredraw
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010126 sil! NetrwKeepj keepalt call s:NetrwBrowse(1,a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010127 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010128" 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 +010010129" call Dret("netrw#LocalBrowseCheck")
10130 return
Bram Moolenaar446cb832008-06-24 21:56:24 +000010131 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010010132
Bram Moolenaar85850f32019-07-19 22:05:51 +020010133 " The following code wipes out currently unused netrw buffers
Bram Moolenaar97d62492012-11-15 21:28:22 +010010134 " IF g:netrw_fastbrowse is zero (ie. slow browsing selected)
10135 " AND IF the listing style is not a tree listing
10136 if exists("g:netrw_fastbrowse") && g:netrw_fastbrowse == 0 && g:netrw_liststyle != s:TREELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010137" call Decho("wiping out currently unused netrw buffers",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010138 let ibuf = 1
10139 let buflast = bufnr("$")
10140 while ibuf <= buflast
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010141 if bufwinnr(ibuf) == -1 && isdirectory(s:NetrwFile(bufname(ibuf)))
10142 exe "sil! keepj keepalt ".ibuf."bw!"
Bram Moolenaar97d62492012-11-15 21:28:22 +010010143 endif
10144 let ibuf= ibuf + 1
10145 endwhile
10146 endif
10147 let @@= ykeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010148" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
10149" 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 +000010150 " not a directory, ignore it
Bram Moolenaara6878372014-03-22 21:02:50 +010010151" call Dret("netrw#LocalBrowseCheck : not a directory, ignoring it; dirname<".a:dirname.">")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010152endfun
10153
10154" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010155" s:LocalBrowseRefresh: this function is called after a user has {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000010156" performed any shell command. The idea is to cause all local-browsing
10157" buffers to be refreshed after a user has executed some shell command,
10158" on the chance that s/he removed/created a file/directory with it.
Bram Moolenaara6878372014-03-22 21:02:50 +010010159fun! s:LocalBrowseRefresh()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010160 " determine which buffers currently reside in a tab
10161 if !exists("s:netrw_browselist")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010162 return
10163 endif
10164 if !exists("w:netrw_bannercnt")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010165 return
10166 endif
Christian Brabandtfbd72d22023-12-19 20:22:18 +010010167 if !empty(getcmdwintype())
10168 " cannot move away from cmdline window, see :h E11
10169 return
10170 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010171 if exists("s:netrw_events") && s:netrw_events == 1
10172 " s:LocalFastBrowser gets called (indirectly) from a
10173 let s:netrw_events= 2
Bram Moolenaara6878372014-03-22 21:02:50 +010010174 return
Bram Moolenaar5c736222010-01-06 20:54:52 +010010175 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010176 let itab = 1
10177 let buftablist = []
Bram Moolenaar97d62492012-11-15 21:28:22 +010010178 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010179 while itab <= tabpagenr("$")
10180 let buftablist = buftablist + tabpagebuflist()
10181 let itab = itab + 1
Bram Moolenaar85850f32019-07-19 22:05:51 +020010182 sil! tabn
Bram Moolenaar446cb832008-06-24 21:56:24 +000010183 endwhile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010184 " GO through all buffers on netrw_browselist (ie. just local-netrw buffers):
10185 " | refresh any netrw window
10186 " | wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010187 let curwinid = win_getid(winnr())
Bram Moolenaar446cb832008-06-24 21:56:24 +000010188 let ibl = 0
10189 for ibuf in s:netrw_browselist
Bram Moolenaar446cb832008-06-24 21:56:24 +000010190 if bufwinnr(ibuf) == -1 && index(buftablist,ibuf) == -1
10191 " wipe out any non-displaying netrw buffer
Bram Moolenaar85850f32019-07-19 22:05:51 +020010192 " (ibuf not shown in a current window AND
10193 " ibuf not in any tab)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010194 exe "sil! keepj bd ".fnameescape(ibuf)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010195 call remove(s:netrw_browselist,ibl)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010196 continue
10197 elseif index(tabpagebuflist(),ibuf) != -1
10198 " refresh any netrw buffer
Bram Moolenaar446cb832008-06-24 21:56:24 +000010199 exe bufwinnr(ibuf)."wincmd w"
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010200 if getline(".") =~# 'Quick Help'
Bram Moolenaara6878372014-03-22 21:02:50 +010010201 " decrement g:netrw_quickhelp to prevent refresh from changing g:netrw_quickhelp
10202 " (counteracts s:NetrwBrowseChgDir()'s incrementing)
10203 let g:netrw_quickhelp= g:netrw_quickhelp - 1
10204 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010205 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
10206 NetrwKeepj call s:NetrwRefreshTreeDict(w:netrw_treetop)
10207 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010208 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010209 endif
10210 let ibl= ibl + 1
10211 endfor
Bram Moolenaar85850f32019-07-19 22:05:51 +020010212 call win_gotoid(curwinid)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010213 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010214endfun
10215
10216" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010217" s:LocalFastBrowser: handles setting up/taking down fast browsing for the local browser {{{2
10218"
10219" g:netrw_ Directory Is
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010220" fastbrowse Local Remote
Bram Moolenaar97d62492012-11-15 21:28:22 +010010221" slow 0 D D D=Deleting a buffer implies it will not be re-used (slow)
10222" med 1 D H H=Hiding a buffer implies it may be re-used (fast)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010223" fast 2 H H
Bram Moolenaar97d62492012-11-15 21:28:22 +010010224"
10225" Deleting a buffer means that it will be re-loaded when examined, hence "slow".
10226" Hiding a buffer means that it will be re-used when examined, hence "fast".
Bram Moolenaara6878372014-03-22 21:02:50 +010010227" (re-using a buffer may not be as accurate)
10228"
Bram Moolenaar89a9c152021-08-29 21:55:35 +020010229" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
Bram Moolenaara6878372014-03-22 21:02:50 +010010230" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
10231" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
10232" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
10233" =2: autocmds installed (doesn't ignore any FocusGained events)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010234fun! s:LocalFastBrowser()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010235
10236 " initialize browselist, a list of buffer numbers that the local browser has used
10237 if !exists("s:netrw_browselist")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010238 let s:netrw_browselist= []
10239 endif
10240
10241 " append current buffer to fastbrowse list
10242 if empty(s:netrw_browselist) || bufnr("%") > s:netrw_browselist[-1]
Bram Moolenaar97d62492012-11-15 21:28:22 +010010243 call add(s:netrw_browselist,bufnr("%"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010244 endif
10245
10246 " enable autocmd events to handle refreshing/removing local browser buffers
10247 " If local browse buffer is currently showing: refresh it
10248 " If local browse buffer is currently hidden : wipe it
10249 " g:netrw_fastbrowse=0 : slow speed, never re-use directory listing
10250 " =1 : medium speed, re-use directory listing for remote only
10251 " =2 : fast speed, always re-use directory listing when possible
Bram Moolenaara6878372014-03-22 21:02:50 +010010252 if g:netrw_fastbrowse <= 1 && !exists("#ShellCmdPost") && !exists("s:netrw_events")
10253 let s:netrw_events= 1
10254 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010255 au!
Nir Lichtman1e34b952024-05-08 19:19:34 +020010256 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010257 au ShellCmdPost * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010258 else
Bram Moolenaara6878372014-03-22 21:02:50 +010010259 au ShellCmdPost,FocusGained * call s:LocalBrowseRefresh()
Bram Moolenaar97d62492012-11-15 21:28:22 +010010260 endif
10261 augroup END
Bram Moolenaar97d62492012-11-15 21:28:22 +010010262
10263 " user must have changed fastbrowse to its fast setting, so remove
10264 " the associated autocmd events
Bram Moolenaara6878372014-03-22 21:02:50 +010010265 elseif g:netrw_fastbrowse > 1 && exists("#ShellCmdPost") && exists("s:netrw_events")
Bram Moolenaara6878372014-03-22 21:02:50 +010010266 unlet s:netrw_events
10267 augroup AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010268 au!
10269 augroup END
Bram Moolenaara6878372014-03-22 21:02:50 +010010270 augroup! AuNetrwEvent
Bram Moolenaar97d62492012-11-15 21:28:22 +010010271 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010272endfun
10273
Tom Benham64a536d2024-11-07 21:15:03 +010010274fun! s:NetrwLocalListingList(dirname,setmaxfilenamelen)
Bram Moolenaara6878372014-03-22 21:02:50 +010010275 " get the list of files contained in the current directory
Tom Benham64a536d2024-11-07 21:15:03 +010010276 let dirname = a:dirname
10277 let dirnamelen = strlen(dirname)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010278 let filelist = s:NetrwGlob(dirname,"*",0)
10279 let filelist = filelist + s:NetrwGlob(dirname,".*",0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010280
Nir Lichtman1e34b952024-05-08 19:19:34 +020010281 if g:netrw_cygwin == 0 && has("win32")
Tom Benham64a536d2024-11-07 21:15:03 +010010282 elseif index(filelist,'..') == -1 && dirname !~ '/'
Bram Moolenaara6878372014-03-22 21:02:50 +010010283 " include ../ in the glob() entry if its missing
Tom Benham64a536d2024-11-07 21:15:03 +010010284 let filelist= filelist+[s:ComposePath(dirname,"../")]
Bram Moolenaara6878372014-03-22 21:02:50 +010010285 endif
10286
Tom Benham64a536d2024-11-07 21:15:03 +010010287 if a:setmaxfilenamelen && get(g:, 'netrw_dynamic_maxfilenamelen', 0)
Bram Moolenaara6878372014-03-22 21:02:50 +010010288 let filelistcopy = map(deepcopy(filelist),'fnamemodify(v:val, ":t")')
10289 let g:netrw_maxfilenamelen = max(map(filelistcopy,'len(v:val)')) + 1
Bram Moolenaara6878372014-03-22 21:02:50 +010010290 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010291
Tom Benham64a536d2024-11-07 21:15:03 +010010292 let resultfilelist = []
Bram Moolenaara6878372014-03-22 21:02:50 +010010293 for filename in filelist
Bram Moolenaara6878372014-03-22 21:02:50 +010010294
10295 if getftype(filename) == "link"
10296 " indicate a symbolic link
Bram Moolenaara6878372014-03-22 21:02:50 +010010297 let pfile= filename."@"
10298
10299 elseif getftype(filename) == "socket"
10300 " indicate a socket
Bram Moolenaara6878372014-03-22 21:02:50 +010010301 let pfile= filename."="
10302
10303 elseif getftype(filename) == "fifo"
10304 " indicate a fifo
Bram Moolenaara6878372014-03-22 21:02:50 +010010305 let pfile= filename."|"
10306
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010307 elseif isdirectory(s:NetrwFile(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010308 " indicate a directory
Bram Moolenaara6878372014-03-22 21:02:50 +010010309 let pfile= filename."/"
10310
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010311 elseif exists("b:netrw_curdir") && b:netrw_curdir !~ '^.*://' && !isdirectory(s:NetrwFile(filename))
Nir Lichtman1e34b952024-05-08 19:19:34 +020010312 if has("win32")
Bram Moolenaara6878372014-03-22 21:02:50 +010010313 if filename =~ '\.[eE][xX][eE]$' || filename =~ '\.[cC][oO][mM]$' || filename =~ '\.[bB][aA][tT]$'
10314 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010315 let pfile= filename."*"
10316 else
10317 " normal file
10318 let pfile= filename
10319 endif
10320 elseif executable(filename)
10321 " indicate an executable
Bram Moolenaara6878372014-03-22 21:02:50 +010010322 let pfile= filename."*"
10323 else
10324 " normal file
10325 let pfile= filename
10326 endif
10327
10328 else
10329 " normal file
10330 let pfile= filename
10331 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010332
10333 if pfile =~ '//$'
10334 let pfile= substitute(pfile,'//$','/','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010335 endif
10336 let pfile= strpart(pfile,dirnamelen)
10337 let pfile= substitute(pfile,'^[/\\]','','e')
Bram Moolenaara6878372014-03-22 21:02:50 +010010338
10339 if w:netrw_liststyle == s:LONGLIST
K.Takata71d0ba02024-01-10 03:21:05 +090010340 let longfile = printf("%-".g:netrw_maxfilenamelen."S",pfile)
10341 let sz = getfsize(filename)
10342 let szlen = 15 - (strdisplaywidth(longfile) - g:netrw_maxfilenamelen)
10343 let szlen = (szlen > 0) ? szlen : 0
Bram Moolenaar71badf92023-04-22 22:40:14 +010010344
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010345 if g:netrw_sizestyle =~# "[hH]"
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010346 let sz= s:NetrwHumanReadable(sz)
10347 endif
K.Takata8750e3c2023-11-22 18:20:01 +090010348 let fsz = printf("%".szlen."S",sz)
K.Takata71d0ba02024-01-10 03:21:05 +090010349 let pfile= longfile." ".fsz." ".strftime(g:netrw_timefmt,getftime(filename))
Bram Moolenaara6878372014-03-22 21:02:50 +010010350 endif
10351
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010352 if g:netrw_sort_by =~# "^t"
Bram Moolenaara6878372014-03-22 21:02:50 +010010353 " sort by time (handles time up to 1 quintillion seconds, US)
Bram Moolenaar91359012019-11-30 17:57:03 +010010354 " Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
Bram Moolenaara6878372014-03-22 21:02:50 +010010355 let t = getftime(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010356 let ft = printf("%018d",t)
Bram Moolenaara6878372014-03-22 21:02:50 +010010357 let ftpfile= ft.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010358 let resultfilelist += [ftpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010359
10360 elseif g:netrw_sort_by =~ "^s"
10361 " sort by size (handles file sizes up to 1 quintillion bytes, US)
Bram Moolenaara6878372014-03-22 21:02:50 +010010362 let sz = getfsize(filename)
K.Takata8750e3c2023-11-22 18:20:01 +090010363 let fsz = printf("%018d",sz)
Bram Moolenaara6878372014-03-22 21:02:50 +010010364 let fszpfile= fsz.'/'.pfile
Tom Benham64a536d2024-11-07 21:15:03 +010010365 let resultfilelist += [fszpfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010366
10367 else
10368 " sort by name
Tom Benham64a536d2024-11-07 21:15:03 +010010369 let resultfilelist += [pfile]
Bram Moolenaara6878372014-03-22 21:02:50 +010010370 endif
Tom Benham64a536d2024-11-07 21:15:03 +010010371 endfor
10372
10373 return resultfilelist
10374endfun
10375
10376" ---------------------------------------------------------------------
10377" s:LocalListing: does the job of "ls" for local directories {{{2
10378fun! s:LocalListing()
10379
10380 let filelist = s:NetrwLocalListingList(b:netrw_curdir, 1)
10381 for filename in filelist
10382 sil! NetrwKeepj put =filename
Bram Moolenaara6878372014-03-22 21:02:50 +010010383 endfor
10384
10385 " cleanup any windows mess at end-of-line
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010386 sil! NetrwKeepj g/^$/d
10387 sil! NetrwKeepj %s/\r$//e
Bram Moolenaara6878372014-03-22 21:02:50 +010010388 call histdel("/",-1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010389 exe "setl ts=".(g:netrw_maxfilenamelen+1)
Bram Moolenaara6878372014-03-22 21:02:50 +010010390endfun
10391
10392" ---------------------------------------------------------------------
Bram Moolenaar97d62492012-11-15 21:28:22 +010010393" s:NetrwLocalExecute: uses system() to execute command under cursor ("X" command support) {{{2
10394fun! s:NetrwLocalExecute(cmd)
10395" call Dfunc("s:NetrwLocalExecute(cmd<".a:cmd.">)")
10396 let ykeep= @@
10397 " sanity check
10398 if !executable(a:cmd)
10399 call netrw#ErrorMsg(s:ERROR,"the file<".a:cmd."> is not executable!",89)
10400 let @@= ykeep
10401" call Dret("s:NetrwLocalExecute")
10402 return
10403 endif
10404
10405 let optargs= input(":!".a:cmd,"","file")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010406" call Decho("optargs<".optargs.">",'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010407 let result= system(a:cmd.optargs)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010408" call Decho("result,'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010010409
10410 " strip any ansi escape sequences off
10411 let result = substitute(result,"\e\\[[0-9;]*m","","g")
10412
10413 " show user the result(s)
10414 echomsg result
10415 let @@= ykeep
10416
10417" call Dret("s:NetrwLocalExecute")
10418endfun
10419
10420" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010421" s:NetrwLocalRename: rename a local file or directory {{{2
Bram Moolenaar97d62492012-11-15 21:28:22 +010010422fun! s:NetrwLocalRename(path) range
Bram Moolenaar97d62492012-11-15 21:28:22 +010010423
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010424 if !exists("w:netrw_bannercnt")
10425 let w:netrw_bannercnt= b:netrw_bannercnt
10426 endif
10427
Bram Moolenaar97d62492012-11-15 21:28:22 +010010428 " preparation for removing multiple files/directories
Bram Moolenaar29634562020-01-09 21:46:04 +010010429 let ykeep = @@
10430 let ctr = a:firstline
10431 let svpos = winsaveview()
10432 let all = 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010433
10434 " rename files given by the markfilelist
10435 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10436 for oldname in s:netrwmarkfilelist_{bufnr("%")}
Bram Moolenaar97d62492012-11-15 21:28:22 +010010437 if exists("subfrom")
10438 let newname= substitute(oldname,subfrom,subto,'')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010439 else
10440 call inputsave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010441 let newname= input("Moving ".oldname." to : ",oldname,"file")
Bram Moolenaar97d62492012-11-15 21:28:22 +010010442 call inputrestore()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010443 if newname =~ ''
10444 " two ctrl-x's : ignore all of string preceding the ctrl-x's
10445 let newname = substitute(newname,'^.*','','')
10446 elseif newname =~ ''
10447 " one ctrl-x : ignore portion of string preceding ctrl-x but after last /
10448 let newname = substitute(newname,'[^/]*','','')
10449 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010450 if newname =~ '^s/'
10451 let subfrom = substitute(newname,'^s/\([^/]*\)/.*/$','\1','')
10452 let subto = substitute(newname,'^s/[^/]*/\(.*\)/$','\1','')
Bram Moolenaar97d62492012-11-15 21:28:22 +010010453 let newname = substitute(oldname,subfrom,subto,'')
10454 endif
10455 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010010456 if !all && filereadable(newname)
10457 call inputsave()
10458 let response= input("File<".newname."> already exists; do you want to overwrite it? (y/all/n) ")
10459 call inputrestore()
10460 if response == "all"
10461 let all= 1
10462 elseif response != "y" && response != "yes"
10463 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010464 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaar29634562020-01-09 21:46:04 +010010465 NetrwKeepj call winrestview(svpos)
10466 let @@= ykeep
Bram Moolenaar29634562020-01-09 21:46:04 +010010467 return
10468 endif
10469 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010470 call rename(oldname,newname)
10471 endfor
10472 call s:NetrwUnmarkList(bufnr("%"),b:netrw_curdir)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010473
Bram Moolenaar97d62492012-11-15 21:28:22 +010010474 else
10475
10476 " attempt to rename files/directories
10477 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010478 exe "NetrwKeepj ".ctr
Bram Moolenaar97d62492012-11-15 21:28:22 +010010479
10480 " sanity checks
10481 if line(".") < w:netrw_bannercnt
10482 let ctr= ctr + 1
10483 continue
10484 endif
10485 let curword= s:NetrwGetWord()
10486 if curword == "./" || curword == "../"
10487 let ctr= ctr + 1
10488 continue
10489 endif
10490
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010491 NetrwKeepj norm! 0
Bram Moolenaar97d62492012-11-15 21:28:22 +010010492 let oldname= s:ComposePath(a:path,curword)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010493
10494 call inputsave()
10495 let newname= input("Moving ".oldname." to : ",substitute(oldname,'/*$','','e'))
10496 call inputrestore()
10497
10498 call rename(oldname,newname)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010499 let ctr= ctr + 1
10500 endwhile
10501 endif
10502
10503 " refresh the directory
Tom Benham64a536d2024-11-07 21:15:03 +010010504 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010505 NetrwKeepj call winrestview(svpos)
Bram Moolenaar97d62492012-11-15 21:28:22 +010010506 let @@= ykeep
Bram Moolenaar97d62492012-11-15 21:28:22 +010010507endfun
10508
10509" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000010510" s:NetrwLocalRm: {{{2
10511fun! s:NetrwLocalRm(path) range
KSR-Yasudab52e7ac2023-12-12 01:11:43 +090010512 if !exists("w:netrw_bannercnt")
10513 let w:netrw_bannercnt= b:netrw_bannercnt
10514 endif
10515
Bram Moolenaar446cb832008-06-24 21:56:24 +000010516 " preparation for removing multiple files/directories
Bram Moolenaar97d62492012-11-15 21:28:22 +010010517 let ykeep = @@
Bram Moolenaar446cb832008-06-24 21:56:24 +000010518 let ret = 0
10519 let all = 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010520 let svpos = winsaveview()
Bram Moolenaar446cb832008-06-24 21:56:24 +000010521
10522 if exists("s:netrwmarkfilelist_{bufnr('%')}")
10523 " remove all marked files
Bram Moolenaar446cb832008-06-24 21:56:24 +000010524 for fname in s:netrwmarkfilelist_{bufnr("%")}
10525 let ok= s:NetrwLocalRmFile(a:path,fname,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010526 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010527 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010528 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010529 let all= 1
10530 endif
10531 endfor
10532 call s:NetrwUnMarkFile(1)
10533
10534 else
10535 " remove (multiple) files and directories
Bram Moolenaar446cb832008-06-24 21:56:24 +000010536
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010537 let keepsol= &l:sol
10538 setl nosol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010539 let ctr = a:firstline
10540 while ctr <= a:lastline
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010541 exe "NetrwKeepj ".ctr
Bram Moolenaar446cb832008-06-24 21:56:24 +000010542
10543 " sanity checks
10544 if line(".") < w:netrw_bannercnt
10545 let ctr= ctr + 1
10546 continue
10547 endif
10548 let curword= s:NetrwGetWord()
10549 if curword == "./" || curword == "../"
10550 let ctr= ctr + 1
10551 continue
10552 endif
10553 let ok= s:NetrwLocalRmFile(a:path,curword,all)
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010554 if ok =~# 'q\%[uit]' || ok == "no"
Bram Moolenaar446cb832008-06-24 21:56:24 +000010555 break
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010556 elseif ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010557 let all= 1
10558 endif
10559 let ctr= ctr + 1
10560 endwhile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010561 let &l:sol= keepsol
Bram Moolenaar446cb832008-06-24 21:56:24 +000010562 endif
10563
10564 " refresh the directory
Bram Moolenaar446cb832008-06-24 21:56:24 +000010565 if bufname("%") != "NetrwMessage"
Tom Benham64a536d2024-11-07 21:15:03 +010010566 NetrwKeepj call s:NetrwRefresh(1,s:NetrwBrowseChgDir(1,'./',0))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010010567 NetrwKeepj call winrestview(svpos)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010568 endif
Bram Moolenaar97d62492012-11-15 21:28:22 +010010569 let @@= ykeep
Bram Moolenaar446cb832008-06-24 21:56:24 +000010570endfun
10571
10572" ---------------------------------------------------------------------
10573" s:NetrwLocalRmFile: remove file fname given the path {{{2
10574" Give confirmation prompt unless all==1
10575fun! s:NetrwLocalRmFile(path,fname,all)
10576" call Dfunc("s:NetrwLocalRmFile(path<".a:path."> fname<".a:fname."> all=".a:all)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010577
Bram Moolenaar446cb832008-06-24 21:56:24 +000010578 let all= a:all
10579 let ok = ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010580 NetrwKeepj norm! 0
Christian Brabandt581d4a72024-07-23 21:14:06 +020010581 let rmfile= s:NetrwFile(s:ComposePath(a:path,escape(a:fname, '\\')))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010582" call Decho("rmfile<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010583
10584 if rmfile !~ '^"' && (rmfile =~ '@$' || rmfile !~ '[\/]$')
10585 " attempt to remove file
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010586" call Decho("attempt to remove file<".rmfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010587 if !all
10588 echohl Statement
10589 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010590 let ok= input("Confirm deletion of file <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010591 call inputrestore()
10592 echohl NONE
10593 if ok == ""
10594 let ok="no"
10595 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010596" call Decho("response: ok<".ok.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010597 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010598" call Decho("response: ok<".ok."> (after sub)",'~'.expand("<slnum>"))
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010599 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010600 let all= 1
10601 endif
10602 endif
10603
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010604 if all || ok =~# '^y\%[es]$' || ok == ""
Bram Moolenaarc236c162008-07-13 17:41:49 +000010605 let ret= s:NetrwDelete(rmfile)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010606" call Decho("errcode=".v:shell_error." ret=".ret,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010607 endif
10608
10609 else
10610 " attempt to remove directory
10611 if !all
10612 echohl Statement
10613 call inputsave()
Christian Brabandt581d4a72024-07-23 21:14:06 +020010614 let ok= input("Confirm *recursive* deletion of directory <".rmfile."> ","[{y(es)},n(o),a(ll),q(uit)] ")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010615 call inputrestore()
10616 let ok= substitute(ok,'\[{y(es)},n(o),a(ll),q(uit)]\s*','','e')
10617 if ok == ""
10618 let ok="no"
10619 endif
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010620 if ok =~# '^a\%[ll]$'
Bram Moolenaar446cb832008-06-24 21:56:24 +000010621 let all= 1
10622 endif
10623 endif
10624 let rmfile= substitute(rmfile,'[\/]$','','e')
10625
Christian Brabandt0f5effb2024-09-15 19:17:23 +020010626 if all || ok =~# '^y\%[es]$' || ok == ""
Nir Lichtmanc16c4a22024-05-10 23:43:29 +020010627 if delete(rmfile,"rf")
Bram Moolenaar71badf92023-04-22 22:40:14 +010010628 call netrw#ErrorMsg(s:ERROR,"unable to delete directory <".rmfile.">!",103)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010629 endif
10630 endif
10631 endif
10632
10633" call Dret("s:NetrwLocalRmFile ".ok)
10634 return ok
10635endfun
10636
Bram Moolenaar85850f32019-07-19 22:05:51 +020010637" =====================================================================
Bram Moolenaar9964e462007-05-05 17:54:07 +000010638" Support Functions: {{{1
10639
Bram Moolenaar488c6512005-08-11 20:09:58 +000010640" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010641" netrw#Access: intended to provide access to variable values for netrw's test suite {{{2
10642" 0: marked file list of current buffer
10643" 1: marked file target
10644fun! netrw#Access(ilist)
10645 if a:ilist == 0
10646 if exists("s:netrwmarkfilelist_".bufnr('%'))
10647 return s:netrwmarkfilelist_{bufnr('%')}
10648 else
10649 return "no-list-buf#".bufnr('%')
10650 endif
10651 elseif a:ilist == 1
10652 return s:netrwmftgt
Bram Moolenaar85850f32019-07-19 22:05:51 +020010653 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010010654endfun
10655
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010656" ---------------------------------------------------------------------
10657" netrw#Call: allows user-specified mappings to call internal netrw functions {{{2
10658fun! netrw#Call(funcname,...)
Bram Moolenaar85850f32019-07-19 22:05:51 +020010659 return call("s:".a:funcname,a:000)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010660endfun
10661
Bram Moolenaara6878372014-03-22 21:02:50 +010010662" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010663" netrw#Expose: allows UserMaps and pchk to look at otherwise script-local variables {{{2
10664" I expect this function to be used in
10665" :PChkAssert netrw#Expose("netrwmarkfilelist")
10666" for example.
10667fun! netrw#Expose(varname)
10668" call Dfunc("netrw#Expose(varname<".a:varname.">)")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010669 if exists("s:".a:varname)
10670 exe "let retval= s:".a:varname
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010671" call Decho("retval=".retval,'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010672 if exists("g:netrw_pchk")
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010673" call Decho("type(g:netrw_pchk=".g:netrw_pchk.")=".type(retval),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010674 if type(retval) == 3
10675 let retval = copy(retval)
10676 let i = 0
10677 while i < len(retval)
10678 let retval[i]= substitute(retval[i],expand("$HOME"),'~','')
10679 let i = i + 1
10680 endwhile
10681 endif
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010682" call Dret("netrw#Expose ".string(retval)),'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010683 return string(retval)
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010684 else
10685" call Decho("g:netrw_pchk doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010686 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010687 else
Bram Moolenaar5ef1c6a2019-11-10 22:09:11 +010010688" call Decho("s:".a:varname." doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010689 let retval= "n/a"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010690 endif
10691
10692" call Dret("netrw#Expose ".string(retval))
10693 return retval
10694endfun
10695
10696" ---------------------------------------------------------------------
10697" netrw#Modify: allows UserMaps to set (modify) script-local variables {{{2
10698fun! netrw#Modify(varname,newvalue)
10699" call Dfunc("netrw#Modify(varname<".a:varname.">,newvalue<".string(a:newvalue).">)")
10700 exe "let s:".a:varname."= ".string(a:newvalue)
10701" call Dret("netrw#Modify")
10702endfun
10703
10704" ---------------------------------------------------------------------
Bram Moolenaara6878372014-03-22 21:02:50 +010010705" netrw#RFC2396: converts %xx into characters {{{2
10706fun! netrw#RFC2396(fname)
10707" call Dfunc("netrw#RFC2396(fname<".a:fname.">)")
K.Takata23577652024-01-13 01:30:01 +090010708 let fname = escape(substitute(a:fname,'%\(\x\x\)','\=printf("%c","0x".submatch(1))','ge')," \t")
Bram Moolenaara6878372014-03-22 21:02:50 +010010709" call Dret("netrw#RFC2396 ".fname)
10710 return fname
10711endfun
10712
10713" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010714" netrw#UserMaps: supports user-specified maps {{{2
10715" see :help function()
10716"
10717" g:Netrw_UserMaps is a List with members such as:
10718" [[keymap sequence, function reference],...]
10719"
10720" The referenced function may return a string,
10721" refresh : refresh the display
10722" -other- : this string will be executed
10723" or it may return a List of strings.
10724"
10725" Each keymap-sequence will be set up with a nnoremap
Bram Moolenaar85850f32019-07-19 22:05:51 +020010726" to invoke netrw#UserMaps(a:islocal).
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010727" Related functions:
10728" netrw#Expose(varname) -- see s:varname variables
10729" netrw#Modify(varname,newvalue) -- modify value of s:varname variable
10730" netrw#Call(funcname,...) -- call internal netrw function with optional arguments
10731fun! netrw#UserMaps(islocal)
10732" call Dfunc("netrw#UserMaps(islocal=".a:islocal.")")
10733" call Decho("g:Netrw_UserMaps ".(exists("g:Netrw_UserMaps")? "exists" : "does NOT exist"),'~'.expand("<slnum>"))
10734
10735 " set up usermaplist
10736 if exists("g:Netrw_UserMaps") && type(g:Netrw_UserMaps) == 3
10737" call Decho("g:Netrw_UserMaps has type 3<List>",'~'.expand("<slnum>"))
10738 for umap in g:Netrw_UserMaps
10739" call Decho("type(umap[0]<".string(umap[0]).">)=".type(umap[0])." (should be 1=string)",'~'.expand("<slnum>"))
10740" call Decho("type(umap[1])=".type(umap[1])." (should be 1=string)",'~'.expand("<slnum>"))
10741 " if umap[0] is a string and umap[1] is a string holding a function name
10742 if type(umap[0]) == 1 && type(umap[1]) == 1
10743" call Decho("nno <buffer> <silent> ".umap[0]." :call s:UserMaps(".a:islocal.",".string(umap[1]).")<cr>",'~'.expand("<slnum>"))
10744 exe "nno <buffer> <silent> ".umap[0]." :call <SID>UserMaps(".a:islocal.",'".umap[1]."')<cr>"
10745 else
10746 call netrw#ErrorMsg(s:WARNING,"ignoring usermap <".string(umap[0])."> -- not a [string,funcref] entry",99)
10747 endif
10748 endfor
10749 endif
10750" call Dret("netrw#UserMaps")
10751endfun
10752
10753" ---------------------------------------------------------------------
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010754" netrw#WinPath: tries to insure that the path is windows-acceptable, whether cygwin is used or not {{{2
10755fun! netrw#WinPath(path)
10756" call Dfunc("netrw#WinPath(path<".a:path.">)")
Nir Lichtman1e34b952024-05-08 19:19:34 +020010757 if (!g:netrw_cygwin || &shell !~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$') && has("win32")
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010758 " remove cygdrive prefix, if present
Bram Moolenaar8d043172014-01-23 14:24:41 +010010759 let path = substitute(a:path,g:netrw_cygdrive.'/\(.\)','\1:','')
Bram Moolenaare6ae6222013-05-21 21:01:10 +020010760 " remove trailing slash (Win95)
10761 let path = substitute(path, '\(\\\|/\)$', '', 'g')
10762 " remove escaped spaces
10763 let path = substitute(path, '\ ', ' ', 'g')
10764 " convert slashes to backslashes
10765 let path = substitute(path, '/', '\', 'g')
10766 else
10767 let path= a:path
10768 endif
10769" call Dret("netrw#WinPath <".path.">")
10770 return path
10771endfun
10772
10773" ---------------------------------------------------------------------
Travis Sheltone34d0e32024-07-30 21:08:56 +020010774" s:StripTrailingSlash: removes trailing slashes from a path {{{2
10775fun! s:StripTrailingSlash(path)
10776 " remove trailing slash
10777 return substitute(a:path, '[/\\]$', '', 'g')
10778endfun
10779
Travis Sheltone34d0e32024-07-30 21:08:56 +020010780" ---------------------------------------------------------------------
Bram Moolenaar85850f32019-07-19 22:05:51 +020010781" s:NetrwBadd: adds marked files to buffer list or vice versa {{{2
10782" cb : bl2mf=0 add marked files to buffer list
10783" cB : bl2mf=1 use bufferlist to mark files
10784" (mnemonic: cb = copy (marked files) to buffer list)
10785fun! s:NetrwBadd(islocal,bl2mf)
10786" " call Dfunc("s:NetrwBadd(islocal=".a:islocal." mf2bl=".mf2bl.")")
10787 if a:bl2mf
10788 " cB: add buffer list to marked files
10789 redir => bufl
10790 ls
10791 redir END
10792 let bufl = map(split(bufl,"\n"),'substitute(v:val,''^.\{-}"\(.*\)".\{-}$'',''\1'','''')')
10793 for fname in bufl
10794 call s:NetrwMarkFile(a:islocal,fname)
10795 endfor
10796 else
10797 " cb: add marked files to buffer list
10798 for fname in s:netrwmarkfilelist_{bufnr("%")}
10799" " call Decho("badd ".fname,'~'.expand("<slnum>"))
10800 exe "badd ".fnameescape(fname)
10801 endfor
10802 let curbufnr = bufnr("%")
10803 let curdir = s:NetrwGetCurdir(a:islocal)
10804 call s:NetrwUnmarkList(curbufnr,curdir) " remove markings from local buffer
10805 endif
10806" call Dret("s:NetrwBadd")
10807endfun
10808
10809" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000010810" s:ComposePath: Appends a new part to a path taking different systems into consideration {{{2
10811fun! s:ComposePath(base,subdir)
10812" call Dfunc("s:ComposePath(base<".a:base."> subdir<".a:subdir.">)")
10813
Bram Moolenaar5b435d62012-04-05 17:33:26 +020010814 if has("amiga")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010815" call Decho("amiga",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010816 let ec = a:base[s:Strlen(a:base)-1]
Bram Moolenaarc236c162008-07-13 17:41:49 +000010817 if ec != '/' && ec != ':'
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010818 let ret = a:base."/" . a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010819 else
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020010820 let ret = a:base.a:subdir
Bram Moolenaarc236c162008-07-13 17:41:49 +000010821 endif
10822
Bram Moolenaar85850f32019-07-19 22:05:51 +020010823 " COMBAK: test on windows with changing to root directory: :e C:/
Nir Lichtman1e34b952024-05-08 19:19:34 +020010824 elseif a:subdir =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010825" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010826 let ret= a:subdir
10827
Nir Lichtman1e34b952024-05-08 19:19:34 +020010828 elseif a:base =~ '^\a:[/\\]\([^/\\]\|$\)' && has("win32")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010829" call Decho("windows",'~'.expand("<slnum>"))
Bram Moolenaar5c736222010-01-06 20:54:52 +010010830 if a:base =~ '[/\\]$'
10831 let ret= a:base.a:subdir
10832 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010833 let ret= a:base.'/'.a:subdir
Bram Moolenaar5c736222010-01-06 20:54:52 +010010834 endif
10835
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010836 elseif a:base =~ '^\a\{3,}://'
10837" call Decho("remote linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010838 let urlbase = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\1','')
10839 let curpath = substitute(a:base,'^\(\a\+://.\{-}/\)\(.*\)$','\2','')
10840 if a:subdir == '../'
10841 if curpath =~ '[^/]/[^/]\+/$'
10842 let curpath= substitute(curpath,'[^/]\+/$','','')
10843 else
10844 let curpath=""
10845 endif
10846 let ret= urlbase.curpath
10847 else
10848 let ret= urlbase.curpath.a:subdir
10849 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010850" call Decho("urlbase<".urlbase.">",'~'.expand("<slnum>"))
10851" call Decho("curpath<".curpath.">",'~'.expand("<slnum>"))
10852" call Decho("ret<".ret.">",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010853
10854 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010855" call Decho("local linux/macos",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000010856 let ret = substitute(a:base."/".a:subdir,"//","/","g")
10857 if a:base =~ '^//'
10858 " keeping initial '//' for the benefit of network share listing support
10859 let ret= '/'.ret
10860 endif
10861 let ret= simplify(ret)
10862 endif
10863
10864" call Dret("s:ComposePath ".ret)
10865 return ret
10866endfun
10867
10868" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010869" s:DeleteBookmark: deletes a file/directory from Netrw's bookmark system {{{2
10870" Related Functions: s:MakeBookmark() s:NetrwBookHistHandler() s:NetrwBookmark()
10871fun! s:DeleteBookmark(fname)
10872" call Dfunc("s:DeleteBookmark(fname<".a:fname.">)")
10873 call s:MergeBookmarks()
10874
10875 if exists("g:netrw_bookmarklist")
10876 let indx= index(g:netrw_bookmarklist,a:fname)
10877 if indx == -1
10878 let indx= 0
10879 while indx < len(g:netrw_bookmarklist)
10880 if g:netrw_bookmarklist[indx] =~ a:fname
10881 call remove(g:netrw_bookmarklist,indx)
10882 let indx= indx - 1
10883 endif
10884 let indx= indx + 1
10885 endwhile
10886 else
10887 " remove exact match
10888 call remove(g:netrw_bookmarklist,indx)
10889 endif
10890 endif
10891
10892" call Dret("s:DeleteBookmark")
10893endfun
10894
10895" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000010896" s:FileReadable: o/s independent filereadable {{{2
10897fun! s:FileReadable(fname)
10898" call Dfunc("s:FileReadable(fname<".a:fname.">)")
10899
10900 if g:netrw_cygwin
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010901 let ret= filereadable(s:NetrwFile(substitute(a:fname,g:netrw_cygdrive.'/\(.\)','\1:/','')))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010902 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010903 let ret= filereadable(s:NetrwFile(a:fname))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010904 endif
10905
10906" call Dret("s:FileReadable ".ret)
10907 return ret
10908endfun
10909
10910" ---------------------------------------------------------------------
10911" s:GetTempfile: gets a tempname that'll work for various o/s's {{{2
10912" Places correct suffix on end of temporary filename,
10913" using the suffix provided with fname
10914fun! s:GetTempfile(fname)
10915" call Dfunc("s:GetTempfile(fname<".a:fname.">)")
10916
10917 if !exists("b:netrw_tmpfile")
10918 " get a brand new temporary filename
10919 let tmpfile= tempname()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010920" call Decho("tmpfile<".tmpfile."> : from tempname()",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010921
Bram Moolenaarc236c162008-07-13 17:41:49 +000010922 let tmpfile= substitute(tmpfile,'\','/','ge')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010923" call Decho("tmpfile<".tmpfile."> : chgd any \\ -> /",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010924
Bram Moolenaar9964e462007-05-05 17:54:07 +000010925 " sanity check -- does the temporary file's directory exist?
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010926 if !isdirectory(s:NetrwFile(substitute(tmpfile,'[^/]\+$','','e')))
10927" 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 +010010928 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"your <".substitute(tmpfile,'[^/]\+$','','e')."> directory is missing!",2)
Bram Moolenaar9964e462007-05-05 17:54:07 +000010929" call Dret("s:GetTempfile getcwd<".getcwd().">")
10930 return ""
10931 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000010932
Bram Moolenaar9964e462007-05-05 17:54:07 +000010933 " let netrw#NetSource() know about the tmpfile
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010010934 let s:netrw_tmpfile= tmpfile " used by netrw#NetSource() and netrw#BrowseX()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010935" call Decho("tmpfile<".tmpfile."> s:netrw_tmpfile<".s:netrw_tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000010936
Bram Moolenaar9964e462007-05-05 17:54:07 +000010937 " o/s dependencies
Bram Moolenaar446cb832008-06-24 21:56:24 +000010938 if g:netrw_cygwin != 0
Bram Moolenaar8d043172014-01-23 14:24:41 +010010939 let tmpfile = substitute(tmpfile,'^\(\a\):',g:netrw_cygdrive.'/\1','e')
Nir Lichtman1e34b952024-05-08 19:19:34 +020010940 elseif has("win32")
Bram Moolenaar446cb832008-06-24 21:56:24 +000010941 if !exists("+shellslash") || !&ssl
10942 let tmpfile = substitute(tmpfile,'/','\','g')
10943 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010944 else
Bram Moolenaar446cb832008-06-24 21:56:24 +000010945 let tmpfile = tmpfile
Bram Moolenaar9964e462007-05-05 17:54:07 +000010946 endif
10947 let b:netrw_tmpfile= tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010948" call Decho("o/s dependent fixed tempname<".tmpfile.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010949 else
10950 " re-use temporary filename
10951 let tmpfile= b:netrw_tmpfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010952" call Decho("tmpfile<".tmpfile."> re-using",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010953 endif
10954
10955 " use fname's suffix for the temporary file
10956 if a:fname != ""
10957 if a:fname =~ '\.[^./]\+$'
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010958" call Decho("using fname<".a:fname.">'s suffix",'~'.expand("<slnum>"))
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010959 if a:fname =~ '\.tar\.gz$' || a:fname =~ '\.tar\.bz2$' || a:fname =~ '\.tar\.xz$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000010960 let suffix = ".tar".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020010961 elseif a:fname =~ '.txz$'
10962 let suffix = ".txz".substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010963 else
10964 let suffix = substitute(a:fname,'^.*\(\.[^./]\+\)$','\1','e')
10965 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010966" call Decho("suffix<".suffix.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010967 let tmpfile= substitute(tmpfile,'\.tmp$','','e')
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010968" call Decho("chgd tmpfile<".tmpfile."> (removed any .tmp suffix)",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010969 let tmpfile .= suffix
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010970" call Decho("chgd tmpfile<".tmpfile."> (added ".suffix." suffix) netrw_fname<".b:netrw_fname.">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000010971 let s:netrw_tmpfile= tmpfile " supports netrw#NetSource()
10972 endif
10973 endif
10974
Bram Moolenaara0f849e2015-10-30 14:37:44 +010010975" 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 +000010976" call Dret("s:GetTempfile <".tmpfile.">")
10977 return tmpfile
Bram Moolenaar446cb832008-06-24 21:56:24 +000010978endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +000010979
10980" ---------------------------------------------------------------------
10981" s:MakeSshCmd: transforms input command using USEPORT HOSTNAME into {{{2
Bram Moolenaarc236c162008-07-13 17:41:49 +000010982" a correct command for use with a system() call
Bram Moolenaar9964e462007-05-05 17:54:07 +000010983fun! s:MakeSshCmd(sshcmd)
Bram Moolenaar446cb832008-06-24 21:56:24 +000010984" call Dfunc("s:MakeSshCmd(sshcmd<".a:sshcmd.">) user<".s:user."> machine<".s:machine.">")
Bram Moolenaar13600302014-05-22 18:26:40 +020010985 if s:user == ""
10986 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:machine,'')
10987 else
10988 let sshcmd = substitute(a:sshcmd,'\<HOSTNAME\>',s:user."@".s:machine,'')
10989 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000010990 if exists("g:netrw_port") && g:netrw_port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010991 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.g:netrw_port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010992 elseif exists("s:port") && s:port != ""
Bram Moolenaar7aa9f6a2007-05-10 18:00:30 +000010993 let sshcmd= substitute(sshcmd,"USEPORT",g:netrw_sshport.' '.s:port,'')
Bram Moolenaar9964e462007-05-05 17:54:07 +000010994 else
10995 let sshcmd= substitute(sshcmd,"USEPORT ",'','')
10996 endif
10997" call Dret("s:MakeSshCmd <".sshcmd.">")
10998 return sshcmd
10999endfun
11000
11001" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011002" s:MakeBookmark: enters a bookmark into Netrw's bookmark system {{{2
11003fun! s:MakeBookmark(fname)
11004" call Dfunc("s:MakeBookmark(fname<".a:fname.">)")
11005
11006 if !exists("g:netrw_bookmarklist")
11007 let g:netrw_bookmarklist= []
11008 endif
11009
11010 if index(g:netrw_bookmarklist,a:fname) == -1
11011 " curdir not currently in g:netrw_bookmarklist, so include it
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011012 if isdirectory(s:NetrwFile(a:fname)) && a:fname !~ '/$'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011013 call add(g:netrw_bookmarklist,a:fname.'/')
11014 elseif a:fname !~ '/'
11015 call add(g:netrw_bookmarklist,getcwd()."/".a:fname)
11016 else
11017 call add(g:netrw_bookmarklist,a:fname)
11018 endif
11019 call sort(g:netrw_bookmarklist)
11020 endif
11021
11022" call Dret("s:MakeBookmark")
11023endfun
11024
11025" ---------------------------------------------------------------------
11026" s:MergeBookmarks: merge current bookmarks with saved bookmarks {{{2
11027fun! s:MergeBookmarks()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011028" call Dfunc("s:MergeBookmarks() : merge current bookmarks into .netrwbook")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011029 " get bookmarks from .netrwbook file
11030 let savefile= s:NetrwHome()."/.netrwbook"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011031 if filereadable(s:NetrwFile(savefile))
11032" call Decho("merge bookmarks (active and file)",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011033 NetrwKeepj call s:NetrwBookHistSave()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011034" call Decho("bookmark delete savefile<".savefile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011035 NetrwKeepj call delete(savefile)
11036 endif
11037" call Dret("s:MergeBookmarks")
11038endfun
11039
11040" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011041" s:NetrwBMShow: {{{2
11042fun! s:NetrwBMShow()
11043" call Dfunc("s:NetrwBMShow()")
11044 redir => bmshowraw
11045 menu
11046 redir END
11047 let bmshowlist = split(bmshowraw,'\n')
11048 if bmshowlist != []
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011049 let bmshowfuncs= filter(bmshowlist,'v:val =~# "<SNR>\\d\\+_BMShow()"')
Bram Moolenaarc236c162008-07-13 17:41:49 +000011050 if bmshowfuncs != []
11051 let bmshowfunc = substitute(bmshowfuncs[0],'^.*:\(call.*BMShow()\).*$','\1','')
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011052 if bmshowfunc =~# '^call.*BMShow()'
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011053 exe "sil! NetrwKeepj ".bmshowfunc
Bram Moolenaarc236c162008-07-13 17:41:49 +000011054 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011055 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011056 endif
Bram Moolenaarc236c162008-07-13 17:41:49 +000011057" call Dret("s:NetrwBMShow : bmshowfunc<".(exists("bmshowfunc")? bmshowfunc : 'n/a').">")
11058endfun
11059
11060" ---------------------------------------------------------------------
Bram Moolenaaradc21822011-04-01 18:03:16 +020011061" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011062fun! s:NetrwCursor(editfile)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011063 if !exists("w:netrw_liststyle")
11064 let w:netrw_liststyle= g:netrw_liststyle
11065 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011066" 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 +020011067
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011068" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
11069
Bram Moolenaaradc21822011-04-01 18:03:16 +020011070 if &ft != "netrw"
11071 " if the current window isn't a netrw directory listing window, then use user cursorline/column
11072 " settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011073" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011074
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011075 elseif g:netrw_cursor == 8
11076 if w:netrw_liststyle == s:WIDELIST
11077 setl cursorline
11078 setl cursorcolumn
11079 else
11080 setl cursorline
11081 endif
11082 elseif g:netrw_cursor == 7
11083 setl cursorline
11084 elseif g:netrw_cursor == 6
11085 if w:netrw_liststyle == s:WIDELIST
11086 setl cursorline
11087 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011088 elseif g:netrw_cursor == 4
11089 " all styles: cursorline, cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011090" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011091 setl cursorline
11092 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011093
11094 elseif g:netrw_cursor == 3
11095 " thin-long-tree: cursorline, user's cursorcolumn
11096 " wide : cursorline, cursorcolumn
11097 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011098" call Decho("case g:netrw_cursor==3 and wide: setl cul cuc",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011099 setl cursorline
11100 setl cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011101 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011102" 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 +020011103 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011104 endif
11105
11106 elseif g:netrw_cursor == 2
11107 " thin-long-tree: cursorline, user's cursorcolumn
11108 " wide : cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011109" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
Bram Moolenaar15146672011-10-20 22:22:38 +020011110 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011111
11112 elseif g:netrw_cursor == 1
11113 " thin-long-tree: user's cursorline, user's cursorcolumn
11114 " wide : cursorline, user's cursorcolumn
Bram Moolenaaradc21822011-04-01 18:03:16 +020011115 if w:netrw_liststyle == s:WIDELIST
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011116" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
Bram Moolenaar8d043172014-01-23 14:24:41 +010011117 setl cursorline
Bram Moolenaaradc21822011-04-01 18:03:16 +020011118 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011119" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011120 endif
11121
11122 else
Bram Moolenaaradc21822011-04-01 18:03:16 +020011123 " all styles: user's cursorline, user's cursorcolumn
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011124" call Decho("default: (use user's cul,cuc)",'~'.expand("<slnum>"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011125 let &l:cursorline = s:netrw_usercul
11126 let &l:cursorcolumn = s:netrw_usercuc
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011127 endif
Bram Moolenaaradc21822011-04-01 18:03:16 +020011128
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011129" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaaradc21822011-04-01 18:03:16 +020011130" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011131endfun
11132
11133" ---------------------------------------------------------------------
11134" s:RestoreCursorline: restores cursorline/cursorcolumn to original user settings {{{2
11135fun! s:RestoreCursorline()
Bram Moolenaar8d043172014-01-23 14:24:41 +010011136" call Dfunc("s:RestoreCursorline() currently, cul=".&l:cursorline." cuc=".&l:cursorcolumn." win#".winnr()." buf#".bufnr("%"))
Bram Moolenaaradc21822011-04-01 18:03:16 +020011137 if exists("s:netrw_usercul")
11138 let &l:cursorline = s:netrw_usercul
11139 endif
11140 if exists("s:netrw_usercuc")
11141 let &l:cursorcolumn = s:netrw_usercuc
11142 endif
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011143" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011144" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
11145endfun
11146
Christian Brabandt62f7b552024-06-23 20:23:40 +020011147" s:RestoreRegister: restores all registers given in the dict {{{2
11148fun! s:RestoreRegister(dict)
11149 for [key, val] in items(a:dict)
11150 if key == 'unnamed'
11151 let key = ''
11152 endif
11153 call setreg(key, val[0], val[1])
11154 endfor
11155endfun
11156
Bram Moolenaar00a927d2010-05-14 23:24:24 +020011157" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011158" s:NetrwDelete: Deletes a file. {{{2
11159" Uses Steve Hall's idea to insure that Windows paths stay
11160" acceptable. No effect on Unix paths.
11161" Examples of use: let result= s:NetrwDelete(path)
11162fun! s:NetrwDelete(path)
11163" call Dfunc("s:NetrwDelete(path<".a:path.">)")
11164
Bram Moolenaar5c736222010-01-06 20:54:52 +010011165 let path = netrw#WinPath(a:path)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011166 if !g:netrw_cygwin && has("win32")
Bram Moolenaarc236c162008-07-13 17:41:49 +000011167 if exists("+shellslash")
11168 let sskeep= &shellslash
Bram Moolenaarff034192013-04-24 18:51:19 +020011169 setl noshellslash
Bram Moolenaarc236c162008-07-13 17:41:49 +000011170 let result = delete(path)
11171 let &shellslash = sskeep
11172 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011173" call Decho("exe let result= ".a:cmd."('".path."')",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011174 let result= delete(path)
11175 endif
11176 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011177" call Decho("let result= delete(".path.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011178 let result= delete(path)
11179 endif
11180 if result < 0
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011181 NetrwKeepj call netrw#ErrorMsg(s:WARNING,"delete(".path.") failed!",71)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011182 endif
11183
11184" call Dret("s:NetrwDelete ".result)
11185 return result
Bram Moolenaar446cb832008-06-24 21:56:24 +000011186endfun
11187
11188" ---------------------------------------------------------------------
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011189" s:NetrwBufRemover: removes a buffer that: {{{2s
11190" has buffer-id > 1
11191" is unlisted
11192" is unnamed
11193" does not appear in any window
11194fun! s:NetrwBufRemover(bufid)
11195" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
11196" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
11197" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
11198" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
11199" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
11200
yasuda4dbb2662023-10-04 20:50:35 +020011201 if a:bufid > 1 && !buflisted(a:bufid) && bufloaded(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011202" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
yasuda4dbb2662023-10-04 20:50:35 +020011203 exe "sil! bd! ".a:bufid
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011204 endif
11205
11206" call Dret("s:NetrwBufRemover")
11207endfun
11208
11209" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011210" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
Bram Moolenaar5c736222010-01-06 20:54:52 +010011211fun! s:NetrwEnew(...)
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011212" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011213" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011214
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011215 " Clean out the last buffer:
Bram Moolenaar89a9c152021-08-29 21:55:35 +020011216 " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
11217 " If so, delete it.
11218 call s:NetrwBufRemover(bufnr("$"))
11219
Bram Moolenaar446cb832008-06-24 21:56:24 +000011220 " grab a function-local-variable copy of buffer variables
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011221" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011222 if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
11223 if exists("b:netrw_browser_active") |let netrw_browser_active = b:netrw_browser_active |endif
11224 if exists("b:netrw_cpf") |let netrw_cpf = b:netrw_cpf |endif
11225 if exists("b:netrw_curdir") |let netrw_curdir = b:netrw_curdir |endif
11226 if exists("b:netrw_explore_bufnr") |let netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11227 if exists("b:netrw_explore_indx") |let netrw_explore_indx = b:netrw_explore_indx |endif
11228 if exists("b:netrw_explore_line") |let netrw_explore_line = b:netrw_explore_line |endif
11229 if exists("b:netrw_explore_list") |let netrw_explore_list = b:netrw_explore_list |endif
11230 if exists("b:netrw_explore_listlen")|let netrw_explore_listlen = b:netrw_explore_listlen|endif
11231 if exists("b:netrw_explore_mtchcnt")|let netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11232 if exists("b:netrw_fname") |let netrw_fname = b:netrw_fname |endif
11233 if exists("b:netrw_lastfile") |let netrw_lastfile = b:netrw_lastfile |endif
11234 if exists("b:netrw_liststyle") |let netrw_liststyle = b:netrw_liststyle |endif
11235 if exists("b:netrw_method") |let netrw_method = b:netrw_method |endif
11236 if exists("b:netrw_option") |let netrw_option = b:netrw_option |endif
11237 if exists("b:netrw_prvdir") |let netrw_prvdir = b:netrw_prvdir |endif
11238
Bram Moolenaar85850f32019-07-19 22:05:51 +020011239 NetrwKeepj call s:NetrwOptionsRestore("w:")
Bram Moolenaar71badf92023-04-22 22:40:14 +010011240" call Decho("generate a buffer with NetrwKeepj enew!",'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011241 " when tree listing uses file TreeListing... a new buffer is made.
11242 " Want the old buffer to be unlisted.
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011243 " COMBAK: this causes a problem, see P43
11244" setl nobl
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011245 let netrw_keepdiff= &l:diff
Bram Moolenaar71badf92023-04-22 22:40:14 +010011246 call s:NetrwEditFile("enew!","","")
Bram Moolenaar5ac3b1a2010-07-27 22:50:36 +020011247 let &l:diff= netrw_keepdiff
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011248" call Decho("bufnr($)=".bufnr("$")."<".bufname(bufnr("$"))."> winnr($)=".winnr("$"),'~'.expand("<slnum>"))
Bram Moolenaar85850f32019-07-19 22:05:51 +020011249 NetrwKeepj call s:NetrwOptionsSave("w:")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011250
Bram Moolenaar446cb832008-06-24 21:56:24 +000011251 " copy function-local-variables to buffer variable equivalents
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011252" call Decho("copy function-local variables back to buffer netrw variables",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011253 if exists("netrw_bannercnt") |let b:netrw_bannercnt = netrw_bannercnt |endif
11254 if exists("netrw_browser_active") |let b:netrw_browser_active = netrw_browser_active |endif
11255 if exists("netrw_cpf") |let b:netrw_cpf = netrw_cpf |endif
11256 if exists("netrw_curdir") |let b:netrw_curdir = netrw_curdir |endif
11257 if exists("netrw_explore_bufnr") |let b:netrw_explore_bufnr = netrw_explore_bufnr |endif
11258 if exists("netrw_explore_indx") |let b:netrw_explore_indx = netrw_explore_indx |endif
11259 if exists("netrw_explore_line") |let b:netrw_explore_line = netrw_explore_line |endif
11260 if exists("netrw_explore_list") |let b:netrw_explore_list = netrw_explore_list |endif
11261 if exists("netrw_explore_listlen")|let b:netrw_explore_listlen = netrw_explore_listlen|endif
11262 if exists("netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt = netrw_explore_mtchcnt|endif
11263 if exists("netrw_fname") |let b:netrw_fname = netrw_fname |endif
11264 if exists("netrw_lastfile") |let b:netrw_lastfile = netrw_lastfile |endif
11265 if exists("netrw_liststyle") |let b:netrw_liststyle = netrw_liststyle |endif
11266 if exists("netrw_method") |let b:netrw_method = netrw_method |endif
11267 if exists("netrw_option") |let b:netrw_option = netrw_option |endif
11268 if exists("netrw_prvdir") |let b:netrw_prvdir = netrw_prvdir |endif
11269
Bram Moolenaar5c736222010-01-06 20:54:52 +010011270 if a:0 > 0
11271 let b:netrw_curdir= a:1
11272 if b:netrw_curdir =~ '/$'
11273 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011274 setl nobl
Bram Moolenaar5c736222010-01-06 20:54:52 +010011275 file NetrwTreeListing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011276 setl nobl bt=nowrite bh=hide
Bram Moolenaaradc21822011-04-01 18:03:16 +020011277 nno <silent> <buffer> [ :sil call <SID>TreeListMove('[')<cr>
11278 nno <silent> <buffer> ] :sil call <SID>TreeListMove(']')<cr>
Bram Moolenaar5c736222010-01-06 20:54:52 +010011279 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011280 call s:NetrwBufRename(b:netrw_curdir)
Bram Moolenaar5c736222010-01-06 20:54:52 +010011281 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011282 endif
11283 endif
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011284 if v:version >= 700 && has("balloon_eval") && !exists("s:initbeval") && !exists("g:netrw_nobeval") && has("syntax") && exists("g:syntax_on")
11285 let &l:bexpr = "netrw#BalloonHelp()"
11286 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011287
Bram Moolenaar8d043172014-01-23 14:24:41 +010011288" call Dret("s:NetrwEnew : buf#".bufnr("%")."<".bufname("%")."> expand(%)<".expand("%")."> expand(#)<".expand("#")."> bh=".&bh." win#".winnr()." winnr($)#".winnr("$"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011289endfun
11290
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011291" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011292" s:NetrwExe: executes a string using "!" {{{2
11293fun! s:NetrwExe(cmd)
Bram Moolenaar85850f32019-07-19 22:05:51 +020011294" call Dfunc("s:NetrwExe(a:cmd<".a:cmd.">)")
Konfekt3d7e5672024-10-27 22:16:49 +010011295 if has("win32")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011296" call Decho("using win32:",expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011297 let savedShell=[&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash]
11298 set shell& shellcmdflag& shellxquote& shellxescape&
11299 set shellquote& shellpipe& shellredir& shellslash&
Konfekt3d7e5672024-10-27 22:16:49 +010011300 try
11301 exe a:cmd
11302 finally
11303 let [&shell,&shellcmdflag,&shellxquote,&shellxescape,&shellquote,&shellpipe,&shellredir,&shellslash] = savedShell
11304 endtry
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011305 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011306" call Decho("exe ".a:cmd,'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011307 exe a:cmd
11308 endif
Bram Moolenaar29634562020-01-09 21:46:04 +010011309 if v:shell_error
11310 call netrw#ErrorMsg(s:WARNING,"shell signalled an error",106)
11311 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011312" call Dret("s:NetrwExe : v:shell_error=".v:shell_error)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011313endfun
11314
11315" ---------------------------------------------------------------------
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011316" s:NetrwInsureWinVars: insure that a netrw buffer has its w: variables in spite of a wincmd v or s {{{2
11317fun! s:NetrwInsureWinVars()
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011318 if !exists("w:netrw_liststyle")
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011319" call Dfunc("s:NetrwInsureWinVars() win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011320 let curbuf = bufnr("%")
11321 let curwin = winnr()
11322 let iwin = 1
11323 while iwin <= winnr("$")
11324 exe iwin."wincmd w"
11325 if winnr() != curwin && bufnr("%") == curbuf && exists("w:netrw_liststyle")
11326 " looks like ctrl-w_s or ctrl-w_v was used to split a netrw buffer
11327 let winvars= w:
11328 break
11329 endif
11330 let iwin= iwin + 1
11331 endwhile
Bram Moolenaarff034192013-04-24 18:51:19 +020011332 exe "keepalt ".curwin."wincmd w"
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011333 if exists("winvars")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011334" call Decho("copying w#".iwin." window variables to w#".curwin,'~'.expand("<slnum>"))
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011335 for k in keys(winvars)
11336 let w:{k}= winvars[k]
11337 endfor
11338 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011339" call Dret("s:NetrwInsureWinVars win#".winnr())
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011340 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011341endfun
11342
Bram Moolenaara6878372014-03-22 21:02:50 +010011343" ---------------------------------------------------------------------
11344" s:NetrwLcd: handles changing the (local) directory {{{2
Bram Moolenaar85850f32019-07-19 22:05:51 +020011345" Returns: 0=success
11346" -1=failed
Bram Moolenaara6878372014-03-22 21:02:50 +010011347fun! s:NetrwLcd(newdir)
11348" call Dfunc("s:NetrwLcd(newdir<".a:newdir.">)")
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011349" call Decho("changing local directory",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011350
Bram Moolenaar85850f32019-07-19 22:05:51 +020011351 let err472= 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011352 try
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011353 exe 'NetrwKeepj sil lcd '.fnameescape(a:newdir)
Bram Moolenaara6878372014-03-22 21:02:50 +010011354 catch /^Vim\%((\a\+)\)\=:E344/
11355 " Vim's lcd fails with E344 when attempting to go above the 'root' of a Windows share.
11356 " Therefore, detect if a Windows share is present, and if E344 occurs, just settle at
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011357 " 'root' (ie. '\'). The share name may start with either backslashes ('\\Foo') or
Bram Moolenaara6878372014-03-22 21:02:50 +010011358 " forward slashes ('//Foo'), depending on whether backslashes have been converted to
11359 " forward slashes by earlier code; so check for both.
Nir Lichtman1e34b952024-05-08 19:19:34 +020011360 if has("win32") && !g:netrw_cygwin
Bram Moolenaara6878372014-03-22 21:02:50 +010011361 if a:newdir =~ '^\\\\\w\+' || a:newdir =~ '^//\w\+'
11362 let dirname = '\'
K.Takata71d0ba02024-01-10 03:21:05 +090011363 exe 'NetrwKeepj sil lcd '.fnameescape(dirname)
Bram Moolenaara6878372014-03-22 21:02:50 +010011364 endif
11365 endif
11366 catch /^Vim\%((\a\+)\)\=:E472/
Bram Moolenaar85850f32019-07-19 22:05:51 +020011367 let err472= 1
11368 endtry
11369
11370 if err472
Bram Moolenaara6878372014-03-22 21:02:50 +010011371 call netrw#ErrorMsg(s:ERROR,"unable to change directory to <".a:newdir."> (permissions?)",61)
11372 if exists("w:netrw_prvdir")
11373 let a:newdir= w:netrw_prvdir
11374 else
Bram Moolenaar85850f32019-07-19 22:05:51 +020011375 call s:NetrwOptionsRestore("w:")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011376" call Decho("setl noma nomod nowrap",'~'.expand("<slnum>"))
Bram Moolenaar13600302014-05-22 18:26:40 +020011377 exe "setl ".g:netrw_bufsettings
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011378" 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 +010011379 let a:newdir= dirname
Bram Moolenaara6878372014-03-22 21:02:50 +010011380 endif
Bram Moolenaar85850f32019-07-19 22:05:51 +020011381" call Dret("s:NetrwBrowse -1 : reusing buffer#".(exists("bufnum")? bufnum : 'N/A')."<".dirname."> getcwd<".getcwd().">")
11382 return -1
11383 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011384
Bram Moolenaar1d59aa12020-09-19 18:50:13 +020011385" call Decho("getcwd <".getcwd().">")
11386" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011387" call Dret("s:NetrwLcd 0")
11388 return 0
Bram Moolenaara6878372014-03-22 21:02:50 +010011389endfun
11390
Bram Moolenaar9964e462007-05-05 17:54:07 +000011391" ------------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011392" s:NetrwSaveWordPosn: used to keep cursor on same word after refresh, {{{2
11393" changed sorting, etc. Also see s:NetrwRestoreWordPosn().
11394fun! s:NetrwSaveWordPosn()
11395" call Dfunc("NetrwSaveWordPosn()")
11396 let s:netrw_saveword= '^'.fnameescape(getline('.')).'$'
11397" call Dret("NetrwSaveWordPosn : saveword<".s:netrw_saveword.">")
11398endfun
11399
11400" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011401" s:NetrwHumanReadable: takes a number and makes it "human readable" {{{2
11402" 1000 -> 1K, 1000000 -> 1M, 1000000000 -> 1G
11403fun! s:NetrwHumanReadable(sz)
11404" call Dfunc("s:NetrwHumanReadable(sz=".a:sz.") type=".type(a:sz)." style=".g:netrw_sizestyle )
11405
11406 if g:netrw_sizestyle == 'h'
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011407 if a:sz >= 1000000000
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011408 let sz = printf("%.1f",a:sz/1000000000.0)."g"
11409 elseif a:sz >= 10000000
11410 let sz = printf("%d",a:sz/1000000)."m"
11411 elseif a:sz >= 1000000
11412 let sz = printf("%.1f",a:sz/1000000.0)."m"
11413 elseif a:sz >= 10000
11414 let sz = printf("%d",a:sz/1000)."k"
11415 elseif a:sz >= 1000
11416 let sz = printf("%.1f",a:sz/1000.0)."k"
11417 else
11418 let sz= a:sz
11419 endif
11420
11421 elseif g:netrw_sizestyle == 'H'
11422 if a:sz >= 1073741824
11423 let sz = printf("%.1f",a:sz/1073741824.0)."G"
11424 elseif a:sz >= 10485760
11425 let sz = printf("%d",a:sz/1048576)."M"
11426 elseif a:sz >= 1048576
11427 let sz = printf("%.1f",a:sz/1048576.0)."M"
11428 elseif a:sz >= 10240
11429 let sz = printf("%d",a:sz/1024)."K"
11430 elseif a:sz >= 1024
11431 let sz = printf("%.1f",a:sz/1024.0)."K"
11432 else
11433 let sz= a:sz
11434 endif
11435
11436 else
11437 let sz= a:sz
11438 endif
11439
11440" call Dret("s:NetrwHumanReadable ".sz)
11441 return sz
11442endfun
11443
11444" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011445" s:NetrwRestoreWordPosn: used to keep cursor on same word after refresh, {{{2
11446" changed sorting, etc. Also see s:NetrwSaveWordPosn().
11447fun! s:NetrwRestoreWordPosn()
11448" call Dfunc("NetrwRestoreWordPosn()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011449 sil! call search(s:netrw_saveword,'w')
Bram Moolenaar446cb832008-06-24 21:56:24 +000011450" call Dret("NetrwRestoreWordPosn")
11451endfun
11452
11453" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011454" s:RestoreBufVars: {{{2
11455fun! s:RestoreBufVars()
11456" call Dfunc("s:RestoreBufVars()")
11457
11458 if exists("s:netrw_curdir") |let b:netrw_curdir = s:netrw_curdir |endif
11459 if exists("s:netrw_lastfile") |let b:netrw_lastfile = s:netrw_lastfile |endif
11460 if exists("s:netrw_method") |let b:netrw_method = s:netrw_method |endif
11461 if exists("s:netrw_fname") |let b:netrw_fname = s:netrw_fname |endif
11462 if exists("s:netrw_machine") |let b:netrw_machine = s:netrw_machine |endif
11463 if exists("s:netrw_browser_active")|let b:netrw_browser_active = s:netrw_browser_active|endif
11464
11465" call Dret("s:RestoreBufVars")
11466endfun
11467
11468" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000011469" s:RemotePathAnalysis: {{{2
11470fun! s:RemotePathAnalysis(dirname)
Bram Moolenaar251e1912011-06-19 05:09:16 +020011471" call Dfunc("s:RemotePathAnalysis(a:dirname<".a:dirname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +000011472
Bram Moolenaara6878372014-03-22 21:02:50 +010011473 " method :// user @ machine :port /path
Bram Moolenaar8d043172014-01-23 14:24:41 +010011474 let dirpat = '^\(\w\{-}\)://\(\(\w\+\)@\)\=\([^/:#]\+\)\%([:#]\(\d\+\)\)\=/\(.*\)$'
Bram Moolenaar9964e462007-05-05 17:54:07 +000011475 let s:method = substitute(a:dirname,dirpat,'\1','')
Bram Moolenaar8d043172014-01-23 14:24:41 +010011476 let s:user = substitute(a:dirname,dirpat,'\3','')
11477 let s:machine = substitute(a:dirname,dirpat,'\4','')
11478 let s:port = substitute(a:dirname,dirpat,'\5','')
11479 let s:path = substitute(a:dirname,dirpat,'\6','')
Bram Moolenaar13600302014-05-22 18:26:40 +020011480 let s:fname = substitute(s:path,'^.*/\ze.','','')
Bram Moolenaara6878372014-03-22 21:02:50 +010011481 if s:machine =~ '@'
11482 let dirpat = '^\(.*\)@\(.\{-}\)$'
11483 let s:user = s:user.'@'.substitute(s:machine,dirpat,'\1','')
11484 let s:machine = substitute(s:machine,dirpat,'\2','')
11485 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011486
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011487" call Decho("set up s:method <".s:method .">",'~'.expand("<slnum>"))
11488" call Decho("set up s:user <".s:user .">",'~'.expand("<slnum>"))
11489" call Decho("set up s:machine<".s:machine.">",'~'.expand("<slnum>"))
11490" call Decho("set up s:port <".s:port.">",'~'.expand("<slnum>"))
11491" call Decho("set up s:path <".s:path .">",'~'.expand("<slnum>"))
11492" call Decho("set up s:fname <".s:fname .">",'~'.expand("<slnum>"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011493
11494" call Dret("s:RemotePathAnalysis")
11495endfun
11496
11497" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011498" s:RemoteSystem: runs a command on a remote host using ssh {{{2
11499" Returns status
11500" Runs system() on
11501" [cd REMOTEDIRPATH;] a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011502" Note that it doesn't do s:ShellEscape(a:cmd)!
Bram Moolenaarc236c162008-07-13 17:41:49 +000011503fun! s:RemoteSystem(cmd)
11504" call Dfunc("s:RemoteSystem(cmd<".a:cmd.">)")
11505 if !executable(g:netrw_ssh_cmd)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011506 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 +000011507 elseif !exists("b:netrw_curdir")
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011508 NetrwKeepj call netrw#ErrorMsg(s:ERROR,"for some reason b:netrw_curdir doesn't exist!",53)
Bram Moolenaarc236c162008-07-13 17:41:49 +000011509 else
11510 let cmd = s:MakeSshCmd(g:netrw_ssh_cmd." USEPORT HOSTNAME")
11511 let remotedir= substitute(b:netrw_curdir,'^.*//[^/]\+/\(.*\)$','\1','')
11512 if remotedir != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011513 let cmd= cmd.' cd '.s:ShellEscape(remotedir).";"
Bram Moolenaarc236c162008-07-13 17:41:49 +000011514 else
11515 let cmd= cmd.' '
11516 endif
11517 let cmd= cmd.a:cmd
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011518" call Decho("call system(".cmd.")",'~'.expand("<slnum>"))
Bram Moolenaarc236c162008-07-13 17:41:49 +000011519 let ret= system(cmd)
11520 endif
11521" call Dret("s:RemoteSystem ".ret)
11522 return ret
Bram Moolenaar9964e462007-05-05 17:54:07 +000011523endfun
11524
11525" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011526" s:RestoreWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011527fun! s:RestoreWinVars()
11528" call Dfunc("s:RestoreWinVars()")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011529 if exists("s:bannercnt") |let w:netrw_bannercnt = s:bannercnt |unlet s:bannercnt |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011530 if exists("s:col") |let w:netrw_col = s:col |unlet s:col |endif
11531 if exists("s:curdir") |let w:netrw_curdir = s:curdir |unlet s:curdir |endif
11532 if exists("s:explore_bufnr") |let w:netrw_explore_bufnr = s:explore_bufnr |unlet s:explore_bufnr |endif
11533 if exists("s:explore_indx") |let w:netrw_explore_indx = s:explore_indx |unlet s:explore_indx |endif
11534 if exists("s:explore_line") |let w:netrw_explore_line = s:explore_line |unlet s:explore_line |endif
11535 if exists("s:explore_listlen")|let w:netrw_explore_listlen = s:explore_listlen|unlet s:explore_listlen|endif
11536 if exists("s:explore_list") |let w:netrw_explore_list = s:explore_list |unlet s:explore_list |endif
11537 if exists("s:explore_mtchcnt")|let w:netrw_explore_mtchcnt = s:explore_mtchcnt|unlet s:explore_mtchcnt|endif
11538 if exists("s:fpl") |let w:netrw_fpl = s:fpl |unlet s:fpl |endif
11539 if exists("s:hline") |let w:netrw_hline = s:hline |unlet s:hline |endif
11540 if exists("s:line") |let w:netrw_line = s:line |unlet s:line |endif
11541 if exists("s:liststyle") |let w:netrw_liststyle = s:liststyle |unlet s:liststyle |endif
Bram Moolenaar488c6512005-08-11 20:09:58 +000011542 if exists("s:method") |let w:netrw_method = s:method |unlet s:method |endif
11543 if exists("s:prvdir") |let w:netrw_prvdir = s:prvdir |unlet s:prvdir |endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000011544 if exists("s:treedict") |let w:netrw_treedict = s:treedict |unlet s:treedict |endif
11545 if exists("s:treetop") |let w:netrw_treetop = s:treetop |unlet s:treetop |endif
11546 if exists("s:winnr") |let w:netrw_winnr = s:winnr |unlet s:winnr |endif
11547" call Dret("s:RestoreWinVars")
Bram Moolenaar488c6512005-08-11 20:09:58 +000011548endfun
11549
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011550" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011551" s:Rexplore: implements returning from a buffer to a netrw directory {{{2
11552"
11553" s:SetRexDir() sets up <2-leftmouse> maps (if g:netrw_retmap
11554" is true) and a command, :Rexplore, which call this function.
11555"
Bram Moolenaar85850f32019-07-19 22:05:51 +020011556" s:netrw_posn is set up by s:NetrwBrowseChgDir()
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011557"
11558" s:rexposn_BUFNR used to save/restore cursor position
Bram Moolenaar446cb832008-06-24 21:56:24 +000011559fun! s:NetrwRexplore(islocal,dirname)
Bram Moolenaarff034192013-04-24 18:51:19 +020011560 if exists("s:netrwdrag")
11561 return
11562 endif
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011563" 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 +010011564" call Decho("currently in bufname<".bufname("%").">",'~'.expand("<slnum>"))
11565" 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 +010011566
11567 if &ft == "netrw" && exists("w:netrw_rexfile") && w:netrw_rexfile != ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011568 " a :Rex while in a netrw buffer means: edit the file in w:netrw_rexfile
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011569" call Decho("in netrw buffer, will edit file<".w:netrw_rexfile.">",'~'.expand("<slnum>"))
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011570 exe "NetrwKeepj e ".w:netrw_rexfile
Bram Moolenaara6878372014-03-22 21:02:50 +010011571 unlet w:netrw_rexfile
11572" call Dret("s:NetrwRexplore returning from netrw to buf#".bufnr("%")."<".bufname("%")."> (ft=".&ft.")")
Bram Moolenaar15146672011-10-20 22:22:38 +020011573 return
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011574" else " Decho
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011575" call Decho("treating as not-netrw-buffer: ft=".&ft.((&ft == "netrw")? " == netrw" : "!= netrw"),'~'.expand("<slnum>"))
11576" 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 +020011577 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011578
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011579 " ---------------------------
11580 " :Rex issued while in a file
11581 " ---------------------------
11582
Bram Moolenaara6878372014-03-22 21:02:50 +010011583 " record current file so :Rex can return to it from netrw
11584 let w:netrw_rexfile= expand("%")
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011585" call Decho("set w:netrw_rexfile<".w:netrw_rexfile."> (win#".winnr().")",'~'.expand("<slnum>"))
Bram Moolenaara6878372014-03-22 21:02:50 +010011586
11587 if !exists("w:netrw_rexlocal")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011588" call Dret("s:NetrwRexplore w:netrw_rexlocal doesn't exist (".&ft." win#".winnr().")")
Bram Moolenaara6878372014-03-22 21:02:50 +010011589 return
11590 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011591" 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 +020011592 if w:netrw_rexlocal
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011593 NetrwKeepj call netrw#LocalBrowseCheck(w:netrw_rexdir)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011594 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011595 NetrwKeepj call s:NetrwBrowse(0,w:netrw_rexdir)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011596 endif
Bram Moolenaar15146672011-10-20 22:22:38 +020011597 if exists("s:initbeval")
Bram Moolenaara6878372014-03-22 21:02:50 +010011598 setl beval
Bram Moolenaar15146672011-10-20 22:22:38 +020011599 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011600 if exists("s:rexposn_".bufnr("%"))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011601" call Decho("restore posn, then unlet s:rexposn_".bufnr('%')."<".bufname("%").">",'~'.expand("<slnum>"))
11602 " restore position in directory listing
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011603" call Decho("restoring posn to s:rexposn_".bufnr('%')."<".string(s:rexposn_{bufnr('%')}).">",'~'.expand("<slnum>"))
11604 NetrwKeepj call winrestview(s:rexposn_{bufnr('%')})
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011605 if exists("s:rexposn_".bufnr('%'))
11606 unlet s:rexposn_{bufnr('%')}
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011607 endif
Bram Moolenaar5b435d62012-04-05 17:33:26 +020011608 else
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011609" call Decho("s:rexposn_".bufnr('%')."<".bufname("%")."> doesn't exist",'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011610 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011611
Bram Moolenaar85850f32019-07-19 22:05:51 +020011612 if has("syntax") && exists("g:syntax_on") && g:syntax_on
11613 if exists("s:explore_match")
11614 exe "2match netrwMarkFile /".s:explore_match."/"
11615 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010011616 endif
Bram Moolenaara6878372014-03-22 21:02:50 +010011617
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011618" 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 +010011619" call Dret("s:NetrwRexplore : ft=".&ft)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011620endfun
11621
11622" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011623" s:SaveBufVars: save selected b: variables to s: variables {{{2
11624" use s:RestoreBufVars() to restore b: variables from s: variables
Bram Moolenaar9964e462007-05-05 17:54:07 +000011625fun! s:SaveBufVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011626" call Dfunc("s:SaveBufVars() buf#".bufnr("%"))
Bram Moolenaar9964e462007-05-05 17:54:07 +000011627
11628 if exists("b:netrw_curdir") |let s:netrw_curdir = b:netrw_curdir |endif
11629 if exists("b:netrw_lastfile") |let s:netrw_lastfile = b:netrw_lastfile |endif
11630 if exists("b:netrw_method") |let s:netrw_method = b:netrw_method |endif
11631 if exists("b:netrw_fname") |let s:netrw_fname = b:netrw_fname |endif
11632 if exists("b:netrw_machine") |let s:netrw_machine = b:netrw_machine |endif
11633 if exists("b:netrw_browser_active")|let s:netrw_browser_active = b:netrw_browser_active|endif
11634
11635" call Dret("s:SaveBufVars")
11636endfun
11637
11638" ---------------------------------------------------------------------
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011639" s:SavePosn: saves position associated with current buffer into a dictionary {{{2
11640fun! s:SavePosn(posndict)
11641" call Dfunc("s:SavePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
11642
Bram Moolenaar85850f32019-07-19 22:05:51 +020011643 if !exists("a:posndict[bufnr('%')]")
11644 let a:posndict[bufnr("%")]= []
11645 endif
11646" call Decho("before push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11647 call add(a:posndict[bufnr("%")],winsaveview())
11648" call Decho("after push: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011649
11650" call Dret("s:SavePosn posndict")
11651 return a:posndict
11652endfun
11653
11654" ---------------------------------------------------------------------
11655" s:RestorePosn: restores position associated with current buffer using dictionary {{{2
11656fun! s:RestorePosn(posndict)
11657" call Dfunc("s:RestorePosn(posndict) curbuf#".bufnr("%")."<".bufname("%").">")
Bram Moolenaar85850f32019-07-19 22:05:51 +020011658 if exists("a:posndict")
11659 if has_key(a:posndict,bufnr("%"))
11660" call Decho("before pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11661 let posnlen= len(a:posndict[bufnr("%")])
11662 if posnlen > 0
11663 let posnlen= posnlen - 1
11664" call Decho("restoring posn posndict[".bufnr("%")."][".posnlen."]=".string(a:posndict[bufnr("%")][posnlen]),'~'.expand("<slnum>"))
11665 call winrestview(a:posndict[bufnr("%")][posnlen])
11666 call remove(a:posndict[bufnr("%")],posnlen)
11667" call Decho("after pop: a:posndict[buf#".bufnr("%")."]=".string(a:posndict[bufnr('%')]))
11668 endif
11669 endif
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011670 endif
11671" call Dret("s:RestorePosn")
11672endfun
11673
11674" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011675" s:SaveWinVars: (used by Explore() and NetrwSplit()) {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000011676fun! s:SaveWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011677" call Dfunc("s:SaveWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011678 if exists("w:netrw_bannercnt") |let s:bannercnt = w:netrw_bannercnt |endif
11679 if exists("w:netrw_col") |let s:col = w:netrw_col |endif
11680 if exists("w:netrw_curdir") |let s:curdir = w:netrw_curdir |endif
11681 if exists("w:netrw_explore_bufnr") |let s:explore_bufnr = w:netrw_explore_bufnr |endif
11682 if exists("w:netrw_explore_indx") |let s:explore_indx = w:netrw_explore_indx |endif
11683 if exists("w:netrw_explore_line") |let s:explore_line = w:netrw_explore_line |endif
11684 if exists("w:netrw_explore_listlen")|let s:explore_listlen = w:netrw_explore_listlen|endif
11685 if exists("w:netrw_explore_list") |let s:explore_list = w:netrw_explore_list |endif
11686 if exists("w:netrw_explore_mtchcnt")|let s:explore_mtchcnt = w:netrw_explore_mtchcnt|endif
11687 if exists("w:netrw_fpl") |let s:fpl = w:netrw_fpl |endif
11688 if exists("w:netrw_hline") |let s:hline = w:netrw_hline |endif
11689 if exists("w:netrw_line") |let s:line = w:netrw_line |endif
11690 if exists("w:netrw_liststyle") |let s:liststyle = w:netrw_liststyle |endif
11691 if exists("w:netrw_method") |let s:method = w:netrw_method |endif
11692 if exists("w:netrw_prvdir") |let s:prvdir = w:netrw_prvdir |endif
11693 if exists("w:netrw_treedict") |let s:treedict = w:netrw_treedict |endif
11694 if exists("w:netrw_treetop") |let s:treetop = w:netrw_treetop |endif
11695 if exists("w:netrw_winnr") |let s:winnr = w:netrw_winnr |endif
11696" call Dret("s:SaveWinVars")
11697endfun
11698
11699" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011700" s:SetBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck()) {{{2
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011701" To allow separate windows to have their own activities, such as
11702" Explore **/pattern, several variables have been made window-oriented.
11703" However, when the user splits a browser window (ex: ctrl-w s), these
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011704" variables are not inherited by the new window. SetBufWinVars() and
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011705" UseBufWinVars() get around that.
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011706fun! s:SetBufWinVars()
Bram Moolenaar5c736222010-01-06 20:54:52 +010011707" call Dfunc("s:SetBufWinVars() win#".winnr())
Bram Moolenaar9964e462007-05-05 17:54:07 +000011708 if exists("w:netrw_liststyle") |let b:netrw_liststyle = w:netrw_liststyle |endif
11709 if exists("w:netrw_bannercnt") |let b:netrw_bannercnt = w:netrw_bannercnt |endif
11710 if exists("w:netrw_method") |let b:netrw_method = w:netrw_method |endif
11711 if exists("w:netrw_prvdir") |let b:netrw_prvdir = w:netrw_prvdir |endif
11712 if exists("w:netrw_explore_indx") |let b:netrw_explore_indx = w:netrw_explore_indx |endif
11713 if exists("w:netrw_explore_listlen")|let b:netrw_explore_listlen= w:netrw_explore_listlen|endif
11714 if exists("w:netrw_explore_mtchcnt")|let b:netrw_explore_mtchcnt= w:netrw_explore_mtchcnt|endif
11715 if exists("w:netrw_explore_bufnr") |let b:netrw_explore_bufnr = w:netrw_explore_bufnr |endif
11716 if exists("w:netrw_explore_line") |let b:netrw_explore_line = w:netrw_explore_line |endif
11717 if exists("w:netrw_explore_list") |let b:netrw_explore_list = w:netrw_explore_list |endif
11718" call Dret("s:SetBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011719endfun
11720
11721" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011722" s:SetRexDir: set directory for :Rexplore {{{2
11723fun! s:SetRexDir(islocal,dirname)
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011724" call Dfunc("s:SetRexDir(islocal=".a:islocal." dirname<".a:dirname.">) win#".winnr())
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011725 let w:netrw_rexdir = a:dirname
11726 let w:netrw_rexlocal = a:islocal
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011727 let s:rexposn_{bufnr("%")} = winsaveview()
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011728" call Decho("setting w:netrw_rexdir =".w:netrw_rexdir,'~'.expand("<slnum>"))
11729" call Decho("setting w:netrw_rexlocal=".w:netrw_rexlocal,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011730" call Decho("saving posn to s:rexposn_".bufnr("%")."<".string(s:rexposn_{bufnr("%")}).">",'~'.expand("<slnum>"))
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011731" call Decho("setting s:rexposn_".bufnr("%")."<".bufname("%")."> to ".string(winsaveview()),'~'.expand("<slnum>"))
Bram Moolenaar97d62492012-11-15 21:28:22 +010011732" call Dret("s:SetRexDir : win#".winnr()." ".(a:islocal? "local" : "remote")." dir: ".a:dirname)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011733endfun
11734
11735" ---------------------------------------------------------------------
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011736" s:ShowLink: used to modify thin and tree listings to show links {{{2
11737fun! s:ShowLink()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011738 if exists("b:netrw_curdir")
11739 norm! $?\a
Tom Benham64a536d2024-11-07 21:15:03 +010011740 if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treetop")
11741 let basedir = s:NetrwTreePath(w:netrw_treetop)
11742 else
11743 let basedir = b:netrw_curdir.'/'
11744 endif
11745 let fname = basedir.s:NetrwGetWord()
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011746 let resname = resolve(fname)
Tom Benham64a536d2024-11-07 21:15:03 +010011747 if resname =~ '^\M'.basedir
11748 let dirlen = strlen(basedir)
11749 let resname = strpart(resname,dirlen)
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011750 endif
11751 let modline = getline(".")."\t --> ".resname
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011752 setl noro ma
11753 call setline(".",modline)
11754 setl ro noma nomod
11755 endif
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011756endfun
11757
11758" ---------------------------------------------------------------------
11759" s:ShowStyle: {{{2
11760fun! s:ShowStyle()
11761 if !exists("w:netrw_liststyle")
11762 let liststyle= g:netrw_liststyle
11763 else
11764 let liststyle= w:netrw_liststyle
11765 endif
11766 if liststyle == s:THINLIST
11767 return s:THINLIST.":thin"
11768 elseif liststyle == s:LONGLIST
11769 return s:LONGLIST.":long"
11770 elseif liststyle == s:WIDELIST
11771 return s:WIDELIST.":wide"
11772 elseif liststyle == s:TREELIST
11773 return s:TREELIST.":tree"
11774 else
11775 return 'n/a'
11776 endif
11777endfun
11778
11779" ---------------------------------------------------------------------
Bram Moolenaar8d043172014-01-23 14:24:41 +010011780" s:Strlen: this function returns the length of a string, even if its using multi-byte characters. {{{2
11781" Solution from Nicolai Weibull, vim docs (:help strlen()),
11782" Tony Mechelynck, and my own invention.
Bram Moolenaar446cb832008-06-24 21:56:24 +000011783fun! s:Strlen(x)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011784" "" call Dfunc("s:Strlen(x<".a:x."> g:Align_xstrlen=".g:Align_xstrlen.")")
11785
11786 if v:version >= 703 && exists("*strdisplaywidth")
11787 let ret= strdisplaywidth(a:x)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011788
Bram Moolenaar8d043172014-01-23 14:24:41 +010011789 elseif type(g:Align_xstrlen) == 1
11790 " allow user to specify a function to compute the string length (ie. let g:Align_xstrlen="mystrlenfunc")
11791 exe "let ret= ".g:Align_xstrlen."('".substitute(a:x,"'","''","g")."')"
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011792
Bram Moolenaar8d043172014-01-23 14:24:41 +010011793 elseif g:Align_xstrlen == 1
Bram Moolenaar446cb832008-06-24 21:56:24 +000011794 " number of codepoints (Latin a + combining circumflex is two codepoints)
11795 " (comment from TM, solution from NW)
11796 let ret= strlen(substitute(a:x,'.','c','g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011797
Bram Moolenaar8d043172014-01-23 14:24:41 +010011798 elseif g:Align_xstrlen == 2
11799 " number of spacing codepoints (Latin a + combining circumflex is one spacing
Bram Moolenaar446cb832008-06-24 21:56:24 +000011800 " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
11801 " (comment from TM, solution from TM)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011802 let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011803
Bram Moolenaar8d043172014-01-23 14:24:41 +010011804 elseif g:Align_xstrlen == 3
11805 " virtual length (counting, for instance, tabs as anything between 1 and
11806 " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
Bram Moolenaar446cb832008-06-24 21:56:24 +000011807 " preceded by lam, one otherwise, etc.)
11808 " (comment from TM, solution from me)
Bram Moolenaar8d043172014-01-23 14:24:41 +010011809 let modkeep= &l:mod
11810 exe "norm! o\<esc>"
Bram Moolenaar446cb832008-06-24 21:56:24 +000011811 call setline(line("."),a:x)
11812 let ret= virtcol("$") - 1
Bram Moolenaar8d043172014-01-23 14:24:41 +010011813 d
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011814 NetrwKeepj norm! k
Bram Moolenaar8d043172014-01-23 14:24:41 +010011815 let &l:mod= modkeep
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011816
Bram Moolenaar446cb832008-06-24 21:56:24 +000011817 else
11818 " at least give a decent default
Bram Moolenaar8d043172014-01-23 14:24:41 +010011819 let ret= strlen(a:x)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011820 endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010011821" "" call Dret("s:Strlen ".ret)
Bram Moolenaar446cb832008-06-24 21:56:24 +000011822 return ret
11823endfun
11824
11825" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011826" s:ShellEscape: shellescape(), or special windows handling {{{2
11827fun! s:ShellEscape(s, ...)
Nir Lichtman1e34b952024-05-08 19:19:34 +020011828 if has('win32') && $SHELL == '' && &shellslash
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011829 return printf('"%s"', substitute(a:s, '"', '""', 'g'))
Christian Brabandt8b0fa7a2024-10-31 09:21:23 +010011830 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011831 let f = a:0 > 0 ? a:1 : 0
11832 return shellescape(a:s, f)
11833endfun
11834
11835" ---------------------------------------------------------------------
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011836" s:TreeListMove: supports [[, ]], [], and ][ in tree mode {{{2
Bram Moolenaar446cb832008-06-24 21:56:24 +000011837fun! s:TreeListMove(dir)
11838" call Dfunc("s:TreeListMove(dir<".a:dir.">)")
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011839 let curline = getline('.')
11840 let prvline = (line(".") > 1)? getline(line(".")-1) : ''
11841 let nxtline = (line(".") < line("$"))? getline(line(".")+1) : ''
11842 let curindent = substitute(getline('.'),'^\(\%('.s:treedepthstring.'\)*\)[^'.s:treedepthstring.'].\{-}$','\1','e')
11843 let indentm1 = substitute(curindent,'^'.s:treedepthstring,'','')
11844 let treedepthchr = substitute(s:treedepthstring,' ','','g')
11845 let stopline = exists("w:netrw_bannercnt")? w:netrw_bannercnt : 1
11846" call Decho("prvline <".prvline."> #".(line(".")-1), '~'.expand("<slnum>"))
11847" call Decho("curline <".curline."> #".line(".") , '~'.expand("<slnum>"))
11848" call Decho("nxtline <".nxtline."> #".(line(".")+1), '~'.expand("<slnum>"))
11849" call Decho("curindent<".curindent.">" , '~'.expand("<slnum>"))
11850" call Decho("indentm1 <".indentm1.">" , '~'.expand("<slnum>"))
11851 " COMBAK : need to handle when on a directory
11852 " COMBAK : need to handle ]] and ][. In general, needs work!!!
Bram Moolenaar446cb832008-06-24 21:56:24 +000011853 if curline !~ '/$'
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011854 if a:dir == '[[' && prvline != ''
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011855 NetrwKeepj norm! 0
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011856 let nl = search('^'.indentm1.'\%('.s:treedepthstring.'\)\@!','bWe',stopline) " search backwards
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011857" call Decho("regfile srch back: ".nl,'~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011858 elseif a:dir == '[]' && nxtline != ''
11859 NetrwKeepj norm! 0
Bram Moolenaaraa3b15d2016-04-21 08:53:19 +020011860" call Decho('srchpat<'.'^\%('.curindent.'\)\@!'.'>','~'.expand("<slnum>"))
Bram Moolenaare0fa3742016-02-20 15:47:01 +010011861 let nl = search('^\%('.curindent.'\)\@!','We') " search forwards
11862 if nl != 0
11863 NetrwKeepj norm! k
11864 else
11865 NetrwKeepj norm! G
11866 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011867" call Decho("regfile srch fwd: ".nl,'~'.expand("<slnum>"))
Bram Moolenaar446cb832008-06-24 21:56:24 +000011868 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +000011869 endif
11870
11871" call Dret("s:TreeListMove")
11872endfun
11873
11874" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +000011875" s:UpdateBuffersMenu: does emenu Buffers.Refresh (but due to locale, the menu item may not be called that) {{{2
11876" The Buffers.Refresh menu calls s:BMShow(); unfortunately, that means that that function
11877" can't be called except via emenu. But due to locale, that menu line may not be called
11878" Buffers.Refresh; hence, s:NetrwBMShow() utilizes a "cheat" to call that function anyway.
11879fun! s:UpdateBuffersMenu()
11880" call Dfunc("s:UpdateBuffersMenu()")
Bram Moolenaaradc21822011-04-01 18:03:16 +020011881 if has("gui") && has("menu") && has("gui_running") && &go =~# 'm' && g:netrw_menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011882 try
Bram Moolenaaradc21822011-04-01 18:03:16 +020011883 sil emenu Buffers.Refresh\ menu
Bram Moolenaarc236c162008-07-13 17:41:49 +000011884 catch /^Vim\%((\a\+)\)\=:E/
11885 let v:errmsg= ""
Bram Moolenaar8feef4f2015-01-07 16:57:10 +010011886 sil NetrwKeepj call s:NetrwBMShow()
Bram Moolenaarc236c162008-07-13 17:41:49 +000011887 endtry
11888 endif
11889" call Dret("s:UpdateBuffersMenu")
11890endfun
11891
11892" ---------------------------------------------------------------------
Bram Moolenaar446cb832008-06-24 21:56:24 +000011893" s:UseBufWinVars: (used by NetrwBrowse() and LocalBrowseCheck() {{{2
Bram Moolenaaradc21822011-04-01 18:03:16 +020011894" Matching function to s:SetBufWinVars()
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011895fun! s:UseBufWinVars()
Bram Moolenaar9964e462007-05-05 17:54:07 +000011896" call Dfunc("s:UseBufWinVars()")
11897 if exists("b:netrw_liststyle") && !exists("w:netrw_liststyle") |let w:netrw_liststyle = b:netrw_liststyle |endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011898 if exists("b:netrw_bannercnt") && !exists("w:netrw_bannercnt") |let w:netrw_bannercnt = b:netrw_bannercnt |endif
11899 if exists("b:netrw_method") && !exists("w:netrw_method") |let w:netrw_method = b:netrw_method |endif
11900 if exists("b:netrw_prvdir") && !exists("w:netrw_prvdir") |let w:netrw_prvdir = b:netrw_prvdir |endif
11901 if exists("b:netrw_explore_indx") && !exists("w:netrw_explore_indx") |let w:netrw_explore_indx = b:netrw_explore_indx |endif
11902 if exists("b:netrw_explore_listlen") && !exists("w:netrw_explore_listlen")|let w:netrw_explore_listlen = b:netrw_explore_listlen|endif
11903 if exists("b:netrw_explore_mtchcnt") && !exists("w:netrw_explore_mtchcnt")|let w:netrw_explore_mtchcnt = b:netrw_explore_mtchcnt|endif
11904 if exists("b:netrw_explore_bufnr") && !exists("w:netrw_explore_bufnr") |let w:netrw_explore_bufnr = b:netrw_explore_bufnr |endif
11905 if exists("b:netrw_explore_line") && !exists("w:netrw_explore_line") |let w:netrw_explore_line = b:netrw_explore_line |endif
11906 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 +000011907" call Dret("s:UseBufWinVars")
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +000011908endfun
11909
Bram Moolenaar1afcace2005-11-25 19:54:28 +000011910" ---------------------------------------------------------------------
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011911" s:UserMaps: supports user-defined UserMaps {{{2
11912" * calls a user-supplied funcref(islocal,curdir)
11913" * interprets result
11914" See netrw#UserMaps()
11915fun! s:UserMaps(islocal,funcname)
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011916 if !exists("b:netrw_curdir")
11917 let b:netrw_curdir= getcwd()
11918 endif
11919 let Funcref = function(a:funcname)
11920 let result = Funcref(a:islocal)
11921
11922 if type(result) == 1
11923 " if result from user's funcref is a string...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011924 if result == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011925 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011926 elseif result != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011927 exe result
11928 endif
11929
11930 elseif type(result) == 3
11931 " if result from user's funcref is a List...
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011932 for action in result
11933 if action == "refresh"
Tom Benham64a536d2024-11-07 21:15:03 +010011934 call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./',0))
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011935 elseif action != ""
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011936 exe action
11937 endif
11938 endfor
11939 endif
Bram Moolenaara0f849e2015-10-30 14:37:44 +010011940endfun
11941
Bram Moolenaar85850f32019-07-19 22:05:51 +020011942" ==========================
Bram Moolenaare6ae6222013-05-21 21:01:10 +020011943" Settings Restoration: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011944" ==========================
Bram Moolenaar83bab712005-08-01 21:58:57 +000011945let &cpo= s:keepcpo
11946unlet s:keepcpo
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +000011947
Bram Moolenaar85850f32019-07-19 22:05:51 +020011948" ===============
Bram Moolenaar83bab712005-08-01 21:58:57 +000011949" Modelines: {{{1
Bram Moolenaar85850f32019-07-19 22:05:51 +020011950" ===============
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951" vim:ts=8 fdm=marker